Is it possible to have agents belong to more than one collection variable? I have an agent-based model that compiles
without any errors but when I run the model I get the following error message:
>Error during model startup:
>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>at java.util.ArrayList.RangeCheck(ArrayList.java:547)
>at java.util.ArrayList.get(ArrayList.java:322)
I have checked the logic and it is correct. I am wondering if the error occurs because I am trying to add agents to
multiple collection variables. Eg. 1 agent could belong to multiple collection variables.
Thanks for your help.
Michael R. Gibbs — 02.03.10
I have simulations where agents belong to more than one collection, so yes you can do that.
However,
This error is saying that you are trying to access a element in a empty collection (size:0, java indexes start at 0), so
you must have a sequencing problem where this code is getting executed before you load up your collections. Or, if a
empty collection is valid, then you need to add some code to check for empty collections, or use a iterator loop which
will do nothing if the collection is empty.
Hope this helps
Amy — 03.03.10
Michael,
Thank you for your response. I'm pleased to hear that it is not the collection variable structure of the model causing
the problem. What is really puzzling to me is that the collections of interest are empty in the first place.
The model has two different types of agents (that have similar statecharts). When I run the model, the animation
generates all of the agent animation (it produces 63 squares (agent type 1) and 37 circles (agent type 2) randomly
arranged). However this is when I get the error. When I check the collection variables for squares and circles (as
agents enter the statechart they should be added to the collection variables) there are agents in the collection
variables for the square agents but all of the collection variables for the circle agents are empty (hence the error). I
can't figure out why one set of agents works and the other does not when the statecharts are the same for each? My Java
is not great so maybe I'm missing some sort of important point about how the sequencing of actions actually works in
AnyLogic. To me it seems like the collections should be loaded up initially (which seems to work with the squares but
not the circles).
Thanks in advance for any suggestions you might be able to provide.
Tomas — 08.03.10
Hi Amy,
How you define the second type of agents (Circles) ? - as a different object class ? Is the collection variable in the
same class ? or It's located where the flowchart is ?? is the list static?? I had one similar problem in AnyLogic ,and
as is turns out I was working on a "copy" of this list instead of the original to which the flowchart was
referring hence the error. I am not sure but maybe this is the reason but maybe :)
Best Regards,
Tomas