Merge branch 'master' into popl2012
[match/match.git] / program / PMInstance.hs
1 module PMInstance where
2 import Data.Array.IArray
3 import Data.Array.Unboxed
4 import ArrayStuff
5 import Formatter
6
7 type Wt = Double -- Can be any RealFrac.
8 widenInteger x = fromInteger (toInteger x)
9
10 data PMInstance = PMInstance {
11         -- I feel like I am in C, having to namespace these!  I guess one
12         -- solution would be to have a typeclass for every field name.  A
13         -- specialized solution might desugar to that.
14         pmiNumReviewers :: Int,
15         pmiNumProposals :: Int,
16         pmiRLoad :: UArray Int Wt,
17         pmiRPPref :: UArray (Int, Int) Wt, -- preference: -100 (COI), -99 to 100
18         pmiRPExp :: UArray (Int, Int) Wt, -- expertise: 0 to 3
19         -- New 2011-07-19
20         -- Should we "jam" all three values that are functions of (i, j)?
21         pmiRPFix :: UArray (Int, Int) Bool,
22         pmiPNumReviews :: UArray Int Int
23 }
24
25 -- Let us shoehorn in the new pref scale.
26 prefOldToNew p' = 100 - 5 * p'
27 prefNewToOld p = 20 - 0.2 * p
28
29 instance Show PMInstance where
30         show pmi =
31                 let theRvrs = [0..pmiNumReviewers pmi - 1]; theProps = [0..pmiNumProposals pmi - 1] in
32                 "Instance with " ++ show (pmiNumReviewers pmi) ++ " reviewers and " ++ show (pmiNumProposals pmi) ++ " proposals:\n" ++ formatTable (
33                             (       ""              : map (\i -> "R#" ++ show i       ) theRvrs) :
34                             (       "RLoad"         : map (\i -> show (pmiRLoad pmi ! i)     ) theRvrs) :
35                         map (\j -> ("P#" ++ show j) : map (\i -> show (pmiRPPref pmi ! (i, j)) ++ ":" ++ show (pmiRPExp pmi ! (i, j))) theRvrs) theProps
36                 )
37
38 newtype PMatching = PMatching [(Int, Int)]
39         deriving Show