0

hope you can help me out! I have a NetLogo question about the following code:

breed [tourists tourist]

turtles-own [satisfaction]

to setup
  clear-all
  reset-ticks
end 

to go
  
  tick
  
  ask n-of initial-number-tourists patches
  [
    sprout 1 [
      set color white
      set size 1
    ]
  ]

  ask turtles
  [ let nearest min-one-of turtles [distance myself]
  if-else distance nearest < 0.0000001 [ set satisfaction 0 ]
    [ set satisfaction 1 ] 
  ]

  ask turtles with [satisfaction = 0] [die]

end

The intention is to sprout "initial-number-tourists" at the start of each tick. Then, they calculate their 'satisfaction' based on the if there are turtles close and let the turtles that have a satisfaction of 0 die. Then, the turtles that remain (that are satisfied) will be sprouted again and their satisfaction will be calculated again.

The code is working, however, with unexpected outcomes. What happens is that the turtles are all sprouted, and they all die each tick. The next tick; they are sprouted again and all die again. Even if i set the distance threshold really low like i did in the code I provided.

Hopefully you can help me out!! Kind regards

loet23
  • 21
  • 2

1 Answers1

1

The problem you are encountering is that the nearest turtle to each turtle is itself! Thus the distance to nearest is always zero and satisfaction will be set to zero for every turtle. What you want is the closest among the other turtles,

let nearest min-one-of other turtles [distance myself]

(Your distance threshold will mean that all turtles will have satisfaction of 1, but I assume that is what you wanted to accomplish in your testing. Since turtles are sprouted at the centers of the patches, a threshold of < 1.0 would accomplish the same thing.)

Minor point: the convention is to put tick at the end, not the beginning of the go procedure.

Charles
  • 3,888
  • 11
  • 13
  • Thank you very much! That makes a lot of sense and it works better now! The only thing is that i would like to sprout the turtles that were 'satisfied' in the previous tick in the next tick. The way I do it now, the satisfied turtles are added to the initial number of turtles. I would like to replace the initial number with only the satisfied turtles. Should i do this in the same tick? – loet23 Jan 17 '21 at 18:29
  • Let me see if I understand what you want. Say you start with 20 turtles in the first tick and 8 are satisfied. 12 will then die. On the next tick, do you want the same 8 satisfied turtles at the same locations and 12 new ones (initially unsatisfied since satisfaction is initialized to zero)? Or do you want only the 8 turtles at the same locations and still satisfied, or 8 turtles at new locations, or ...? – Charles Jan 18 '21 at 18:18
  • Thanks for your comment! Yes, what I want is that I would like to have 8 new turtles (the ones that were satisfied) sprouted at a new location in the next tick. To make it more clear: the model is about tourists at the beach. It is being assumed that the ones that were satisfied at day 1 (tick 1), will return at day 2 (tick 2), but then at a different location. Then their satisfaction is calculated againa, the same way. Is that possible? – loet23 Jan 19 '21 at 13:04
  • Hi Charles, I was wondering if you've seen my last comment! I'm still encountering the problem with my code: The problem is that the tourist don't leave at the end of the tick. I know it's because i sprout them again but i don't know how to do it another way.. I think it's really easy to solve but can not find the right solution – loet23 Jan 21 '21 at 17:37
  • If the tourists are to retain their identity and any variables associated with them, could you not simply have them move to a new (random) location at the beginning of the next tick (day) and then have first-time tourists sprouted for that day as well? Assuming you don't want more than one tourist on a patch, you could ask only patches without a turtle on them to sprout a first-time visitor. – Charles Jan 22 '21 at 14:21