- Add code to visualize an instance and matching as a graph (bipartite, rather
authorMatt McCutchen <matt@mattmccutchen.net>
Fri, 11 Jul 2008 04:20:07 +0000 (00:20 -0400)
committerMatt McCutchen <matt@mattmccutchen.net>
Fri, 11 Jul 2008 04:20:07 +0000 (00:20 -0400)
  than the more complex reduction graph).
- Remove obsolete definitions from doMatching.
- Add a script to run optimized, and improve the debug script to avoid the need
  for debugdir.

program/Makefile
program/ProposalMatcher.hs
program/Test.hs
program/debug
program/run-optimized [new file with mode: 0755]

index eb0274a..df9942e 100644 (file)
@@ -1,5 +1,7 @@
 # Let's keep it simple for now.
 all:
        ghc -fglasgow-exts --make -c *.hs
+all-optimized:
+       ghc -fglasgow-exts --make -O -hisuf O.hi -osuf O.o -c *.hs
 clean:
        rm -f *.hi *.o
index f523c27..46a693c 100644 (file)
@@ -102,16 +102,6 @@ todo = undefined
 -- Returns a list of reviews as ordered pairs (reviewer#, proposal#).
 doMatching :: Instance -> [(Int, Int)]
 doMatching inst@(Instance numRvrs numProps _ _) =
-       -- Copied from doReduction.  There should be a better way to get these here.
-       let
-               source = 0
-               sink = 1
-               rvrNode i boringness = 2 + 3*i + boringness
-               propNode j expertness = 2 + 3*numRvrs + 3*j + expertness
-               firstPropNode = propNode 0 0
-               idPropNode n = (n - (2 + 3*numRvrs)) `div` 3
-               numNodes = 2 + 3*numRvrs + 3*numProps
-               in
        let ReductionResult graph source sink idxBounds edIdx = doReduction inst in
        let flowArray = minCostFlow idxBounds reIdx reCap reCost graph (source, sink) in
        let pairs = do
index 260ce0b..cef7a53 100644 (file)
@@ -36,6 +36,10 @@ import Data.Graph.Inductive.Graph
 import Data.Graph.Inductive.Tree
 import ArrayStuff
 
+-- A fixed-seeded random number generator for reproducible experimentation.
+myGen = read "314159265 1" :: StdGen
+
+-- TESTING GRAPH ALGORITHMS
 myGraph = mkGraph [(0, ()), (1, ()), (2, ())]
        [(0, 1, (0, 2)), (0, 2, (1, 3)), (2, 1, (2, -2))] :: Gr () (Int, Int)
 
@@ -46,6 +50,7 @@ flowArray = minCostFlow (0, 2) fst (const 1) snd myGraph (0, 1)
 myNCGraph = mkGraph [(0, ())] [(0, 0, -1)] :: Gr () Int
 bfNCResult = bellmanFord id 0 myNCGraph
 
+-- VISUALIZATION STUFF
 data REdgeF = REdgeF Int Int Int Wt
 instance Show REdgeF where
        show (REdgeF idx cap flow cost) = "#" ++ (show idx) ++ ": "
@@ -54,6 +59,25 @@ flowAnnotate g fa =
        mkGraph (labNodes g) (map (\(n1, n2, REdge i ca co) ->
                (n1, n2, REdgeF i ca (fa ! i) co)) $ labEdges g) :: Gr () REdgeF
 
+showInstanceAsGraph :: Instance -> [(Int, Int)] -> Gr String String
+showInstanceAsGraph (Instance numRvrs numProps rloadA prefA) matchedPairs =
+       let
+               rvrNode i = i
+               propNode j = numRvrs + j
+               numNodes = numRvrs + numProps
+               theNodes = map (\i -> (rvrNode i, "R#" ++ show i ++
+                               " (RLoad " ++ show (rloadA ! i) ++ ")")) [0..numRvrs-1] ++
+                       map (\j -> (propNode j, "P#" ++ show j)) [0..numProps-1]
+               parenthesizeIf False s = s
+               parenthesizeIf True s = "(" ++ s ++ ")"
+               theEdges = do
+                       i <- [0..numRvrs-1]
+                       j <- [0..numProps-1]
+                       return (rvrNode i, propNode j,
+                               parenthesizeIf (elem (i, j) matchedPairs) $ show (prefA ! (i, j)))
+       in mkGraph theNodes theEdges
+
+-- PROPOSAL-MATCHING EXAMPLES
 -- Example from idea book p. 425
 {- 
 (myNumRvrs, myNumProps) = (4, 3)
@@ -80,3 +104,5 @@ ReductionResult rrg rrso rrsi rreib rredi = rdnResult
 rdnFlowArray = minCostFlow rreib reIdx reCap reCost rrg (rrso, rrsi)
 rrg2 = flowAnnotate rrg rdnFlowArray
 myMatching = doMatching myInst
+
+iGraph = showInstanceAsGraph myInst myMatching -- Visualize me!
index 3668570..32e8157 100755 (executable)
@@ -1,5 +1,3 @@
 #!/bin/bash
 # Let ghci see only the source so it loads the modules debuggably.
-mkdir -p debugdir
-(cd debugdir && ln -fs ../*.hs .)
-exec ghci -fglasgow-exts -i -idebugdir Test "$@"
+exec ghci -fglasgow-exts -hisuf D.hi -osuf D.o Test "$@"
diff --git a/program/run-optimized b/program/run-optimized
new file mode 100755 (executable)
index 0000000..26846df
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+make all-optimized && exec ghci -hisuf O.hi -osuf O.o Test "$@"