The random instance generator and other improvements.
[match/match.git] / program / ProposalMatcher.hs
similarity index 83%
rename from program/ProposalMatch.hs
rename to program/ProposalMatcher.hs
index 028f22c..c0bd7a0 100644 (file)
@@ -1,17 +1,12 @@
-module ProposalMatch where
+module ProposalMatcher where
 import UnitMinCostFlow
 import Data.Array.IArray
 import Data.Graph.Inductive.Graph
 import Data.Graph.Inductive.Tree
 import Data.List
 
-import ProposalMatchConfig
-
-data Instance = Instance
-       Int                -- numReviewers
-       Int                -- numProposals
-       (Int -> Wt)        -- reviewer -> relative load
-       (Int -> Int -> Wt) -- reviewer -> proposal -> pref
+import Instance
+import ProposalMatcherConfig
 
 prefBoringness p = if prefIsVeryBoring p then 2
        else if prefIsBoring p then 1 else 0
@@ -19,7 +14,7 @@ prefExpertness p = if prefIsExpert p then 2
        else if prefIsKnowledgeable p then 1 else 0
 
 doReduction :: Instance -> Gr () Wt
-doReduction (Instance numRvrs numProps rloadF prefF) =
+doReduction (Instance numRvrs numProps rloadA prefA) =
        let
                source = 0
                sink = 1
@@ -29,8 +24,8 @@ doReduction (Instance numRvrs numProps rloadF prefF) =
                in
        let
                totalReviews = reviewsEachProposal * numProps
-               totalRelativeLoad = foldl (+) 0 (map rloadF [0 .. numRvrs - 1])
-               targetLoad i = ceiling (numAsWt totalReviews * rloadF i / totalRelativeLoad)
+               totalRelativeLoad = foldl (+) 0 (map (rloadA !) [0 .. numRvrs - 1])
+               targetLoad i = ceiling (numAsWt totalReviews * (rloadA ! i) / totalRelativeLoad)
                -- A...H refer to idea book p.429
                edgesABC = do
                        i <- [0 .. numRvrs - 1]
@@ -48,7 +43,7 @@ doReduction (Instance numRvrs numProps rloadF prefF) =
                edgesD = do
                        i <- [0 .. numRvrs - 1]
                        j <- [0 .. numProps - 1]
-                       let pref = prefF i j
+                       let pref = prefA ! (i, j)
                        if prefIsConflict pref
                                then []
                                else [(rvrNode i (prefBoringness pref),
@@ -73,7 +68,7 @@ doReduction (Instance numRvrs numProps rloadF prefF) =
 todo = undefined
 -- Returns a list of reviews as ordered pairs (reviewer#, proposal#).
 doMatching :: Instance -> [(Int, Int)]
-doMatching inst@(Instance numRvrs numProps rloadF prefF) =
+doMatching inst@(Instance numRvrs numProps _ _) =
        -- Copied from doReduction.  There should be a better way to get these here.
        let
                source = 0