module PMDefaults where
-import Instance
+import PMInstance
import ProposalMatcher
import qualified NaiveMinCostFlow
-module Instance where
+module PMInstance where
import Data.Array.IArray
import Data.Array.Unboxed
import ArrayStuff
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
-module InstanceGenerator where
-import Instance
+module PMInstanceGenerator where
+import PMInstance
import System.Random
import RandomizedMonad
import Data.Array.IArray
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)
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
import Data.Graph.Inductive.Tree
import Data.List
-import Instance
+import PMInstance
import IMinCostFlow
data PMConfig = PMConfig {
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
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
module TestUtils,
-- Generate instances.
- module Instance,
- module InstanceGenerator,
+ module PMInstance,
+ module PMInstanceGenerator,
-- Solve instances.
module ProposalMatcher,
module RandomizedMonad
) where
import TestUtils
-import Instance
-import InstanceGenerator
+import PMInstance
+import PMInstanceGenerator
import ProposalMatcher
import PMDefaults
import System.Random
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
import System.Posix.IO
import System.Posix.Time
import System.Process
-import Instance
+import PMInstance
import ProposalMatcher
import MonadStuff
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