New paper-side gadget for PC + ERC
[match/match.git] / program / Main.hs
CommitLineData
56b565b1
MM
1import PMInstance
2import PMDefaults
3import ProposalMatcher
4import System.IO
5import Data.Array.IArray
6import ArrayStuff
7import Text.CSV
8
9-- pretty silly but it does the job
10swapTabCommaIn s = map (\c -> if c == '\t' then ',' else if c == ',' then '\t' else c) s
11removeQuotes s = filter (\c -> not (c == '"')) s
12parseTSV fname str = case parseCSV fname (swapTabCommaIn str) of
13 Left pe -> Left pe
14 Right ll -> Right $ map (map swapTabCommaIn) ll
15printTSV ll = removeQuotes $ swapTabCommaIn $ printCSV $ map (map swapTabCommaIn) ll
16
17main = do
18 incsv <- hGetContents stdin
19 -- handle errors another day, or let the platform do it
20 let Right inll = parseTSV "standard input" incsv
21 let loadList = head inll
22 let numRvrs = length loadList
23 let loadA = listArray (0, numRvrs-1) (map read loadList)
24 let numProps = length (tail inll) `div` 2
25 -- explicit type on the next line appears to be necessary
26 let pxarr = listOfListsToArray2D (tail inll) :: Array (Int,Int) String
27 -- careful, we end up transposing the array in here
28 let prefA = funcArray ((0,0), (numRvrs-1,numProps-1)) (\(i,j) -> read $ pxarr ! (2*j, i))
29 let expA = funcArray ((0,0), (numRvrs-1,numProps-1)) (\(i,j) -> read $ pxarr ! (2*j+1, i))
30 let theInst = PMInstance numRvrs numProps loadA prefA expA
31 let PMatching theMatching = doMatching pmDefaults theInst
32 hPutStr stdout $ printTSV $ map (\(i, j) -> map show [i, j]) theMatching