Merge branch 'master' into popl2012
[match/match.git] / program / Main.hs
... / ...
CommitLineData
1import PMInstance
2import PMDefaults
3import ProposalMatcher
4import System.IO
5import Data.Array.IArray
6import Data.Array.Unboxed
7import ArrayStuff
8import TSV
9
10-- Command-line interface with simple tab-separated input/output formats.
11-- ./match <example.in
12
13main = do
14 incsv <- hGetContents stdin
15 -- handle errors another day, or let the platform do it
16 let inll = parseTSV incsv
17 let loadList = tail (head inll)
18 let numRvrs = length loadList
19 let loadA = listArray (0, numRvrs-1) (map read loadList)
20 let numProps = length (tail inll) `div` 2
21 -- explicit type on the next line appears to be necessary
22 let pxarr = listOfListsToArray2D (tail inll) :: Array (Int,Int) String
23 -- careful, we end up transposing the array in here
24 let prefFixA = funcArray ((0,0), (numRvrs-1,numProps-1)) (\(i,j) ->
25 let
26 cell = pxarr ! (2*j, i+1)
27 (fix, pstr) = if last cell == '*' then (True, init cell) else (False, cell)
28 pref = read pstr
29 in (pref, fix)) :: Array (Int,Int) (Wt,Bool)
30 let prefA = amap2 fst prefFixA; fixA = amap2 snd prefFixA
31 let expA = funcArray ((0,0), (numRvrs-1,numProps-1)) (\(i,j) -> read $ pxarr ! (2*j+1, i+1))
32 let pnrA = funcArray (0, numProps-1) (\j -> read $ pxarr ! (2*j, 0))
33 let theInst = PMInstance numRvrs numProps loadA prefA expA fixA pnrA
34 let PMatching theMatching = doMatching pmDefaults theInst
35 hPutStr stdout $ formatTSV $ map (\(i, j) -> map show [i, j]) theMatching