nigus21
nigus21

Reputation: 339

Calculating turtle mortality based on distance from origin in netlogo

I am writing a procedure (Pass-Away-Space) to calculate mortality of turtles moving from the origin (start-patch) through out the world. Each turtle calculates its own mortality based on its distance from the origin (start-patch). The code I am attempting to implement for this procedure is as follows:

    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

The error I am getting is expected input to be a number but got the list. I am not sure what the issue is and I was wondering if anyone could point out and rectify the problem with the code.

Upvotes: 1

Views: 139

Answers (1)

Luke C
Luke C

Reputation: 10301

The problem here is your of turtles. Since an ask procedure affects one turtle at a time, each turtle in your procedure above is evaluating the [distance start-patch] of all turtles instead of just its own distance to the start patch. To clarify, check out the following setup:

globals [ start-patch ]

to setup
  ca
  reset-ticks
  crt 10 [
    setxy random 30 - 15 random 30 - 15
  ]
  set start-patch patch 0 0
end

to incorrect-example
  ask turtles [
    print ([ distance start-patch ] of turtles)
  ]
end

to correct-example
  ask turtles [
    print distance start-patch
  ]
end

Compare the print output of the incorrect-example and the correct-example procedures, and you'll see that when you use [distance start-patch] of turtles you get the list of distances of all turtles. When you ask turtles to evaluate a turtles-own variable (including color, size, etc) each turtle will automatically access its own version of that variable- there's no need to specify which turtle. So, your pass-away-space might look something more like below (untested):

to Pass-Away-Space
  ask turtles [
    let chances 1 - exp( -1 * mortality * (distance start-patch) )
    if chances >= 1 [
      die
    set dead-count dead-count + 1
    ]
  ]
end

Upvotes: 1

Related Questions