Reputation: 31
There are different colored turtles in my model each operating under different rules. I want procedures governing the movement of one turtle(say, red turtle) to run simultaneously with other procedures governing the movement of different colored turtles.
Upvotes: 2
Views: 646
Reputation: 9610
Suppose you have two turtle procedures do-red
and do-blue
that you want to run on red and blue turtles. Then you can just ask turtles [do-something]
and condition on the color. Assuming you are not changing the colors:
to do-something ;; turtle proc
if (color = red) [do-red]
if (color = blue) [do-blue]
end
EDIT:
This does not provide true concurrency, but seriously, how often can agent behavior be truly concurrent? For example, if do-red
affects other turtles (red or blue), what is the "concurrent" outcome when turtle 0
and turtle 1
both influence turtle 2
, who responds only to individual influences. To give another example, if you want every turtle to choose an unoccupied patch to move to, and two choose the same patch, who wins? The is why update-state
solutions cannot address the general problem of concurrency. Of course, it is still crucial for some problems. (E.g., CA.)
Upvotes: 1
Reputation: 9796
I don't think Alan's answer is complete. Here he is assuming do-red doesn't effect blue turtles. To simulate concurrency you need to store the state and update it later. All computations will performed on the stored state in the given time-step.
Example Using Alan's code:
to do-something ;; turtle proc
if (color = red) [do-red]
if (color = blue) [do-blue]
update-turtles-state
end
Note: do-blue shouldn't use the computational output of do-red in any way for a given time-step.
Upvotes: 0
Reputation: 19
Alan's answer is the correct one. However, just FYI - each turtle (whether red or blue) will act in turn with the above procedure, and none with act "at the same time." That just doesn't happen in NetLogo, by default.
However, you can use a form of simulated concurrency. There is a section of the user guide on "ask-concurrent" that explains this built-in function in detail.
Upvotes: 1