haga/src-students/Main.hs

70 lines
1.7 KiB
Haskell
Raw Permalink 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
2024-02-11 21:25:15 +01:00
import Protolude hiding (for)
import System.IO
2024-04-22 14:33:40 +02:00
import Seminar
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"
2024-04-22 14:33:40 +02:00
<> value 1500
<> help "Number of iterations"
)
<*> option
auto
( long "population-size"
<> short 'p'
<> metavar "N"
2024-04-21 19:20:02 +02:00
<> value 400
<> 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
2024-04-29 10:41:01 +02:00
let cfg = GaRunConfig {
enviroment = AssignmentEnviroment (students prios, topics prios),
initialEvaluator = prios,
selectionType = Tournament 3,
termination = (steps (iterations opts)),
poulationSize = (populationSize opts),
stepSize = 120,
elitismRatio = 5/100
}
pop' <- runEffect (for (run cfg) logCsv)
prios' <- calc prios pop'
let (res, _) = bests prios' 5 pop'
prios' <- calc prios' res
mapM_ (format prios') res
where
2024-04-22 14:33:40 +02:00
format seminarL s = do
let f = fitness' seminarL s
2024-05-07 14:58:00 +02:00
putErrText $ show f <> "\n" <> output (AssignmentEnviroment (students prios, topics prios)) s
2024-02-11 21:25:15 +01:00
logCsv = putText . csv
csv (t, f) = show t <> " " <> show f