How do I change the turtle attribute if one of its links disappears?

In NetLogo: suppose the model has

  • turtle (0) of breed A with non-oriented links with three turtles (1, 2 and 3) of breed B;
  • turtle 0 has an attribute named "link count" equal to 3.

Now let one of 3 neighbors 0 die.

How can I program turtle 0 to automatically change the number of its references to 2?

+3


source to share


1 answer


If all you want is a way to track number references, use count my-links

a custom variable instead.

In general, the smallest error in updating a value when the reference count changes is to calculate that value when you need it. It's easy for the number of links count my-links

. For more complex things, wrap them in a reporter:

to-report energy-of-neighbors
  report sum [ energy ] of link-neighbors
end

      

If this doesn't work for any reason (agents must respond when a link disappears, or you see a severe, measurable performance impact on computation on the fly), you'll have to make updates yourself when the link count changes. The best way to do this is to encapsulate the team behavior:



to update-on-link-change [ link-being-removed ] ;; turtle procedure
  ; update stuff
end

      

and then encapsulate things that can cause the number of references to change (like death of turtles) in commands:

to linked-agent-death ;; turtle procedure
  ask links [
    ask other-end [ update-on-link-change myself ]
  ]
  die
end

      

+3


source







All Articles