Skip to content
Snippets Groups Projects
Commit 820d7a7d authored by xo30xoqa's avatar xo30xoqa
Browse files

Gave the Wolpertinger something to do...

parent c9136d3f
No related branches found
No related tags found
No related merge requests found
...@@ -49,7 +49,7 @@ optional arguments: ...@@ -49,7 +49,7 @@ optional arguments:
name of the map file name of the map file
-o, --outdir OUTDIR location of the output directory -o, --outdir OUTDIR location of the output directory
-l, --loglevel LOGLEVEL -l, --loglevel LOGLEVEL
verbosity: "debug", "info", or "errors" verbosity: "debug", "info", or "quiet"
-r, --runtime RUNTIME -r, --runtime RUNTIME
duration in days that the simulation will run duration in days that the simulation will run
(type: Int64) (type: Int64)
......
...@@ -107,7 +107,7 @@ function parsecommandline() ...@@ -107,7 +107,7 @@ function parsecommandline()
arg_type = String arg_type = String
required = false required = false
"--loglevel", "-l" "--loglevel", "-l"
help = "verbosity: \"debug\", \"info\", or \"errors\"" help = "verbosity: \"debug\", \"info\", or \"quiet\""
arg_type = String arg_type = String
required = false required = false
"--runtime", "-r" "--runtime", "-r"
...@@ -122,13 +122,3 @@ function parsecommandline() ...@@ -122,13 +122,3 @@ function parsecommandline()
args args
end 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
...@@ -11,8 +11,10 @@ and instantiate the AgentBasedModel object. ...@@ -11,8 +11,10 @@ and instantiate the AgentBasedModel object.
""" """
function initialise(config::String=PARAMFILE) function initialise(config::String=PARAMFILE)
initsettings(config) initsettings(config)
Random.seed!(param("core.seed"))
setupdatadir() setupdatadir()
landcover = GeoArrays.read(param("core.mapfile")) landcover = GeoArrays.read(param("core.mapfile"))
#TODO load field map
space = GridSpace(size(landcover)[1:2], periodic=false) space = GridSpace(size(landcover)[1:2], periodic=false)
properties = Dict{Symbol,Any}(:day=>0, properties = Dict{Symbol,Any}(:day=>0,
:landcover=>landcover) :landcover=>landcover)
...@@ -25,7 +27,6 @@ function initialise(config::String=PARAMFILE) ...@@ -25,7 +27,6 @@ function initialise(config::String=PARAMFILE)
model model
end end
""" """
stepsimulation!(model) stepsimulation!(model)
...@@ -40,19 +41,17 @@ function stepsimulation!(model::AgentBasedModel) ...@@ -40,19 +41,17 @@ function stepsimulation!(model::AgentBasedModel)
#TODO #TODO
end end
""" """
finalise(model) finalise(model)
Wrap up the simulation. Output all remaining data and exit. Wrap up the simulation. Output all remaining data and exit.
""" """
function finalise(model::AgentBasedModel) function finalise(model::AgentBasedModel)
@info "Simulation ran. Nothing happened. But it will!" @info "Simulation ran. Things are beginning to happen!"
#TODO #TODO
genocide!(model) genocide!(model)
end end
""" """
simulate(config) simulate(config)
......
...@@ -13,8 +13,8 @@ initialise their population and update each individual. ...@@ -13,8 +13,8 @@ initialise their population and update each individual.
""" """
struct Species struct Species
name::String name::String
initpop::Function # takes one argument: model initpop!::Function # takes one argument: model
update::Function # takes two arguments: animal, model update!::Function # takes two arguments: animal, model
end end
""" """
...@@ -31,6 +31,7 @@ by the `species` struct passed by them during initialisation. ...@@ -31,6 +31,7 @@ by the `species` struct passed by them during initialisation.
energy::Int32 energy::Int32
end end
# This dict stores the definitions for all species that can be simulated
let specieslist = Dict{String, Species}() let specieslist = Dict{String, Species}()
""" """
registerspecies(species) registerspecies(species)
...@@ -59,8 +60,9 @@ Update an animal by one day. ...@@ -59,8 +60,9 @@ Update an animal by one day.
""" """
function stepagent!(animal::Animal, model::AgentBasedModel) function stepagent!(animal::Animal, model::AgentBasedModel)
animal.age += 1 animal.age += 1
animal.species.update(animal,model) animal.species.update!(animal,model)
if animal.energy <= 0 if animal.energy <= 0
@debug "$(animal.species.name) $(animal.id) has died."
kill_agent!(animal, model) kill_agent!(animal, model)
end end
end end
...@@ -71,8 +73,9 @@ end ...@@ -71,8 +73,9 @@ end
Initialise the model with all simulated animal populations. Initialise the model with all simulated animal populations.
""" """
function initnature!(model::AgentBasedModel) function initnature!(model::AgentBasedModel)
#The config file determines which species are simulated in this run
for s in param("nature.targetspecies") for s in param("nature.targetspecies")
getspecies(s).initpop(model) getspecies(s).initpop!(model)
end end
end end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
### ###
### This file holds the code for the Wolpertinger (https://en.wikipedia.org/wiki/Wolpertinger). ### 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 ;-) ### 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 ...@@ -12,8 +12,8 @@ Initialise a population of Wolpertingers in random locations around the landscap
""" """
function initwolpertinger!(model::AgentBasedModel) function initwolpertinger!(model::AgentBasedModel)
species = getspecies("Wolpertinger") species = getspecies("Wolpertinger")
worldsize = size(model.landcover)[1:2] x, y = size(model.landcover)
popsize = round(worldsize[1]*worldsize[2]/1000) popsize = Int(round((x*y)/10000))
for i in 1:popsize for i in 1:popsize
add_agent!(Animal, model, species, hermaphrodite, 0, 100) add_agent!(Animal, model, species, hermaphrodite, 0, 100)
end end
...@@ -27,8 +27,15 @@ Wolpertingers are rather stupid creatures, all they do is move around randomly ...@@ -27,8 +27,15 @@ Wolpertingers are rather stupid creatures, all they do is move around randomly
and occasionally reproduce by spontaneous parthogenesis... and occasionally reproduce by spontaneous parthogenesis...
""" """
function updatewolpertinger!(w::Animal, model::AgentBasedModel) function updatewolpertinger!(w::Animal, model::AgentBasedModel)
#TODO # walk in a random direction
@debug "The Wolpertinger is a mysterious animal..." w.id 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 end
registerspecies(Species("Wolpertinger", initwolpertinger!, updatewolpertinger!)) registerspecies(Species("Wolpertinger", initwolpertinger!, updatewolpertinger!))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment