X-Git-Url: https://mattmccutchen.net/match/match.git/blobdiff_plain/2e7d542623d17554667ca0199dd988caf3c442ae..eb6c3c9f810799e3bfe8cd302dd9d00f97b4baf7:/program/Test.hs diff --git a/program/Test.hs b/program/Test.hs index 7840b5e..1530aa9 100644 --- a/program/Test.hs +++ b/program/Test.hs @@ -1,23 +1,52 @@ -module Test where +module Test ( + -- Export everything we need to have fun in GHCi: + module Test, + module TestUtils, + + -- Generate instances. + module PMInstance, + module PMInstanceGenerator, + + -- Solve instances. + module ProposalMatcher, + module PMDefaults, + + -- Run randomized things. + module System.Random, + module RandomizedMonad, + + -- Evaluate. + module Evaluation +) where +import TestUtils +import PMInstance +import PMInstanceGenerator +import ProposalMatcher +import PMDefaults +import System.Random +import RandomizedMonad +import Evaluation + +-- Other imports we need import BellmanFord -import UnitMinCostFlow -import ProposalMatch -import ProposalMatchConfig -import Data.Array +import Data.Array.IArray +import Data.Array.Unboxed import Data.Graph.Inductive.Graph import Data.Graph.Inductive.Tree +import ArrayStuff --- So we can call graphviz' at the GHCi prompt -import Data.Graph.Inductive.Graphviz -graphviz' g = Data.Graph.Inductive.Graphviz.graphviz' g - +-- TESTING GRAPH ALGORITHMS myGraph = mkGraph [(0, ()), (1, ()), (2, ())] - [(0, 1, 2), (0, 2, 3), (2, 1, -2)] :: Gr () Double + [(0, 1, (0, 2)), (0, 2, (1, 3)), (2, 1, (2, -2))] :: Gr () (Int, Int) -spTree1 = spTree 0 myGraph +bfResult = bellmanFord snd 0 myGraph -(flowVal, flowResid) = umcf 0 1 myGraph +flowArray = minCostFlow pmDefaults (0, 2) fst (const 1) snd myGraph (0, 1) +myNCGraph = mkGraph [(0, ())] [(0, 0, -1)] :: Gr () Int +bfNCResult = bellmanFord id 0 myNCGraph + +-- PROPOSAL-MATCHING EXAMPLES -- Example from idea book p. 425 {- (myNumRvrs, myNumProps) = (4, 3) @@ -31,16 +60,23 @@ myPrefsArray = array ((0,0), (myNumRvrs-1,myNumProps-1)) [ (myNumRvrs, myNumProps) = (5, 3) -myPrefsArray = array ((0,0), (myNumRvrs-1,myNumProps-1)) [ - ((0, 0), 15), ((1, 0), 10), ((2, 0), 15), ((3, 0), 40), ((4, 0), 20), - ((0, 1), 30), ((1, 1), 7), ((2, 1), 10), ((3, 1), 15), ((4, 1), 15), - ((0, 2), 15), ((1, 2), 25), ((2, 2), 20), ((3, 2), 20), ((4, 2), 15) - ] +myPrefs = transposeArray $ listArray ((0,0), (myNumProps-1,myNumRvrs-1)) [ + 15, 10, 15, 40, 20, + 30, 7, 10, 15, 15, + 15, 25, 20, 20, 15 + ] :: UArray (Int, Int) Wt + +myInst = PMInstance myNumRvrs myNumProps (constArray (0, myNumRvrs-1) 1) myPrefs + +rdnResult = doReduction pmDefaults myInst +ReductionResult rrg rrso rrsi rreib rredi = rdnResult +rdnFlowArray = minCostFlow pmDefaults rreib reIdx reCap reCost rrg (rrso, rrsi) +rrg2 = flowAnnotate rrg rdnFlowArray +myMatching = doMatching pmDefaults myInst -myPrefs = \i j -> myPrefsArray ! (i, j) -myInst = Instance myNumRvrs myNumProps (const 1) myPrefs +iGraph = showInstanceAsGraph myInst myMatching -- Visualize me! -rdnGraph = doReduction myInst -(rdnFlowVal, rdnFlowResid) = umcf 0 1 rdnGraph -rdnFlow = flowDiff rdnGraph rdnFlowResid -myMatching = doMatching myInst +-- Evaluation! +eInst = runRandom myGen $ randomInstance 20 50 +eval1 = doEvaluateMatching pmDefaults eInst +eval2 = doEvaluateMatching pmDefaults{loadTolerance = 2} eInst