Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Persefone.jl
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Persefone
Persefone.jl
Commits
b614eee8
Commit
b614eee8
authored
2 years ago
by
xo30xoqa
Browse files
Options
Downloads
Patches
Plain Diff
Added animal species traits
parent
d8c33a04
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/core/simulation.jl
+3
-2
3 additions, 2 deletions
src/core/simulation.jl
src/nature/nature.jl
+22
-0
22 additions, 0 deletions
src/nature/nature.jl
src/nature/wolpertinger.jl
+17
-8
17 additions, 8 deletions
src/nature/wolpertinger.jl
src/parameters.toml
+3
-3
3 additions, 3 deletions
src/parameters.toml
with
45 additions
and
13 deletions
src/core/simulation.jl
+
3
−
2
View file @
b614eee8
...
@@ -35,9 +35,10 @@ end
...
@@ -35,9 +35,10 @@ end
Execute one update of the model.
Execute one update of the model.
"""
"""
function
stepsimulation!
(
model
::
AgentBasedModel
)
function
stepsimulation!
(
model
::
AgentBasedModel
)
@info
"Simulating day
$
(model.date
+Day(1)
)."
@info
"Simulating day
$
(model.date)."
for
a
in
Schedulers
.
ByType
((
Farmer
,
Animal
,
CropPlot
),
true
)(
model
)
for
a
in
Schedulers
.
ByType
((
Farmer
,
Animal
,
CropPlot
),
true
)(
model
)
stepagent!
(
getindex
(
model
,
a
),
model
)
#The animal may have been killed, so we need a try/catch
try
stepagent!
(
getindex
(
model
,
a
),
model
)
catch
keyerror
end
end
end
savepopulationdata
(
model
)
savepopulationdata
(
model
)
model
.
date
+=
Day
(
1
)
model
.
date
+=
Day
(
1
)
...
...
This diff is collapsed.
Click to expand it.
src/nature/nature.jl
+
22
−
0
View file @
b614eee8
...
@@ -16,6 +16,7 @@ struct Species
...
@@ -16,6 +16,7 @@ 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
traits
::
Dict
{
String
,
Any
}
# a collection of species-specific traits
end
end
"""
"""
...
@@ -55,6 +56,27 @@ let specieslist = Dict{String, Species}()
...
@@ -55,6 +56,27 @@ let specieslist = Dict{String, Species}()
end
end
end
end
"""
newspecies(properties...)
A utility function to create and register a new species.
All function arguments are passed on to Species().
"""
function
newspecies
(
properties
...
)
registerspecies
(
Species
(
properties
...
))
end
"""
trait(animal, trait)
A utility function to return a trait value for this animal's species.
Returns nothing if the trait is not defined.
"""
function
trait
(
animal
::
Animal
,
trait
::
String
)
!
(
trait
in
keys
(
animal
.
species
.
traits
))
&&
(
return
nothing
)
return
animal
.
species
.
traits
[
trait
]
end
"""
"""
stepagent!(animal, model)
stepagent!(animal, model)
...
...
This diff is collapsed.
Click to expand it.
src/nature/wolpertinger.jl
+
17
−
8
View file @
b614eee8
...
@@ -13,11 +13,11 @@ Initialise a population of Wolpertingers in random locations around the landscap
...
@@ -13,11 +13,11 @@ 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"
)
x
,
y
=
size
(
model
.
landscape
)
x
,
y
=
size
(
model
.
landscape
)
popsize
=
Int
(
round
((
x
*
y
)
/
10000
))
popsize
=
Int
(
round
((
x
*
y
)
*
species
.
traits
[
"popdensity"
]
))
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
,
species
.
traits
[
"birthenergy"
]
)
end
end
@debug
"Hid
$(popsize)
W
olpertingers for gullible tourists to find."
@debug
"Hid
$(popsize)
w
olpertingers for gullible tourists to find."
end
end
"""
"""
...
@@ -29,13 +29,22 @@ and occasionally reproduce by spontaneous parthogenesis...
...
@@ -29,13 +29,22 @@ and occasionally reproduce by spontaneous parthogenesis...
function
updatewolpertinger!
(
w
::
Animal
,
model
::
AgentBasedModel
)
function
updatewolpertinger!
(
w
::
Animal
,
model
::
AgentBasedModel
)
# walk in a random direction
# walk in a random direction
direction
=
Tuple
(
rand
([
-
1
,
1
],
2
))
direction
=
Tuple
(
rand
([
-
1
,
1
],
2
))
walk!
(
w
,
direction
,
model
;
ifempty
=
false
)
speed
=
rand
([
1
,
trait
(
w
,
"maxspeed"
)])
w
.
energy
-=
rand
([
1
,
10
])
*
5
for
i
in
1
:
speed
walk!
(
w
,
direction
,
model
;
ifempty
=
false
)
end
w
.
energy
-=
speed
# reproduce every once in a blue moon
# reproduce every once in a blue moon
if
rand
()
<
0.0
1
if
rand
()
<
0.0
5
@debug
"Wolpertinger
$
(w.id) has reproduced."
@debug
"Wolpertinger
$
(w.id) has reproduced."
add_agent!
(
w
.
pos
,
Animal
,
model
,
getspecies
(
"Wolpertinger"
),
hermaphrodite
,
0
,
100
)
add_agent!
(
w
.
pos
,
Animal
,
model
,
getspecies
(
"Wolpertinger"
),
hermaphrodite
,
0
,
trait
(
w
,
"birthenergy"
))
end
end
end
end
registerspecies
(
Species
(
"Wolpertinger"
,
initwolpertinger!
,
updatewolpertinger!
))
newspecies
(
"Wolpertinger"
,
initwolpertinger!
,
updatewolpertinger!
,
Dict
(
"popdensity"
=>
1
/
10000
,
"birthenergy"
=>
400
,
"maxspeed"
=>
5
))
This diff is collapsed.
Click to expand it.
src/parameters.toml
+
3
−
3
View file @
b614eee8
...
@@ -9,19 +9,19 @@
...
@@ -9,19 +9,19 @@
[core]
[core]
configfile
=
"src/parameters.toml"
# location of the configuration file
configfile
=
"src/parameters.toml"
# location of the configuration file
landcovermap
=
"data/landcover_jena.tif"
# location of the landcover map
landcovermap
=
"data/landcover_jena.tif"
# location of the landcover map
farmfieldsmap
=
"data/fields_jena.tif"
# location of the field geometry map
TODO not the real file yet
farmfieldsmap
=
"data/fields_jena.tif"
# location of the field geometry map
outdir
=
"results"
# location and name of the output folder
outdir
=
"results"
# location and name of the output folder
loglevel
=
"debug"
# verbosity level: "debug", "info", "quiet"
loglevel
=
"debug"
# verbosity level: "debug", "info", "quiet"
seed
=
0
# seed value for the RNG (0 -> random value)
seed
=
0
# seed value for the RNG (0 -> random value)
# dates to start and end the simulation
# dates to start and end the simulation
startdate
=
2020-01-01
startdate
=
2020-01-01
enddate
=
2020-01-
05
enddate
=
2020-01-
31
[farm]
[farm]
[nature]
[nature]
targetspecies
=
[
"Wolpertinger"
]
# list of target species to simulate
targetspecies
=
[
"Wolpertinger"
,
"Wyvern"
]
# list of target species to simulate
[crop]
[crop]
cropmodel
=
"linear"
# crop growth model to use, "linear" or "aquacrop" (not yet implemented)
cropmodel
=
"linear"
# crop growth model to use, "linear" or "aquacrop" (not yet implemented)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment