| 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 | type ReviewerInfo = Array Int Double |
| 12 | |
| 13 | randomReviewerInfo = do |
| 14 | list <- sequence $ replicate numTopics $ |
| 15 | withProb [(0.15, return 2), (0.4, return 1)] (return 0) |
| 16 | return $ listArray (0, numTopics-1) list |
| 17 | |
| 18 | -- One topic or two different topics |
| 19 | data ProposalTopics = PTopic1 Int | PTopic2 Int Int |
| 20 | |
| 21 | --type ProposalAuthors = Maybe Int |
| 22 | |
| 23 | type ProposalInfo = (ProposalTopics, Wt) |
| 24 | |
| 25 | randomProposalTopics = do |
| 26 | t1 <- mrandomR (0, numTopics-1) |
| 27 | withProb [(0.5, return $ PTopic1 t1)] (do |
| 28 | t2 <- filterRandomized (/= t1) $ mrandomR (0, numTopics-1) |
| 29 | return $ PTopic2 t1 t2 |
| 30 | ) |
| 31 | |
| 32 | -- Add conflict of interest later. |
| 33 | {-- |
| 34 | randomProposalAuthors = do |
| 35 | withProb [(0.5, return [])] (do |
| 36 | a1 <- mrandomR (0, numRvrs-1) |
| 37 | withProb [(0.5, return [a1])] (do |
| 38 | a2 <- filterRandomized (/= a1) $ mrandomR (0, numRvrs-1) |
| 39 | return [a1,a2] |
| 40 | ) |
| 41 | ) |
| 42 | --} |
| 43 | |
| 44 | randomProposalInfo = do |
| 45 | topics <- randomProposalTopics |
| 46 | diff <- mrandomR (3, 5) |
| 47 | return (topics, fromInteger diff) |
| 48 | |
| 49 | expertnessToPref expertness = if expertness == 0 then 7 |
| 50 | else if expertness == 1 then 5 |
| 51 | else 3 |
| 52 | |
| 53 | randomInstance :: Int -> Int -> Randomized Instance |
| 54 | randomInstance numRvrs numProps = do |
| 55 | reviewerInfosList <- sequence $ replicate numRvrs $ randomReviewerInfo |
| 56 | -- reviewerProfs is an array of arrays. |
| 57 | -- A pair-indexed array might be better... |
| 58 | let reviewerInfos = listArray (0, numRvrs-1) reviewerInfosList :: Array Int ReviewerInfo |
| 59 | proposalInfosList <- sequence $ replicate numProps $ randomProposalInfo |
| 60 | let proposalInfos = listArray (0, numProps-1) proposalInfosList :: Array Int ProposalInfo |
| 61 | let loadA = funcArray (0, numRvrs-1) $ const 1 |
| 62 | let prefA = funcArray ((0, 0), (numRvrs-1, numProps-1)) (\(i,j) -> |
| 63 | let |
| 64 | ii = reviewerInfos ! i |
| 65 | jj = proposalInfos ! j |
| 66 | topicPref = case fst jj of |
| 67 | PTopic1 t1 -> expertnessToPref (ii ! t1) |
| 68 | PTopic2 t1 t2 -> (expertnessToPref (ii ! t1) |
| 69 | + expertnessToPref (ii ! t2)) / 2 |
| 70 | in topicPref * snd jj - 4) |
| 71 | return $ Instance numRvrs numProps loadA prefA |