better fitness

This commit is contained in:
Stefan Dresselhaus
2018-05-23 13:07:34 +02:00
parent 8eeb837b9f
commit ee008ba920
2 changed files with 25 additions and 8 deletions

View File

@ -151,7 +151,15 @@ fitness p = do
products <- produceCompounds p nutrients -- produce compounds
survivalRate <- deterPredators products -- defeat predators with produced compounds
let sumEnzymes = sum $ (\(_,q,a) -> fromIntegral q*a) <$> genome p -- amount of enzymes * activation = resources "wasted"
costOfEnzymes = 0.99 ** sumEnzymes
staticCostOfEnzymes = 1 - 0.01*sumEnzymes -- static cost of creating enzymes
-- primaryEnzymes = filter (\(e,_,_) -> case (fst.fst.synthesis) e of -- select enzymes which use substrate
-- Substrate _ -> True
-- otherwise -> False)
-- (genome p)
nutrientsAvailable <- fmap snd <$> asks soil
let nutrientsLeft = [products ! i | i <- [0..fromEnum (maxBound :: Nutrient)]]
nutrientRatio = minimum $ zipWith (/) nutrientsLeft nutrientsAvailable
costOfEnzymes = max 0 $ staticCostOfEnzymes - nutrientRatio * 0.1 -- cost to keep enzymes are static costs + amount of nutrient sucked out of the primary cycle
return $ survivalRate * costOfEnzymes
-- can also be written as, but above is more clear.
-- fitness p = absorbNutrients p >>= produceCompounds p >>= deterPredators
@ -174,16 +182,22 @@ produceCompounds (Plant genes _) substrate = do
return final
-- TODO:
-- - choose predators beforehand, then only apply those who appear in full force.
-- - dampen full-force due to auto-mimicry-effect. => Fitness would not depend on single plant.
deterPredators :: Vector Amount -> World Probability
deterPredators cs = do
ps <- asks predators
ts <- asks toxicCompounds
ds <- liftIO $ randoms <$> newStdGen
let
appearingPredators = fmap fst . filter (\((_,p),r) -> p > r) $ zip ps ds -- assign one probability to each predator, filter those who appear, throw random data away again.
-- appearingPredators is now a sublist of ps.
deter :: Predator -> Double
-- multiply (toxicity of t with 100% effectiveness at l| for all toxins t | and t not in p's irresistance-list)
deter p = product [1 - min 1 (cs ! fromEnum t / l) | (t,l) <- ts, t `elem` irresistance p]
-- multiply (probability of occurence * intensity of destruction / probability to deter predator | for all predators)
return $ product ([min 1 ((1-prob) * fitnessImpact p / deter p) | (p,prob) <- ps] `using` parList rdeepseq)
return $ product ([min 1 ((1-prob) * fitnessImpact p / deter p) | (p,prob) <- appearingPredators])
-- Mating & Creation of diversity
-- ------------------------------