dumb error in fitness-function

This commit is contained in:
Stefan Dresselhaus
2018-06-07 12:56:05 +02:00
parent eeacfad4f6
commit 8befc7c94d
2 changed files with 16 additions and 13 deletions

View File

@ -38,7 +38,7 @@ exampleEnvironment addedC es pred tox =
, maxCompound = maxCompoundWithoutGeneric + addedC
, toxicCompounds = tox --[(Produced FPP,0.1)] ++ tox
, possibleEnzymes = es -- [pps,fpps] ++ es
, settings = Settings { automimicry = False
, settings = Settings { automimicry = True
, predatorsRandom = False
, numPlants = 150
}
@ -88,7 +88,6 @@ loop loopAmount ps env = loop' loopAmount 0 ps env
toxins = toxicCompounds env
padded i str = take i $ str ++ repeat ' '
printEvery = 10
addedConstFitness = 0.1
loop' :: Int -> Int -> [Plant] -> Environment -> IO ()
loop' loopAmount curLoop plants e = unless (loopAmount+1 == curLoop) $ do
when (curLoop `mod` printEvery == 0) $ do
@ -97,7 +96,7 @@ loop loopAmount ps env = loop' loopAmount 0 ps env
putStrLn ""
putStrLn $ "Generation " ++ show curLoop ++ " of " ++ show loopAmount ++ ":"
newPlants <- flip runReaderT e $ do
(!fs,cs) <- unzip . fmap (\(f,c) -> (f,c)) <$> fitness plants
(!fs,cs) <- unzip <$> fitness plants
let fps = zip plants fs -- gives us plants & their fitness in a tuple
sumFitness = sum fs
when (curLoop `mod` printEvery == 0) $ liftIO $ do
@ -126,16 +125,16 @@ main :: IO ()
main = do
hSetBuffering stdin NoBuffering
--hSetBuffering stdout NoBuffering
randomCompounds <- makeHead (Substrate PPM) <$> generateTreeFromList 20 (toEnum <$> [(maxCompoundWithoutGeneric+1)..] :: [Compound]) -- generate roughly x compounds
randomCompounds <- makeHead (Substrate PPM) <$> generateTreeFromList 40 (toEnum <$> [(maxCompoundWithoutGeneric+1)..] :: [Compound]) -- generate roughly x compounds
ds <- randoms <$> newStdGen
probs <- randomRs (0.2,0.7) <$> newStdGen
let poisonedTree = poisonTree ds randomCompounds
poisonCompounds = foldMap (\(a,b) -> [(b,a) | a > 0.2]) poisonedTree
poisonCompounds = foldMap (\(a,b) -> [(b,a) | a > 0.5]) poisonedTree
predators <- generatePredators 0.5 poisonedTree
let env = exampleEnvironment (getTreeSize randomCompounds) (generateEnzymeFromTree randomCompounds) (zip predators probs) poisonCompounds
emptyPlants = replicate (numPlants . settings $ env) emptyPlant
enzs <- randomRs (0,length (possibleEnzymes env) - 1) <$> newStdGen
let startPlants = randomGenome 10 enzs (possibleEnzymes env) emptyPlants
let startPlants = randomGenome 1 enzs (possibleEnzymes env) emptyPlants
printEnvironment env
writeFile "poison.twopi" $ generateDotFromPoisonTree "poison" 0.5 poisonedTree
putStr "\ESC[?1049h"
@ -221,3 +220,6 @@ generateEnzymeFromTree t = (makeSimpleEnzyme c . getElement <$> sts)
where
c = getElement t
sts = getSubTrees t
stepDebug a = liftIO $ print a >> void getChar