Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

Distance-based mortality model in netlogo

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...