From e95df3f5aa9099829c63bab4a5c5ea96808edeb0 Mon Sep 17 00:00:00 2001 From: Matt McCutchen Date: Sat, 27 Aug 2011 11:40:35 -0400 Subject: [PATCH] Make PMatching a newtype for clarity. --- program/Evaluation.hs | 2 +- program/PMInstance.hs | 3 ++- program/ProposalMatcher.hs | 2 +- program/TestUtils.hs | 10 +++++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/program/Evaluation.hs b/program/Evaluation.hs index 032a1a9..f69668d 100644 --- a/program/Evaluation.hs +++ b/program/Evaluation.hs @@ -10,7 +10,7 @@ import ArrayStuff type MatchingEvaluation = Array Int Wt evaluateMatching :: PMConfig -> PMInstance -> PMatching -> MatchingEvaluation -evaluateMatching cfg inst@(PMInstance numRvrs numProps rloadA prefA) matching = +evaluateMatching cfg inst@(PMInstance numRvrs numProps rloadA prefA) (PMatching matching) = let reviewersByProposal = accumArray (flip (:)) [] (0, numProps-1) $ map (\(i,j) -> (j,i)) matching :: Array Int [Int] in diff --git a/program/PMInstance.hs b/program/PMInstance.hs index 70d7529..7fac0bb 100644 --- a/program/PMInstance.hs +++ b/program/PMInstance.hs @@ -23,4 +23,5 @@ instance Show PMInstance where map (\j -> ("P#" ++ show j) : map (\i -> show (prefA ! (i, j))) theRvrs) theProps ) -type PMatching = [(Int, Int)] +newtype PMatching = PMatching [(Int, Int)] + deriving Show diff --git a/program/ProposalMatcher.hs b/program/ProposalMatcher.hs index d435d67..dcc757a 100644 --- a/program/ProposalMatcher.hs +++ b/program/ProposalMatcher.hs @@ -112,4 +112,4 @@ doMatching cfg inst@(PMInstance numRvrs numProps _ _) = then [(i, j)] else [] in - sort pairs -- for prettiness + PMatching (sort pairs) -- for prettiness diff --git a/program/TestUtils.hs b/program/TestUtils.hs index 96a170c..d171850 100644 --- a/program/TestUtils.hs +++ b/program/TestUtils.hs @@ -34,7 +34,7 @@ flowAnnotate g fa = (n1, n2, REdgeF i ca (fa ! i) co)) $ labEdges g) :: Gr () REdgeF showInstanceAsGraph :: PMInstance -> PMatching -> Gr String String -showInstanceAsGraph (PMInstance numRvrs numProps rloadA prefA) matchedPairs = +showInstanceAsGraph (PMInstance numRvrs numProps rloadA prefA) (PMatching matchedPairs) = let rvrNode i = i propNode j = numRvrs + j @@ -91,14 +91,14 @@ l1 /\ l2 = (l1 \\ l2, l2 \\ l1) runEvaluation cfg nr np = do let inst = runRandom myGen $ randomInstance cfg nr np putStr (show inst ++ "\n") - let m0 = doMatching cfg{loadTolerance = 0} inst + let PMatching m0 = doMatching cfg{loadTolerance = 0} inst putStr ("Matching with load tolerance 0:\n" ++ show m0 ++ "\n") - let m1 = doMatching cfg{loadTolerance = 1} inst + let PMatching m1 = doMatching cfg{loadTolerance = 1} inst putStr ("Matching with load tolerance 1:\n" ++ show m1 ++ "\n") putStr ("Differences:\n" ++ show (m0 /\ m1) ++ "\n") - let e0 = evaluateMatching cfg{loadTolerance = 0} inst m0 + let e0 = evaluateMatching cfg{loadTolerance = 0} inst (PMatching m0) putStr ("Evaluation of first matching:\n" ++ show e0 ++ "\n") - let e1 = evaluateMatching cfg{loadTolerance = 1} inst m1 + let e1 = evaluateMatching cfg{loadTolerance = 1} inst (PMatching m1) putStr ("Evaluation of second matching:\n" ++ show e1 ++ "\n") putStr ("Evaluation differences:\n" ++ show (sortedDiffEvaluations e0 e1) ++ "\n") -- 2.34.1