Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does an Agentset button behave different than an observer button asking the agentset?

Tags:

netlogo

I see a behavior difference between an agentset button (patch, turtle, link) which runs a certain section of code and an observer button which asks patches (or turtles, or links) to run the same section of code. Is this a bug in NetLogo? Is this a bug in my code?

like image 802
Robert Grider Avatar asked Jan 12 '16 17:01

Robert Grider


People also ask

What is an agentset in NetLogo?

Agents are beings that can follow instructions. In NetLogo, there are four types of agents: turtles, patches, links, and the observer. Turtles are agents that move around in the world. The world is two dimensional and is divided up into a grid of patches.

What code does NetLogo use?

What programming language was NetLogo written in? NetLogo is written mostly in Scala, with some parts in Java. (Scala code compiles to Java byte code and is fully interoperable with Java and other JVM languages.)


1 Answers

The cause of the behavior difference isn't actually a bug, but a rather obscure corner of NetLogo. The ask-concurrent primitive lies at the core of this behavior. An agentset button uses the same mechanism as ask-concurrent behind the scenes. Replacing any agentset button with an observer button which uses ask-concurrent to run the same code on the same agentset shouldn't change the behavior of the button.

Typically the differences between ask and ask-concurrent don't amount to much. Turtles may move slightly differently, but it will work basically the same. In some cases though, the differences can be really dramatic. The NetLogo Models Library provides a model called "Ask-Concurrent Example" which explores the differences between ask and ask-concurrent.

There is also documentation on this in the NetLogo Programming Guide, in the "Turtle, patch, and link forever buttons" section of http://ccl.northwestern.edu/netlogo/docs/programming.html#buttons; much of the section on ask-concurrent at http://ccl.northwestern.edu/netlogo/docs/programming.html#ask-concurrent also applies.

Note: Use of ask-concurrent isn't recommended. I'm using it here to clarify the behavior, but it should not be used in general.

Note 2: In general, the safest and most predictable approach is not to use turtle, patch, and link buttons at all. Instead, use observer buttons only, and use ask turtles, ask patches, or ask links in the button code, as appropriate.

like image 73
Robert Grider Avatar answered Oct 08 '22 12:10

Robert Grider