updates here too
This commit is contained in:
parent
4b611a9d74
commit
0dd02d06b3
@ -11,6 +11,7 @@ import HushGP.GP.PushArgs
|
|||||||
import HushGP.GP.PushData
|
import HushGP.GP.PushData
|
||||||
import HushGP.GP.Variation
|
import HushGP.GP.Variation
|
||||||
import HushGP.Genome
|
import HushGP.Genome
|
||||||
|
import HushGP.GP.Individual
|
||||||
|
|
||||||
-- import Debug.Trace (trace, traceStack)
|
-- import Debug.Trace (trace, traceStack)
|
||||||
|
|
||||||
|
@ -7,31 +7,11 @@ import HushGP.GP.PushArgs
|
|||||||
import HushGP.Instructions.Opens
|
import HushGP.Instructions.Opens
|
||||||
import HushGP.State
|
import HushGP.State
|
||||||
import HushGP.Utility
|
import HushGP.Utility
|
||||||
|
import HushGP.GP.Individual
|
||||||
|
|
||||||
-- import HushGP.Instructions
|
-- import HushGP.Instructions
|
||||||
-- import Debug.Trace
|
-- 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.
|
-- | Makes a random individual based on the variables in a passed PushArgs.
|
||||||
makeRandomIndividual :: PushArgs -> IO Individual
|
makeRandomIndividual :: PushArgs -> IO Individual
|
||||||
makeRandomIndividual pushArgs = do
|
makeRandomIndividual pushArgs = do
|
||||||
|
@ -23,3 +23,7 @@ mapIndexed = mapIndexed' 0
|
|||||||
mapIndexed' :: Int -> (Int -> a -> b) -> [a] -> [b]
|
mapIndexed' :: Int -> (Int -> a -> b) -> [a] -> [b]
|
||||||
mapIndexed' _ _ [] = []
|
mapIndexed' _ _ [] = []
|
||||||
mapIndexed' count f (x : xs) = f count x : mapIndexed' (count + 1) f xs
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user