It seems like using elements() to bag agents and then step them in a for loop is a recipe for artifacts: agents in the top left corner always act before agents in the bottom right.

I usually do what Russell does, keeping a reference to agents in a separate collection and stepping that, but I prefer an ArrayList to aBag; partially because of generics but mostly because I can call Collections.shuffle(agentList,random) and randomize their order before stepping them. The only caveat is that MersenneTwisterFast is not a kosher Random object so you can’t pass it directly, but you can just pass a seed from the MASON randomizer to a standard Java one (or extend the MASON one so that it fulfills Randominterface).

As far as I could tell, shuffling and stepping is a bit faster than schedule all your agents separately and letting the scheduler randomize for you. But that might have been a fluke and I never tested this carefully enough.

On Sun, Oct 25, 2015 at 4:13 AM Russell Thomas <[log in to unmask]> wrote:
I have accomplished this by having an łagents" Bag variable in the main
class (SimState), and then every time I create a new object, I add it to
the łagents" bag.  Then I iterate over all agents simply by looping using
get() method.  If your agents ever die, then you also need to remove them
from the łagents˛ bag.  This, of course, requires passing the SimState
object to what ever object is iterating over all agents.  But, in my case,
these objects involved UI, data collection, debug, and other
administrative functions, and not objects within the model Iąm simulating.

With this method, you never need to be concerned with where they might
reside in any other data structure, including ObjectGrid or SparseGrid.


On 10/24/15, 9:56 PM, "MASON Multiagent Simulation Toolkit on behalf of
Sean Luke" <[log in to unmask] on behalf of
[log in to unmask]> wrote:

>Iterating over all the objects in an ObjectGrid2D means iterating over
>every single
>cell in the array.  If you don't have a lot of objects relative to the
>cells, this can
>be very slow, and it would make more sense to use a SparseGrid2D instead.
>You could use a double for-loop to go through all the objects.  But
>elements() isn't too slow, and it's O(1).
>On Oct 24, 2015, at 10:37 AM, Axel Kowald <[log in to unmask]> wrote:
>> Hello Together,
>> I just wonder what the best way is to iterate over all the agent on my
>> ObjectGrid2D ?
>> Currently I'm extracting a Bag with all agents by using the elements()
>> method. It works, but I'm not sure how fast/slow it is. Would it be
>> worth to maintain my own Bag and do the bookkeeping by
>> inserting/removing agents when needed?
>> thanx,
>>  Axel