Tree generates arbitrary compounds (needs rename -.-)

This commit is contained in:
Stefan Dresselhaus
2018-05-07 00:44:12 +02:00
parent 723df072c1
commit cd16dbb39b
6 changed files with 185 additions and 35 deletions

View File

@ -1,8 +1,5 @@
{-# LANGUAGE TypeApplications #-}
module Main where
import Environment
import Text.Printf
import Control.Monad.Reader
import Numeric.LinearAlgebra
@ -12,6 +9,8 @@ import Control.Concurrent
import qualified Debug.Trace as Debug
import System.IO
import ArbitraryEnzymeTree
import Environment
-- Example definitions
-- -------------------
@ -31,8 +30,8 @@ greenfly = Predator [] 0.2 -- killed by any toxic Component
-- Environment
exampleEnvironment :: Environment
exampleEnvironment =
exampleEnvironment :: Int -> [Enzyme] -> Environment
exampleEnvironment addedC es =
Environment
{ soil = [ (Nitrate, 2)
, (Phosphor, 3)
@ -40,9 +39,9 @@ exampleEnvironment =
]
, predators = [ (greenfly, 0.1) ]
, metabolismIteration = 100
, maxCompound = maxCompoundWithoutGeneric
, maxCompound = maxCompoundWithoutGeneric + addedC
, toxicCompounds = [(Produced FPP,0.5)] --FPP kills 100% if produced amount above 0.2 units
, possibleEnzymes = [pps,fpps]
, possibleEnzymes = [pps,fpps] ++ es
}
-- Plants
@ -111,10 +110,12 @@ main :: IO ()
main = do
hSetBuffering stdin NoBuffering
hSetBuffering stdout NoBuffering
let emptyPlants = replicate 100 emptyPlant
printEnvironment exampleEnvironment
randomCompounds <- generateTreeFromList 10 (toEnum <$> [(maxCompoundWithoutGeneric+1)..] :: [Compound]) -- generate roughly 10 compounds
let env = exampleEnvironment (getTreeSize randomCompounds) (generateEnzymeFromTree randomCompounds)
emptyPlants = replicate 100 emptyPlant
printEnvironment env
putStr "\ESC[?1049h"
loop 100 emptyPlants exampleEnvironment
loop 100 emptyPlants env
putStrLn "Simulation ended. Press key to exit."
_ <- getChar
putStr "\ESC[?1049l"
@ -170,3 +171,10 @@ printColor x c
colorOff :: String
colorOff = "\ESC[0m"
generateEnzymeFromTree :: EnzymeTree s Compound -> [Enzyme]
generateEnzymeFromTree t = (makeSimpleEnzyme c . getElement <$> sts)
++ concatMap generateEnzymeFromTree sts
where
c = getElement t
sts = getSubTrees t