Add conflicts of interest to the InstanceGenerator and make some other cleanups.
[match/match.git] / program / InstanceGenerator.hs
1 module InstanceGenerator where
2 import Instance
3 import System.Random
4 import RandomizedMonad
5 import Data.Array.IArray
6 import ArrayStuff
7
8 numTopics = 20
9
10 -- Expertise on each of the topics
11 data ReviewerInfo = ReviewerInfo {
12         riTopicExpertness :: Array Int Double,
13         riConflicts       :: [Int]
14 }
15
16 randomReviewerInfo numProps = do
17         expns <- indRandomArray (0, numTopics-1) $
18                 withProb [(0.15, return 2), (0.4, return 1)] (return 0)
19         -- Samir: "Its often the case that each reviewer has a COI with say
20         -- one proposal submitted either by their University (different faculty)
21         -- or by a recent co-author."
22         conflicts <- withProb [(0.7, do
23                         cp <- mrandomR (0, numProps-1)
24                         return [cp]
25                 )] (return [])
26         return (ReviewerInfo expns conflicts)
27
28 -- One topic or two different topics
29 data ProposalTopics = PTopic1 Int | PTopic2 Int Int
30
31 data ProposalInfo = ProposalInfo {
32         piTopics     :: ProposalTopics,
33         piDifficulty :: Wt
34 }
35
36 randomProposalInfo = do
37         topics <- do
38                 t1 <- mrandomR (0, numTopics-1)
39                 withProb [(0.5, return $ PTopic1 t1)] (do
40                         t2 <- filterRandomized (/= t1) $ mrandomR (0, numTopics-1)
41                         return $ PTopic2 t1 t2
42                         )
43         diff <- mrandomR (3, 5)
44         return (ProposalInfo topics (fromInteger diff))
45
46 expertnessToPref expertness = if expertness == 0 then 7
47         else if expertness == 1 then 5
48         else 3
49
50 randomInstance :: Int -> Int -> Randomized Instance
51 randomInstance numRvrs numProps = do
52         reviewerInfos <- indRandomArray (0, numRvrs-1) $ randomReviewerInfo numProps
53                 :: Randomized (Array Int ReviewerInfo)
54         proposalInfos <- indRandomArray (0, numProps-1) $ randomProposalInfo
55                 :: Randomized (Array Int ProposalInfo)
56         let loadA = constArray (0, numRvrs-1) 1
57         let prefA = funcArray ((0, 0), (numRvrs-1, numProps-1)) (\(i,j) ->
58                 let
59                         ReviewerInfo iTE iC = reviewerInfos ! i
60                         ProposalInfo jT jD = proposalInfos ! j
61                         isConflict = elem j iC
62                         topicPref = case jT of
63                                 PTopic1 jt1 -> expertnessToPref (iTE ! jt1)
64                                 PTopic2 jt1 jt2 -> (expertnessToPref (iTE ! jt1)
65                                         + expertnessToPref (iTE ! jt2)) / 2
66                 in if isConflict then 40 else topicPref * jD - 4)
67         return $ Instance numRvrs numProps loadA prefA