Reputation: 9806
GIVEN : Given an agentset of turtles where each turtle has patch it wants to move, in the next time step(tick).
PROBLEM : Two or more turtles may have the same patch set which they want to move to
TO SOLVE : then I have decide depending upon another parameter of the turtles as to which one will move to that patch and rest stay still.
CONSTRAINT: Thus, Each patch has only one allowed turtle.
How do i code this, agentset doesn't have the necessary functionality like remove duplicates etc.
Thanks in advance.
Upvotes: 0
Views: 87
Reputation: 9620
Use the table
extension. Looping the the turtles with ask
, create a table mapping patch coordinates to a list of turtles wanting to move there. Write a resolve-conflicts
reporter that picks one turtle from such a list. Walk through the table using resolve-conflicts
to pick one turtle for each target, and move that one to the target patch.
I wish the table
extension should add a groupby
primitive. This need is pretty common.
Upvotes: 1
Reputation: 123
You could create a list of all variables containing the destined patch of each turtles (let's say this turtle variable is called next-patch). Then you loop through the list and if one patch appears twice (if j = i), you ask the turtle with next-patch = i to choose another patch.
Upvotes: 1