Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...