How can I count dead turtles in Netlogo

I would like to know that the number of all turtles died in my pseudo-model. How can i do this? I would really appreciate a simple and quick solution to this problem, for example count dead turtles.

I thought about such a procedure (but I don’t 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 sample code (without checking 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
+4
source share
2 answers

I am afraid that you yourself must track this in a global variable. So add

globals [ number-dead ]

at the top of your model. Then change deathas follows:

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-deadit will always be equal to the number of dead turtles.

+5
source

It is really simple:

to setup
 let total-population count turtles
end

to go
 let current-population count turtles
 let dead-people total-population - current-population
ticks
end
0
source

All Articles