X-Git-Url: https://mattmccutchen.net/match/match.git/blobdiff_plain/fd0d2377785ca843a46b0050a7351dac82c84777..89b7fd0dac0bef62999e7448fce184c19fe5bc6b:/program/TestUtils.hs diff --git a/program/TestUtils.hs b/program/TestUtils.hs index f2dbe11..623391d 100644 --- a/program/TestUtils.hs +++ b/program/TestUtils.hs @@ -4,14 +4,19 @@ import Data.Array.IArray import Data.Graph.Inductive.Graph import Data.Graph.Inductive.Graphviz import Data.Graph.Inductive.Tree +import Data.List import System.IO import System.Random import System.Posix.IO import System.Posix.Time import System.Process -import Instance +import PMInstance import ProposalMatcher +import PMDefaults +import PMInstanceGenerator +import Evaluation import MonadStuff +import RandomizedMonad -- This module has stuff that is helpful for testing but isn't itself an example. @@ -27,8 +32,8 @@ flowAnnotate g fa = mkGraph (labNodes g) (map (\(n1, n2, REdge i ca co) -> (n1, n2, REdgeF i ca (fa ! i) co)) $ labEdges g) :: Gr () REdgeF -showInstanceAsGraph :: Instance -> [(Int, Int)] -> Gr String String -showInstanceAsGraph (Instance numRvrs numProps rloadA prefA) matchedPairs = +showInstanceAsGraph :: PMInstance -> PMatching -> Gr String String +showInstanceAsGraph (PMInstance numRvrs numProps rloadA prefA) matchedPairs = let rvrNode i = i propNode j = numRvrs + j @@ -76,3 +81,23 @@ goGraph theGraph = waitForProcess dotPid -- Then open the file. goFile fname + +-- Both-ways list difference +(/\) :: Eq a => [a] -> [a] -> ([a], [a]) +l1 /\ l2 = (l1 \\ l2, l2 \\ l1) + +-- Evaluation! +runEvaluation nr np = do + let inst = runRandom myGen $ randomInstance nr np + putStr (show inst ++ "\n") + let m0 = doMatching pmDefaults{loadTolerance = 0} inst + putStr ("Matching with load tolerance 0:\n" ++ show m0 ++ "\n") + let m1 = doMatching pmDefaults{loadTolerance = 1} inst + putStr ("Matching with load tolerance 1:\n" ++ show m1 ++ "\n") + putStr ("Differences:\n" ++ show (m0 /\ m1) ++ "\n") + let e0 = evaluateMatching pmDefaults{loadTolerance = 0} inst m0 + putStr ("Evaluation of first matching:\n" ++ show e0 ++ "\n") + let e1 = evaluateMatching pmDefaults{loadTolerance = 1} inst m1 + putStr ("Evaluation of second matching:\n" ++ show e1 ++ "\n") + putStr ("Evaluation differences:\n" ++ + show (sortedDiffEvaluations e0 e1) ++ "\n")