| 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 Instance, |
| 8 | module InstanceGenerator, |
| 9 | |
| 10 | -- Solve instances. |
| 11 | module ProposalMatcher, |
| 12 | module PMDefaults, |
| 13 | |
| 14 | -- Run randomized things. |
| 15 | module System.Random, |
| 16 | module RandomizedMonad |
| 17 | ) where |
| 18 | import TestUtils |
| 19 | import Instance |
| 20 | import InstanceGenerator |
| 21 | import ProposalMatcher |
| 22 | import PMDefaults |
| 23 | import System.Random |
| 24 | import RandomizedMonad |
| 25 | |
| 26 | -- Other imports we need |
| 27 | import BellmanFord |
| 28 | import Data.Array.IArray |
| 29 | import Data.Array.Unboxed |
| 30 | import Data.Graph.Inductive.Graph |
| 31 | import Data.Graph.Inductive.Tree |
| 32 | import ArrayStuff |
| 33 | |
| 34 | -- TESTING GRAPH ALGORITHMS |
| 35 | myGraph = mkGraph [(0, ()), (1, ()), (2, ())] |
| 36 | [(0, 1, (0, 2)), (0, 2, (1, 3)), (2, 1, (2, -2))] :: Gr () (Int, Int) |
| 37 | |
| 38 | bfResult = bellmanFord snd 0 myGraph |
| 39 | |
| 40 | flowArray = minCostFlow pmDefaults (0, 2) fst (const 1) snd myGraph (0, 1) |
| 41 | |
| 42 | myNCGraph = mkGraph [(0, ())] [(0, 0, -1)] :: Gr () Int |
| 43 | bfNCResult = bellmanFord id 0 myNCGraph |
| 44 | |
| 45 | -- PROPOSAL-MATCHING EXAMPLES |
| 46 | -- Example from idea book p. 425 |
| 47 | {- |
| 48 | (myNumRvrs, myNumProps) = (4, 3) |
| 49 | |
| 50 | myPrefsArray = 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 | |
| 59 | myPrefs = 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 | |
| 65 | myInst = Instance myNumRvrs myNumProps (constArray (0, myNumRvrs-1) 1) myPrefs |
| 66 | |
| 67 | rdnResult = doReduction pmDefaults myInst |
| 68 | ReductionResult rrg rrso rrsi rreib rredi = rdnResult |
| 69 | rdnFlowArray = minCostFlow pmDefaults rreib reIdx reCap reCost rrg (rrso, rrsi) |
| 70 | rrg2 = flowAnnotate rrg rdnFlowArray |
| 71 | myMatching = doMatching pmDefaults myInst |
| 72 | |
| 73 | iGraph = showInstanceAsGraph myInst myMatching -- Visualize me! |