From 0dd02d06b3cd1d93df5914ea56793bb12000cb6c Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Sat, 1 Mar 2025 23:22:31 -0600 Subject: [PATCH] updates here too --- src/HushGP/GP.hs | 1 + src/HushGP/Genome.hs | 22 +--------------------- src/HushGP/Utility.hs | 4 ++++ 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/HushGP/GP.hs b/src/HushGP/GP.hs index 71292d0..9c76e69 100644 --- a/src/HushGP/GP.hs +++ b/src/HushGP/GP.hs @@ -11,6 +11,7 @@ import HushGP.GP.PushArgs import HushGP.GP.PushData import HushGP.GP.Variation import HushGP.Genome +import HushGP.GP.Individual -- import Debug.Trace (trace, traceStack) diff --git a/src/HushGP/Genome.hs b/src/HushGP/Genome.hs index a1ff9f6..f3fbb47 100644 --- a/src/HushGP/Genome.hs +++ b/src/HushGP/Genome.hs @@ -7,31 +7,11 @@ import HushGP.GP.PushArgs import HushGP.Instructions.Opens import HushGP.State import HushGP.Utility +import HushGP.GP.Individual -- import HushGP.Instructions -- import Debug.Trace --- | The structure for an individual containing the genome, the totalFitness, and --- the individual fitness cases for lexicase. -data Individual = Individual - { plushy :: [Gene], - totalFitness :: Maybe Double, - fitnessCases :: Maybe [Double] - } - deriving (Show, Eq) - -instance Ord Individual where - ind0 <= ind1 = totalFitness ind0 <= totalFitness ind1 - --- | Extracts the fitnessCases from an Individual. Errors if the field is empty. -extractFitnessCases :: Individual -> [Double] -extractFitnessCases Individual {fitnessCases = Nothing} = error "Error: fitnessCases is empty!" -extractFitnessCases Individual {fitnessCases = Just xs} = xs - -extractTotalFitness :: Individual -> Double -extractTotalFitness Individual {totalFitness = Nothing} = error "Error: totalFitness is empty!" -extractTotalFitness Individual {totalFitness = Just x} = x - -- | Makes a random individual based on the variables in a passed PushArgs. makeRandomIndividual :: PushArgs -> IO Individual makeRandomIndividual pushArgs = do diff --git a/src/HushGP/Utility.hs b/src/HushGP/Utility.hs index db2ebe5..edc265c 100644 --- a/src/HushGP/Utility.hs +++ b/src/HushGP/Utility.hs @@ -23,3 +23,7 @@ mapIndexed = mapIndexed' 0 mapIndexed' :: Int -> (Int -> a -> b) -> [a] -> [b] mapIndexed' _ _ [] = [] mapIndexed' count f (x : xs) = f count x : mapIndexed' (count + 1) f xs + +-- | Returns a random element from a passed list. No generator required. +randElem :: [a] -> IO a +randElem xs = (xs !!) . fst . uniformR (0, length xs - 1) <$> initStdGen