-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSetup.hs
31 lines (29 loc) · 1.03 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Distribution.Simple
import System.Directory
import Data.List (intercalate, delete, isInfixOf, sort)
import qualified Data.Text as T
import qualified Data.Text.IO as T
main :: IO ()
main = do
generateRealLifeGraphs
defaultMain
-- | generate real life graphs from a text file
generateRealLifeGraphs :: IO ()
generateRealLifeGraphs = do
gr <- sort . delete "README.md" <$> listDirectory prefixDir
str <- foldl accumF (return start) gr
writeFile generatedFile $ init (init str) ++ "\n ]"
where
accumF str' filegr = str' >>= \str -> do
edges <- readFile $ prefixDir ++ filegr
let edges' = map ((\[x,y] -> " ( " ++ x ++ " , "++y++" )") . words) $ drop 2 $ lines edges
return $ unlines [str," [",intercalate "," edges'," ],"]
prefix = "src/BenchGraph/RealLife/"
prefixDir = prefix ++ "Graphs/"
generatedFile = prefix ++ "Generated.hs"
start = unlines
[ "module BenchGraph.RealLife.Generated (generated) where"
, ""
, "generated :: [[(Int,Int)]]"
, "generated = ["
]