Add TODOs and comments about shuffle
This commit is contained in:
parent
59b5e4de8b
commit
939502e511
16
src/GA.hs
16
src/GA.hs
|
@ -26,6 +26,19 @@ import Protolude
|
||||||
import Test.QuickCheck hiding (sample, shuffle)
|
import Test.QuickCheck hiding (sample, shuffle)
|
||||||
import Test.QuickCheck.Instances
|
import Test.QuickCheck.Instances
|
||||||
|
|
||||||
|
-- TODO using sample here was a quick hack
|
||||||
|
{-|
|
||||||
|
Shuffles a non-empty list.
|
||||||
|
-}
|
||||||
|
shuffle' :: (MonadRandom m) => NonEmpty a -> m (NonEmpty a)
|
||||||
|
shuffle' xs = do
|
||||||
|
i <- sample . uniform 0 $ NE.length xs - 1
|
||||||
|
let x = xs NE.!! i
|
||||||
|
xs' <- sample . shuffle $ deleteI i xs
|
||||||
|
return $ x :| xs'
|
||||||
|
where
|
||||||
|
deleteI i xs = fst (NE.splitAt (i - 1) xs) ++ snd (NE.splitAt i xs)
|
||||||
|
|
||||||
-- TODO Enforce this being > 0
|
-- TODO Enforce this being > 0
|
||||||
type N = Int
|
type N = Int
|
||||||
|
|
||||||
|
@ -130,6 +143,7 @@ children2 nX i1 i2 = do
|
||||||
i6 <- mutate i4
|
i6 <- mutate i4
|
||||||
return $ i5 :| [i6]
|
return $ i5 :| [i6]
|
||||||
|
|
||||||
|
-- TODO there should be some shuffle here
|
||||||
{-|
|
{-|
|
||||||
The @k@ best individuals in the population when comparing using the supplied
|
The @k@ best individuals in the population when comparing using the supplied
|
||||||
function.
|
function.
|
||||||
|
@ -167,6 +181,8 @@ ga' nParents nX pop term nResult = do
|
||||||
f <- liftIO $ fitness s
|
f <- liftIO $ fitness s
|
||||||
putText $ show f <> "\n" <> pretty s
|
putText $ show f <> "\n" <> pretty s
|
||||||
|
|
||||||
|
-- TODO add top x percent selection (select n guys, sort by fitness first)
|
||||||
|
|
||||||
step
|
step
|
||||||
:: (Individual i, MonadRandom m, Monad m)
|
:: (Individual i, MonadRandom m, Monad m)
|
||||||
=> N
|
=> N
|
||||||
|
|
Loading…
Reference in New Issue
Block a user