问题
I am calculating cumulative turtle mortality in netlogo as a function of distance moved by turtles (100 of them) from the origin (start-patch
) in the netlogo interface world. In the code below the 'Pass-Away
' procedure is linked to a global interface switch called "space-death" which when switched on yields said distance-based mortality undertaken by the procedure called "Pass-Away-Space
", otherwise maintains regular per-time-step (tick
) mortality undertaken by the procedure called "Pass-Away-Time
":
to Pass-Away-Time
ask turtles [
let chances 1 - exp( -1 * mortality * ticks )
if chances >= 1 [die
set dead-count dead-count + 1
]
]
end
to Pass-Away-Space
ask turtles [
let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles)
if chances >= 1 [die
set dead-count dead-count + 1
]
]
end
to Pass-Away
ask turtles [
ifelse space-death [
Pass-Away-Space][
Pass-Away-Time
]
]
end
I get two errors doing this, both likely due to issues with the coding of the "Pass-Away-Space
" procedure. The first is Only the observer can ASK the set of all turtles. Then when I move the let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles)
outside of the ask turtles[]
brackets this error is resolved only yield another that says ** expected input to be a number but got the list* followed by a sequence of numbers. Perhaps due to the fact that the section of the mortality equation that reads * [distance start-patch] of turtles
is invoked for multiple turtles (which is exactly what I want to achieve - have each random-walking turtle use its distance from the origin to calculate its cumulative per-step mortality and die above a threshold - an event that occurs at different times for different turtles at different distances). Any thoughts on how to resolve this?
回答1:
The first error is because you are asking all turtles to ask all turtles. Starting with your Pass-Away
procedure and assuming space-death
is set to TRUE. What happens? You ask all turtles to run the Pass-Away-Space
procedure. That is, each turtle will run that procedure in turn. The first step of that procedure is to ask turtles [ ]
. So a turtle is asking all turtles to do something. Hence the error.
To fix it, you need to rewrite the Pass-Away-Space
procedure so it runs whatever code needs to be run for a SINGLE turtle (and similarly for Pass-Away-Time
). You probably want something like:
to Pass-Away-Space
if exp( -1 * mortality * [distance start-patch]) < 0
[ die
set dead-count dead-count + 1
]
end
回答2:
So the first issue here is the nested use of the ask turtles [ ... ]
command, which we can disambiguate by removing it from the to Pass-Away
procedure or alternatively, from both of the other two (preceding) functions nested within it, as seen below (demonstrating the later of the aforementioned means.
let start-patch patch 0 0
to Pass-Away-Time
ask turtles [
let chances 1 - exp( -1 * mortality * ticks )
if chances >= 1 [die
set dead-count dead-count + 1
]
]
end
to Pass-Away-Space
ask turtles [
; let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles)
let chances 1 - exp( -1 * mortality * (distance start-patch))
if chances >= 1 [die
set dead-count dead-count + 1
]
]
end
to Pass-Away
ifelse space-death [
Pass-Away-Space][
Pass-Away-Time
]
end
The second error can be resolved by switching the line of code commented (;
) out in the to Pass-Away-Space
procedure withe the immediate succeeding line so that when each turtle attempts to execute chances
, cumulative per-distance (from origin) mortality is not calculated as an array of turtle chances with the use of the [distance start-patch] of turtles
command, but rather per individual turtle with (distance start-patch)
whenever the procedure is called by the nesting to Pass-Away
procedure.
来源:https://stackoverflow.com/questions/44146656/distance-based-mortality-model-in-netlogo