haga/src/Main.hs

64 lines
1.5 KiB
Haskell
Raw Normal View History

{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
2019-05-30 12:40:32 +02:00
2020-01-07 08:45:50 +01:00
import Options.Applicative
import Pipes
import Pretty
2024-02-11 21:25:15 +01:00
import Protolude hiding (for)
import System.IO
-- import Szenario212Pun
2024-02-11 21:25:15 +01:00
import Szenario191
data Options = Options
2024-02-19 21:56:28 +01:00
{ iterations :: !N,
populationSize :: !N
}
2020-01-07 08:45:50 +01:00
options :: Parser Options
options =
Options
<$> option
auto
( long "iterations"
<> short 'i'
<> metavar "N"
<> value 1000
<> help "Number of iterations"
)
<*> option
auto
( long "population-size"
<> short 'p'
<> metavar "N"
<> value 100
<> help "Population size"
)
2020-01-07 08:45:50 +01:00
optionsWithHelp :: ParserInfo Options
2020-01-07 08:45:50 +01:00
optionsWithHelp =
info
(helper <*> options)
2020-01-07 08:45:50 +01:00
( fullDesc
<> progDesc "Run a GA"
<> header "haga - Haskell implementations of EAs"
)
main :: IO ()
main =
execParser optionsWithHelp >>= \opts -> do
hSetBuffering stdout NoBuffering
let env = AssignmentEnviroment (students prios, topics prios)
2024-02-27 13:20:33 +01:00
let selType = Tournament 2
let run' = run prios env selType 2 (5 / 100) (populationSize opts) (steps (iterations opts)) :: Producer (Int, R) IO (Population Assignment)
pop' <-
runEffect (for run' logCsv)
let (res, _) = bests prios 5 pop'
mapM_ format res
where
format s = do
let f = fitness prios s
putErrText $ show f <> "\n" <> pretty s
2024-02-11 21:25:15 +01:00
logCsv = putText . csv
csv (t, f) = show t <> " " <> show f