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