From ec84f84aa83e9961274e776e9c1eb3a6d0fb22cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A4tzel?= Date: Fri, 18 Oct 2019 13:43:18 +0200 Subject: [PATCH] Add 1-elitism as (unchangeable, for now) default --- src/GA.hs | 7 +++++-- src/Main.hs | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/GA.hs b/src/GA.hs index 49f24e2..987d476 100644 --- a/src/GA.hs +++ b/src/GA.hs @@ -174,11 +174,14 @@ step -> Population i -> m (Population i) step nParents nX pop = do + iBests <- bests 1 pop is <- proportionate nParents pop i :| is' <- children nX is iWorsts <- worst nParents pop - let popClean = foldr L.delete (NE.toList . unPop $ pop) iWorsts - return . Pop $ i :| is' <> popClean + let popClean = foldr L.delete (NE.toList . unPop $ pop) $ iBests <> iWorsts + -- TODO why does this not work? (we should use it!) + -- Pop <$> (shuffle' . NE.nub $ i :| is' <> popClean <> iBests) + return . Pop . NE.nub $ i :| is' <> popClean <> iBests {-| Runs the GA, using in each iteration diff --git a/src/Main.hs b/src/Main.hs index 1639f01..ae7b3d9 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -20,7 +20,6 @@ main = do res <- bests 5 pop' sequence_ $ format <$> res where - format :: (Individual i, MonadIO m, Pretty i) => i -> m () format s = do f <- liftIO $ fitness s putErrText $ show f <> "\n" <> pretty s