2019-10-18 09:57:43 +02:00
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
2019-05-30 12:40:32 +02:00
|
|
|
{-# LANGUAGE NoImplicitPrelude #-}
|
2019-10-18 09:10:11 +02:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2019-05-30 12:40:32 +02:00
|
|
|
|
2020-01-07 08:45:50 +01:00
|
|
|
import Options.Applicative
|
2019-10-18 09:57:43 +02:00
|
|
|
import Pipes
|
2019-10-22 16:42:16 +02:00
|
|
|
import Pretty
|
2020-01-07 08:45:50 +01:00
|
|
|
import Protolude hiding (for, option)
|
2019-10-18 09:57:43 +02:00
|
|
|
import System.IO
|
2020-01-07 07:48:57 +01:00
|
|
|
import Szenario191
|
2019-10-17 19:50:19 +02:00
|
|
|
|
2020-01-07 08:45:50 +01:00
|
|
|
data Options
|
|
|
|
= Options
|
|
|
|
{ iterations :: N,
|
|
|
|
populationSize :: N
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-02 17:47:43 +02:00
|
|
|
optionsWithHelp :: ParserInfo Options
|
2020-01-07 08:45:50 +01:00
|
|
|
optionsWithHelp =
|
|
|
|
info (helper <*> options)
|
|
|
|
( fullDesc
|
|
|
|
<> progDesc "Run a GA"
|
|
|
|
<> header "haga - Haskell implementations of EAs"
|
|
|
|
)
|
2019-10-18 09:57:43 +02:00
|
|
|
|
|
|
|
main :: IO ()
|
2020-01-07 08:45:50 +01:00
|
|
|
main = execParser optionsWithHelp >>= \opts -> do
|
2019-10-18 09:57:43 +02:00
|
|
|
hSetBuffering stdout NoBuffering
|
2020-01-07 08:45:50 +01:00
|
|
|
pop <- population (populationSize opts) (I prios [])
|
2020-05-02 17:47:43 +02:00
|
|
|
pop' <-
|
|
|
|
runEffect
|
|
|
|
$ for (run (tournament 2) 2 1 (5 / 100) pop (steps $ iterations opts)) log
|
2019-10-22 14:33:19 +02:00
|
|
|
(res, _) <- bests 5 pop'
|
2019-10-18 09:57:43 +02:00
|
|
|
sequence_ $ format <$> res
|
|
|
|
where
|
|
|
|
format s = do
|
|
|
|
f <- liftIO $ fitness s
|
|
|
|
putErrText $ show f <> "\n" <> pretty s
|
|
|
|
log = putText . csv
|
2019-10-22 14:33:19 +02:00
|
|
|
csv (t, f) = show t <> " " <> show f
|