- Implement CS2 min-cost-flow adaptor and generalize common min-cost-flow stuff
[match/match.git] / program / Test.hs
... / ...
CommitLineData
1module Test (
2 -- Export everything we need to have fun in GHCi:
3 module Test,
4 module TestUtils,
5
6 -- Generate instances.
7 module Instance,
8 module InstanceGenerator,
9
10 -- Solve instances.
11 module ProposalMatcher,
12 module ProposalMatcherConfig,
13
14 -- Run randomized things.
15 module System.Random,
16 module RandomizedMonad
17) where
18import TestUtils
19import Instance
20import InstanceGenerator
21import ProposalMatcher
22import ProposalMatcherConfig hiding (Wt)
23import System.Random
24import RandomizedMonad
25
26-- Other imports we need
27import BellmanFord
28import Data.Array.IArray
29import Data.Array.Unboxed
30import Data.Graph.Inductive.Graph
31import Data.Graph.Inductive.Tree
32import ArrayStuff
33
34-- TESTING GRAPH ALGORITHMS
35myGraph = mkGraph [(0, ()), (1, ()), (2, ())]
36 [(0, 1, (0, 2)), (0, 2, (1, 3)), (2, 1, (2, -2))] :: Gr () (Int, Int)
37
38bfResult = bellmanFord snd 0 myGraph
39
40flowArray = minCostFlow (0, 2) fst (const 1) snd myGraph (0, 1)
41
42myNCGraph = mkGraph [(0, ())] [(0, 0, -1)] :: Gr () Int
43bfNCResult = bellmanFord id 0 myNCGraph
44
45-- PROPOSAL-MATCHING EXAMPLES
46-- Example from idea book p. 425
47{-
48(myNumRvrs, myNumProps) = (4, 3)
49
50myPrefsArray = array ((0,0), (myNumRvrs-1,myNumProps-1)) [
51 ((0, 0), 15), ((1, 0), 10), ((2, 0), 15), ((3, 0), 40),
52 ((0, 1), 30), ((1, 1), 7), ((2, 1), 10), ((3, 1), 15),
53 ((0, 2), 15), ((1, 2), 25), ((2, 2), 20), ((3, 2), 20)
54 ]
55-}
56
57(myNumRvrs, myNumProps) = (5, 3)
58
59myPrefs = transposeArray $ listArray ((0,0), (myNumProps-1,myNumRvrs-1)) [
60 15, 10, 15, 40, 20,
61 30, 7, 10, 15, 15,
62 15, 25, 20, 20, 15
63 ] :: UArray (Int, Int) Wt
64
65myInst = Instance myNumRvrs myNumProps (constArray (0, myNumRvrs-1) 1) myPrefs
66
67rdnResult = doReduction myInst
68ReductionResult rrg rrso rrsi rreib rredi = rdnResult
69rdnFlowArray = minCostFlow rreib reIdx reCap reCost rrg (rrso, rrsi)
70rrg2 = flowAnnotate rrg rdnFlowArray
71myMatching = doMatching myInst
72
73iGraph = showInstanceAsGraph myInst myMatching -- Visualize me!