2 -- Export everything we need to have fun in GHCi:
4 -- See the results of examples.
9 module InstanceGenerator,
12 module ProposalMatcher,
13 module ProposalMatcherConfig,
15 -- Run randomized things.
17 module RandomizedMonad,
20 module Data.Graph.Inductive.Graphviz
23 import InstanceGenerator
24 import ProposalMatcher
25 import ProposalMatcherConfig
27 import RandomizedMonad
28 import Data.Graph.Inductive.Graphviz
30 -- Other imports we need
32 import NaiveMinCostFlow
33 import Data.Array.IArray
34 import Data.Array.Unboxed
35 import Data.Graph.Inductive.Graph
36 import Data.Graph.Inductive.Tree
39 myGraph = mkGraph [(0, ()), (1, ()), (2, ())]
40 [(0, 1, (0, 2)), (0, 2, (1, 3)), (2, 1, (2, -2))] :: Gr () (Int, Int)
42 bfResult = bellmanFord snd 0 myGraph
44 flowArray = minCostFlow (0, 2) fst (const 1) snd myGraph (0, 1)
46 myNCGraph = mkGraph [(0, ())] [(0, 0, -1)] :: Gr () Int
47 bfNCResult = bellmanFord id 0 myNCGraph
49 data REdgeF = REdgeF Int Int Int Wt
50 instance Show REdgeF where
51 show (REdgeF idx cap flow cost) = "#" ++ (show idx) ++ ": "
52 ++ (show flow) ++ " of " ++ (show cap) ++ " @ " ++ (show cost)
54 mkGraph (labNodes g) (map (\(n1, n2, REdge i ca co) ->
55 (n1, n2, REdgeF i ca (fa ! i) co)) $ labEdges g) :: Gr () REdgeF
57 -- Example from idea book p. 425
59 (myNumRvrs, myNumProps) = (4, 3)
61 myPrefsArray = array ((0,0), (myNumRvrs-1,myNumProps-1)) [
62 ((0, 0), 15), ((1, 0), 10), ((2, 0), 15), ((3, 0), 40),
63 ((0, 1), 30), ((1, 1), 7), ((2, 1), 10), ((3, 1), 15),
64 ((0, 2), 15), ((1, 2), 25), ((2, 2), 20), ((3, 2), 20)
68 (myNumRvrs, myNumProps) = (5, 3)
70 myPrefs = transposeArray $ listArray ((0,0), (myNumProps-1,myNumRvrs-1)) [
74 ] :: UArray (Int, Int) Wt
76 myInst = Instance myNumRvrs myNumProps (funcArray (0, myNumRvrs-1) $ const 1) myPrefs
78 rdnResult = doReduction myInst
79 ReductionResult rrg rrso rrsi rreib rredi = rdnResult
80 rdnFlowArray = minCostFlow rreib reIdx reCap reCost rrg (rrso, rrsi)
81 rrg2 = flowAnnotate rrg rdnFlowArray
82 myMatching = doMatching myInst