Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I count dead turtles in Netlogo

Tags:

netlogo

I would like to know the numbers of all turtles died in my pseudo model. How can I do that? I would appreciate very much a simply and fast running solution for that problem, like count dead turtles.

I was thinking of a routine like this (but do not know how to implement it):

if turtle is dead % checking all turtles if dead or alive set death_count death_count + 1 % set counter tick % go one step ahead in model

This is my code sample (without any check so far):

breed [ humans human ]
humans-own [ age ]

to setup
  ca

  create-humans(random 100)
  [
    setxy random-xcor random-ycor
    set age (random 51)
  ]

  reset-ticks
end

to death
  ask humans [
     if floor (ticks mod 1) = 0 [
       set age age + 1 ]
     if age > 85 [ die ]
  ]
end

to go
  death
  tick
  if ticks > 20 [ stop ]
end
like image 649
Til Hund Avatar asked Dec 08 '14 14:12

Til Hund


1 Answers

I'm afraid you have to keep track of it yourself in a global variable. So, add

globals [ number-dead ]

to the top of your model. Then, change death like so:

to death
  ask humans [
     if floor (ticks mod 1) = 0 [
       set age age + 1 ]
     if age > 85 [
       set number-dead number-dead + 1
       die
     ]
  ]
end

Then number-dead will always be equal to the number of turtles that have died.

like image 68
Bryan Head Avatar answered Nov 17 '22 11:11

Bryan Head