Skip to content
Snippets Groups Projects
Commit 2432ddff authored by xo30xoqa's avatar xo30xoqa
Browse files

@species syntax now works as intended :-)

Translated the Wolpertinger to the new syntax, Wyvern to follow later.
parent 71a01dca
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,7 @@ include("nature/nature.jl") ...@@ -46,7 +46,7 @@ include("nature/nature.jl")
include("nature/lifehistory.jl") include("nature/lifehistory.jl")
include("nature/ecologicaldata.jl") include("nature/ecologicaldata.jl")
#include("nature/species/skylark.jl") #include("nature/species/skylark.jl")
#include("nature/species/wolpertinger.jl") include("nature/species/wolpertinger.jl")
#include("nature/species/wyvern.jl") #include("nature/species/wyvern.jl")
include("core/simulation.jl") include("core/simulation.jl")
......
### Persephone - a socio-economic-ecological model of European agricultural landscapes. ### Persephone - a socio-economic-ecological model of European agricultural landscapes.
### ###
### This file manages the landscape maps that underlie the model. ### This file manages the landscape maps that underlie the model.
...@@ -40,7 +41,7 @@ function initlandscape() ...@@ -40,7 +41,7 @@ function initlandscape()
lc = landcover[x,y][1] lc = landcover[x,y][1]
(ismissing(lc)) && (lc = 0) (ismissing(lc)) && (lc = 0)
lcv = LandCover(Int(lc/10)) lcv = LandCover(Int(lc/10))
landscape[x,y] = Pixel(lcv, farmfields[x,y][1]) landscape[x,y] = Pixel(lcv, farmfields[x,y][1], Vector{Symbol}())
end end
end end
return landscape return landscape
......
...@@ -14,7 +14,7 @@ Create output files for each data group collected by the nature model. ...@@ -14,7 +14,7 @@ Create output files for each data group collected by the nature model.
function initecologicaldata() function initecologicaldata()
newdataoutput(POPFILE, "Date;Species;Abundance", savepopulationdata, newdataoutput(POPFILE, "Date;Species;Abundance", savepopulationdata,
param("nature.popoutfreq")) param("nature.popoutfreq"))
newdataoutput(INDFILE, "Date;ID;X;Y;Species;Sex;Age;Energy", newdataoutput(INDFILE, "Date;ID;X;Y;Species;Sex;Age",
saveindividualdata, param("nature.indoutfreq")) saveindividualdata, param("nature.indoutfreq"))
end end
...@@ -29,7 +29,7 @@ function savepopulationdata(model::AgentBasedModel) ...@@ -29,7 +29,7 @@ function savepopulationdata(model::AgentBasedModel)
pops = Dict{String,Int}(s=>0 for s = param("nature.targetspecies")) pops = Dict{String,Int}(s=>0 for s = param("nature.targetspecies"))
for a in allagents(model) for a in allagents(model)
(typeof(a) != Animal) && continue (typeof(a) != Animal) && continue
pops[a.species.name] += 1 pops[a.traits["name"]] += 1
end end
data = "" data = ""
for p in keys(pops) for p in keys(pops)
...@@ -50,7 +50,7 @@ function saveindividualdata(model::AgentBasedModel) ...@@ -50,7 +50,7 @@ function saveindividualdata(model::AgentBasedModel)
data = "" data = ""
for a in allagents(model) for a in allagents(model)
(typeof(a) != Animal) && continue (typeof(a) != Animal) && continue
entry = join([model.date,a.id,a.pos[1],a.pos[2],a.species.name,a.sex,a.age,a.energy], ";") entry = join([model.date,a.id,a.pos[1],a.pos[2],a.traits["name"],a.sex,a.age], ";")
data *= entry*"\n" data *= entry*"\n"
end end
data data
......
...@@ -5,49 +5,34 @@ ...@@ -5,49 +5,34 @@
### Although I dare say the Wolpertinger is probably rather endangered... ### Although I dare say the Wolpertinger is probably rather endangered...
### ###
##TODO convert to @species syntax
""" """
initwolpertinger!(model) The wolpertinger is a mysterious beast, found in the hills and alps of Bavaria.
It is purported to have the body of a hare, the wings of a bird, and the antlers
Initialise a population of Wolpertingers in random locations around the landscape. of a deer.
""" """
function initwolpertinger!(model::AgentBasedModel) @species Wolpertinger begin
species = getspecies("Wolpertinger") popdensity = 1/100000
x, y = size(model.landscape) fecundity = 0.02
popsize = Int(round((x*y)*species.traits["popdensity"])) mortality = 0.01
for i in 1:popsize maxspeed = 5
add_agent!(Animal, model, species, hermaphrodite, 0, species.traits["birthenergy"])
end
@debug "Hid $(popsize) wolpertingers for gullible tourists to find."
end
""" initialise! = initrandompopulation(popdensity)
updatewolpertinger(animal, model) phase = "lifephase"
Wolpertingers are rather stupid creatures, all they do is move around randomly """
and occasionally reproduce by spontaneous parthogenesis... Wolpertingers are rather stupid creatures, all they do is move around randomly
""" and occasionally reproduce by spontaneous parthogenesis...
function updatewolpertinger!(w::Animal, model::AgentBasedModel) """
# walk in a random direction @phase lifephase begin
direction = Tuple(rand([-1,1], 2)) direction = Tuple(rand([-1,1], 2))
speed = rand([1, trait(w, "maxspeed")]) for i in 1:rand(1:@trait(maxspeed))
for i in 1:speed walk!(animal, direction, model; ifempty=false)
walk!(w, direction, model; ifempty=false) end
end
w.energy -= speed if rand() < @trait(fecundity)
# reproduce every once in a blue moon @reproduce
if rand() < trait(w, "fecundity") end
@debug "Wolpertinger $(w.id) has reproduced."
add_agent!(w.pos, Animal, model, getspecies("Wolpertinger"), @kill @trait(mortality)
hermaphrodite, 0, trait(w, "birthenergy"))
end end
end end
newspecies("Wolpertinger",
initwolpertinger!,
updatewolpertinger!,
Dict("popdensity"=>1/10000,
"birthenergy"=>400,
"fecundity"=>0.01,
"maxspeed"=>5))
...@@ -18,10 +18,10 @@ startdate = 2020-01-01 ...@@ -18,10 +18,10 @@ startdate = 2020-01-01
enddate = 2020-12-31 enddate = 2020-12-31
[farm] [farm]
farmmodel = "FieldManager" # which version of the farm model to use
[nature] [nature]
targetspecies = ["Wolpertinger", "Wyvern"] # list of target species to simulate targetspecies = ["Wolpertinger"] # list of target species to simulate
popoutfreq = "daily" # output frequency population-level data, daily/monthly/yearly/end/never popoutfreq = "daily" # output frequency population-level data, daily/monthly/yearly/end/never
indoutfreq = "end" # output frequency individual-level data, daily/monthly/yearly/end/never indoutfreq = "end" # output frequency individual-level data, daily/monthly/yearly/end/never
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment