From: Matt McCutchen Date: Mon, 28 Jul 2008 15:08:09 +0000 (-0400) Subject: Rename Instance -> PMInstance and introduce PMatching type. X-Git-Url: https://mattmccutchen.net/match/match.git/commitdiff_plain/05a6f0edaacc70ab373988ec4bafdf9963551004 Rename Instance -> PMInstance and introduce PMatching type. --- diff --git a/program/PMDefaults.hs b/program/PMDefaults.hs index 5f9ede2..b5ef0c7 100644 --- a/program/PMDefaults.hs +++ b/program/PMDefaults.hs @@ -1,5 +1,5 @@ module PMDefaults where -import Instance +import PMInstance import ProposalMatcher import qualified NaiveMinCostFlow diff --git a/program/Instance.hs b/program/PMInstance.hs similarity index 82% rename from program/Instance.hs rename to program/PMInstance.hs index 145a8f3..d039810 100644 --- a/program/Instance.hs +++ b/program/PMInstance.hs @@ -1,4 +1,4 @@ -module Instance where +module PMInstance where import Data.Array.IArray import Data.Array.Unboxed import ArrayStuff @@ -7,18 +7,21 @@ import Formatter type Wt = Double -- Can be any RealFrac. numAsWt x = fromInteger (toInteger x) -data Instance = Instance +data PMInstance = PMInstance Int -- numReviewers Int -- numProposals (UArray Int Wt) -- ! reviewer -> relative load (UArray (Int, Int) Wt) -- ! (reviewer, proposal) -> pref deriving Eq -instance Show Instance where - show (Instance numRvrs numProps loadA prefA) = +instance Show PMInstance where + show (PMInstance numRvrs numProps loadA prefA) = let theRvrs = [0..numRvrs-1]; theProps = [0..numProps-1] in "Instance with " ++ show numRvrs ++ " reviewers and " ++ show numProps ++ " proposals:\n" ++ formatTable ( ( "" : map (\i -> "R#" ++ show i ) theRvrs) : ( "RLoad" : map (\i -> show (loadA ! i) ) theRvrs) : map (\j -> ("P#" ++ show j) : map (\i -> show (prefA ! (i, j))) theRvrs) theProps ) + +type PMatching = [(Int, Int)] + \ No newline at end of file diff --git a/program/InstanceGenerator.hs b/program/PMInstanceGenerator.hs similarity index 92% rename from program/InstanceGenerator.hs rename to program/PMInstanceGenerator.hs index fbd95b2..1143f61 100644 --- a/program/InstanceGenerator.hs +++ b/program/PMInstanceGenerator.hs @@ -1,5 +1,5 @@ -module InstanceGenerator where -import Instance +module PMInstanceGenerator where +import PMInstance import System.Random import RandomizedMonad import Data.Array.IArray @@ -47,7 +47,7 @@ expertnessToPref expertness = if expertness == 0 then 7 else if expertness == 1 then 5 else 3 -randomInstance :: Int -> Int -> Randomized Instance +randomInstance :: Int -> Int -> Randomized PMInstance randomInstance numRvrs numProps = do reviewerInfos <- indRandomArray (0, numRvrs-1) $ randomReviewerInfo numProps :: Randomized (Array Int ReviewerInfo) @@ -64,4 +64,4 @@ randomInstance numRvrs numProps = do PTopic2 jt1 jt2 -> (expertnessToPref (iTE ! jt1) + expertnessToPref (iTE ! jt2)) / 2 in if isConflict then 40 else topicPref * jD - 4) - return $ Instance numRvrs numProps loadA prefA + return $ PMInstance numRvrs numProps loadA prefA diff --git a/program/ProposalMatcher.hs b/program/ProposalMatcher.hs index 86bbf88..2f5f63f 100644 --- a/program/ProposalMatcher.hs +++ b/program/ProposalMatcher.hs @@ -4,7 +4,7 @@ import Data.Graph.Inductive.Graph import Data.Graph.Inductive.Tree import Data.List -import Instance +import PMInstance import IMinCostFlow data PMConfig = PMConfig { @@ -58,8 +58,8 @@ indexEdges i ((v1, v2, re):es) = let (imax, ies) = indexEdges (i+1) es in (imax, (v1, v2, re{ reIdx = i }) : ies) -doReduction :: PMConfig -> Instance -> ReductionResult -doReduction cfg (Instance numRvrs numProps rloadA prefA) = +doReduction :: PMConfig -> PMInstance -> ReductionResult +doReduction cfg (PMInstance numRvrs numProps rloadA prefA) = let source = 0 sink = 1 @@ -118,8 +118,8 @@ doReduction cfg (Instance numRvrs numProps rloadA prefA) = ReductionResult (mkGraph theNodes theEdges) source sink (0, imax-1) edIdx -- Returns a list of reviews as ordered pairs (reviewer#, proposal#). -doMatching :: PMConfig -> Instance -> [(Int, Int)] -doMatching cfg inst@(Instance numRvrs numProps _ _) = +doMatching :: PMConfig -> PMInstance -> PMatching +doMatching cfg inst@(PMInstance numRvrs numProps _ _) = let ReductionResult graph source sink idxBounds edIdx = doReduction cfg inst in let flowArray = minCostFlow cfg idxBounds reIdx reCap reCost graph (source, sink) in let pairs = do diff --git a/program/Test.hs b/program/Test.hs index 4d715c4..8307e38 100644 --- a/program/Test.hs +++ b/program/Test.hs @@ -4,8 +4,8 @@ module Test ( module TestUtils, -- Generate instances. - module Instance, - module InstanceGenerator, + module PMInstance, + module PMInstanceGenerator, -- Solve instances. module ProposalMatcher, @@ -16,8 +16,8 @@ module Test ( module RandomizedMonad ) where import TestUtils -import Instance -import InstanceGenerator +import PMInstance +import PMInstanceGenerator import ProposalMatcher import PMDefaults import System.Random @@ -62,7 +62,7 @@ myPrefs = transposeArray $ listArray ((0,0), (myNumProps-1,myNumRvrs-1)) [ 15, 25, 20, 20, 15 ] :: UArray (Int, Int) Wt -myInst = Instance myNumRvrs myNumProps (constArray (0, myNumRvrs-1) 1) myPrefs +myInst = PMInstance myNumRvrs myNumProps (constArray (0, myNumRvrs-1) 1) myPrefs rdnResult = doReduction pmDefaults myInst ReductionResult rrg rrso rrsi rreib rredi = rdnResult diff --git a/program/TestUtils.hs b/program/TestUtils.hs index f2dbe11..da68cf4 100644 --- a/program/TestUtils.hs +++ b/program/TestUtils.hs @@ -9,7 +9,7 @@ import System.Random import System.Posix.IO import System.Posix.Time import System.Process -import Instance +import PMInstance import ProposalMatcher import MonadStuff @@ -27,8 +27,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