diff --git a/README.md b/README.md index 8772a49d0f31368bae70d1b0c4a700a135244f5e..7337725e9b1bfd1af3d7666318ecc7b350daf5d8 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ optional arguments: name of the map file -o, --outdir OUTDIR location of the output directory -l, --loglevel LOGLEVEL - verbosity: "debug", "info", or "errors" + verbosity: "debug", "info", or "quiet" -r, --runtime RUNTIME duration in days that the simulation will run (type: Int64) diff --git a/src/core/input.jl b/src/core/input.jl index 193fae5bbed929330fc6f088f37a15e50d646303..539056531a71f8b3fb5f1d295c903b90ca2488b2 100644 --- a/src/core/input.jl +++ b/src/core/input.jl @@ -107,7 +107,7 @@ function parsecommandline() arg_type = String required = false "--loglevel", "-l" - help = "verbosity: \"debug\", \"info\", or \"errors\"" + help = "verbosity: \"debug\", \"info\", or \"quiet\"" arg_type = String required = false "--runtime", "-r" @@ -122,13 +122,3 @@ function parsecommandline() args end -""" - readtiffmapfile(filename) - -Read in a TIFF map file and return it as an array. -""" -function readtiffmapfile(filename) - tiff = GeoArrays.read(filename) - space = GridSpace(size(tiff)[1:2], periodic=false) - #TODO this requires GeoArrays -end diff --git a/src/core/simulation.jl b/src/core/simulation.jl index 8b0fc7261fd36bef4e2d0c4b44b28046c69a39d2..8337356dd35f979c656813dbecd15a7958b24e57 100644 --- a/src/core/simulation.jl +++ b/src/core/simulation.jl @@ -11,8 +11,10 @@ and instantiate the AgentBasedModel object. """ function initialise(config::String=PARAMFILE) initsettings(config) + Random.seed!(param("core.seed")) setupdatadir() landcover = GeoArrays.read(param("core.mapfile")) + #TODO load field map space = GridSpace(size(landcover)[1:2], periodic=false) properties = Dict{Symbol,Any}(:day=>0, :landcover=>landcover) @@ -25,7 +27,6 @@ function initialise(config::String=PARAMFILE) model end - """ stepsimulation!(model) @@ -40,19 +41,17 @@ function stepsimulation!(model::AgentBasedModel) #TODO end - """ finalise(model) Wrap up the simulation. Output all remaining data and exit. """ function finalise(model::AgentBasedModel) - @info "Simulation ran. Nothing happened. But it will!" + @info "Simulation ran. Things are beginning to happen!" #TODO genocide!(model) end - """ simulate(config) diff --git a/src/nature/nature.jl b/src/nature/nature.jl index e2b7cf102b3e4f75d7457773f32e46ca0fe0d224..87776e235a81c519daa14e4ca8471b03303c72cb 100644 --- a/src/nature/nature.jl +++ b/src/nature/nature.jl @@ -13,8 +13,8 @@ initialise their population and update each individual. """ struct Species name::String - initpop::Function # takes one argument: model - update::Function # takes two arguments: animal, model + initpop!::Function # takes one argument: model + update!::Function # takes two arguments: animal, model end """ @@ -31,6 +31,7 @@ by the `species` struct passed by them during initialisation. energy::Int32 end +# This dict stores the definitions for all species that can be simulated let specieslist = Dict{String, Species}() """ registerspecies(species) @@ -59,8 +60,9 @@ Update an animal by one day. """ function stepagent!(animal::Animal, model::AgentBasedModel) animal.age += 1 - animal.species.update(animal,model) + animal.species.update!(animal,model) if animal.energy <= 0 + @debug "$(animal.species.name) $(animal.id) has died." kill_agent!(animal, model) end end @@ -71,8 +73,9 @@ end Initialise the model with all simulated animal populations. """ function initnature!(model::AgentBasedModel) + #The config file determines which species are simulated in this run for s in param("nature.targetspecies") - getspecies(s).initpop(model) + getspecies(s).initpop!(model) end end diff --git a/src/nature/wolpertinger.jl b/src/nature/wolpertinger.jl index 8875ec55bd2466a4a90f359878e995537dadd335..2cb2b92414a0fbe7b1d37a31da7246b2f23ac0c7 100644 --- a/src/nature/wolpertinger.jl +++ b/src/nature/wolpertinger.jl @@ -2,7 +2,7 @@ ### ### This file holds the code for the Wolpertinger (https://en.wikipedia.org/wiki/Wolpertinger). ### NOT FOR ACTUAL USE! This is of course only a test species ;-) -### Although I dare say the Wolpertinger is rather endangered... +### Although I dare say the Wolpertinger is probably rather endangered... ### """ @@ -12,8 +12,8 @@ Initialise a population of Wolpertingers in random locations around the landscap """ function initwolpertinger!(model::AgentBasedModel) species = getspecies("Wolpertinger") - worldsize = size(model.landcover)[1:2] - popsize = round(worldsize[1]*worldsize[2]/1000) + x, y = size(model.landcover) + popsize = Int(round((x*y)/10000)) for i in 1:popsize add_agent!(Animal, model, species, hermaphrodite, 0, 100) end @@ -27,8 +27,15 @@ Wolpertingers are rather stupid creatures, all they do is move around randomly and occasionally reproduce by spontaneous parthogenesis... """ function updatewolpertinger!(w::Animal, model::AgentBasedModel) - #TODO - @debug "The Wolpertinger is a mysterious animal..." w.id + # walk in a random direction + direction = Tuple(rand([-1,1], 2)) + walk!(w, direction, model; ifempty=false) + w.energy -= rand([1, 10])*5 + # reproduce every once in a blue moon + if rand() < 0.01 + @debug "Wolpertinger $(w.id) has reproduced." + add_agent!(w.pos, Animal, model, getspecies("Wolpertinger"), hermaphrodite, 0, 100) + end end registerspecies(Species("Wolpertinger", initwolpertinger!, updatewolpertinger!))