haga/src/Main.hs

69 lines
1.6 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-03-04 11:36:31 +01:00
-- import Szenario191
import IrisDataset
2024-03-17 18:14:52 +01:00
import Debug.Trace as DB
import qualified Data.Map.Strict as Map
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-03-17 18:14:52 +01:00
<> value 500
<> help "Number of iterations"
)
<*> option
auto
( long "population-size"
<> short 'p'
<> metavar "N"
2024-03-17 18:14:52 +01:00
<> 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
2024-03-04 11:36:31 +01:00
let env = irisLE
let selType = Tournament 3
2024-03-10 11:43:22 +01:00
let run' = run irisLEE env selType 40 (5 / 100) (populationSize opts) (steps (iterations opts))
2024-03-17 18:14:52 +01:00
pop' <- runEffect (for run' logCsv)
irisLEE' <- calc irisLEE pop'
let (res, _) = bests irisLEE' 5 pop'
let irisLEE' = irisLEE {training = False}
irisLEE' <- calc irisLEE' res
mapM_ (format irisLEE') res
where
2024-03-04 11:36:31 +01:00
format irisL s = do
2024-03-10 11:43:22 +01:00
let f = fitness' irisL 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