Commit | Line | Data |
---|---|---|
56b565b1 MM |
1 | import PMInstance |
2 | import PMDefaults | |
3 | import ProposalMatcher | |
4 | import System.IO | |
5 | import Data.Array.IArray | |
578d7d98 | 6 | import Data.Array.Unboxed |
56b565b1 | 7 | import ArrayStuff |
a70586aa | 8 | import TSV |
56b565b1 | 9 | |
bbabbd01 MM |
10 | -- Command-line interface with simple tab-separated input/output formats. |
11 | -- ./match <example.in | |
12 | ||
56b565b1 MM |
13 | main = do |
14 | incsv <- hGetContents stdin | |
15 | -- handle errors another day, or let the platform do it | |
a70586aa | 16 | let inll = parseTSV incsv |
578d7d98 | 17 | let loadList = tail (head inll) |
56b565b1 MM |
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 | |
578d7d98 MM |
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 | |
56b565b1 | 34 | let PMatching theMatching = doMatching pmDefaults theInst |
a70586aa | 35 | hPutStr stdout $ formatTSV $ map (\(i, j) -> map show [i, j]) theMatching |