Make the evaluator's review weights configurable.
[match/match.git] / program / Evaluation.hs
1 module Evaluation where
2 import PMInstance
3 import PMConfig
4 import ProposalMatcher
5
6 import Data.Array.IArray
7 import Data.List
8 import ArrayStuff
9
10 type MatchingEvaluation = Array Int Wt
11
12 evaluateMatching :: PMConfig -> PMInstance -> PMatching -> MatchingEvaluation
13 evaluateMatching cfg inst@(PMInstance numRvrs numProps rloadA prefA) matching =
14         let reviewersByProposal = accumArray (flip (:)) []
15                 (0, numProps-1) $ map (\(i,j) -> (j,i)) matching
16                 :: Array Int [Int] in
17         aixmap (\j rl ->
18                 -- Sort this proposal's reviews, best first.
19                 let jPrefsInc = sort $ map (\i -> prefA ! (i,j)) rl in
20                 -- Charge each review's assignmentCost.
21                 sum $ zipWith (\wt prf -> wt * assignmentCost cfg prf)
22                         (reviewEvalWeights cfg)
23                         -- A missing review counts as a preference of 50 (really bad).
24                         (jPrefsInc ++ repeat 50)
25                 )
26                 reviewersByProposal
27
28 doEvaluateMatching :: PMConfig -> PMInstance -> MatchingEvaluation
29 doEvaluateMatching cfg inst =
30         let matching = doMatching cfg inst in
31         evaluateMatching cfg inst matching
32
33 -- Sorted from negative cost changes (better in e2)
34 -- to positive cost changes (worse in e2).
35 sortedDiffEvaluations :: MatchingEvaluation -> MatchingEvaluation -> [Wt]
36 sortedDiffEvaluations e1 e2 =
37         sort $ zipWith (-) (elems e1) (elems e2)