Abhishek Bhatia
Abhishek Bhatia

Reputation: 9806

Groups agents on the basis of particular value in the agenset

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

Answers (2)

Alan
Alan

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

AndyB
AndyB

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

Related Questions