1
votes

I create a spreadsheet with some properties (columns); then in Anylogic create an agent (population of agents) and load it from DB. Run model. Works perfectly, it shows I have an Agent population "products" with 6 agents.. (model has FluidSource, Pipe, Tank, Valve, FluidDispose, all basic configuration)

So now I open the FluidSource, select Custom batch and for Batch: products.get[0].productName (productName is parameter of type string). I have also tried:

products[0];
products[0].productName;
products.get(0);

Now run again.. in model window it says "Error while drawing animation frame..." (orange block top right) and in model.Console it says: Error during model creation: Index: 0, Size: 0 java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 ...

What am I doing wrong? How do I assign my FluidSource batch to one of my "Product" agents?

1
So I take out the "Custom batch" option again (leave it to default batch), add a Text and a Button and code the Button's action: products.get(0).productName; and run. It shows I have six products in my agent population as before and when I press the button my text display "ULP95" - which is the correct name for my first "Product" agent - so nothing wrong with the code ??Cecil

1 Answers

0
votes

The problem is the order of initialization: your FluidSource object is trying to access the products population before that population is actually filled with agents.

Make your FluidSource account for this by using this conditional check:

products.size() == 0 ? "InitialBatch" : products[0].productName