Katie Tseng
Katie Tseng

Reputation: 1

NetLogo: reporters not reporting correctly by turtle breed

I have the following chunk of code:

to volver-a-casa
   (ifelse estado < 6 or estado = 8
      if donde != 1 [
        move-to mi-casa
        set donde 1
        set nro-personas nro-personas + 1     
        set color color + 10
      ]
   estado = 7 [
     set nro-personas nro-personas - 1
     set nro-fallecidos nro-fallecidos + 1
     set nro-fallecidos1 count personas1 with [estado = 7]
     set nro-fallecidos2 count personas2 with [estado = 7]
     set nro-fallecidos3 count personas3 with [estado = 7]
     set nro-fallecidos4 count personas4 with [estado = 7]
     move-to mi-casa
     set fallecidos fallecidos + 1
     die
   ]
  )

In my infectious disease model, I have 4 breeds of turtles (personas1, personas2, etc.) where estado is a turtle variable with 9 different categories or "states". The turtles transition to different states (estado) as they move been different types of patches (work, school, home). For each breed, there is a global reporter variable nropersonas that counts the number of turtles with estado = 7. I also attempted to construct separate global reporter variables (nrofallecidos1, nrofallecidos2, etc.) to count the number of turtles by breed that have estado = 7. nropersonas successfully counts the total number of turtles at each tick that has estado = 7, but my breed-specific reporter variables, nrofallecidos1, nrofallecidos2, etc., are not reporting at all (turtle count is 0 across all reporters).

Any help would be appreciated. Thank you!

Upvotes: 0

Views: 43

Answers (1)

LittleLynx
LittleLynx

Reputation: 1181

I noticed two things:

  1. When you use ifelse, you only have to state the condition for the first case (estado < 6 or estado = 8 in your case). The contrary (estado = 7) is implicated by logic and has to be deleted from your code. In the code below, I kept it as a comment.
  2. To be more clear about what happend, you can add more square brackets. I like to have opening and closing brackets at the same level, but that's a style question.

Correct syntax is:

to volver-a-casa
ifelse estado < 6 or estado = 8
[
  if donde != 1 
  [
    move-to mi-casa
    set donde 1
    set nro-personas nro-personas + 1     
    set color color + 10
  ]
]
[
  ; in this case estado is 7
  set nro-personas nro-personas - 1
  set nro-fallecidos nro-fallecidos + 1
  set nro-fallecidos1 count personas1 with [estado = 7]
  set nro-fallecidos2 count personas2 with [estado = 7]
  set nro-fallecidos3 count personas3 with [estado = 7]
  set nro-fallecidos4 count personas4 with [estado = 7]
  move-to mi-casa
  set fallecidos fallecidos + 1
  die
]
end

Upvotes: 1

Related Questions