Reputation: 125
In my Anylogic model I have an agent population (terminals) of 4 agents with the time measurement shown below. I want to make a graph of this end.distribution
.
If I create a graph in that agent tab and run the model, the graph will always appear within my GIS Map in the Main agent, which makes it unreadable. Thus, I want to create the graph within the Main agent tab. However, when I make the graph in the Main agent with this histogram data: terminals(0).end.distribution
, I receive this error: Index 0 out of bounds for length 0
, while there are 4 agents and this reference to terminals(0)
does work in a tab of another agent population. Does anybody know how to make it work?
Upvotes: 0
Views: 370
Reputation: 2517
Your issue is an initialisation-order one: your histograms initialises themselves before the embedded agents they are referring to for their data are created (and so you get the error).
There are various ways to control the initialisation order but the 'correct' solution here (irrespective of initialisation order) is to use a replicated Histogram chart, where each replication 'links' to the appropriate Terminal agent to get its data (and so will only exist when the respective Terminal agent exists in its population).
This also means you only 'code' the histogram once, and it will dynamically adjust to create as many histograms as you have agents (which is what you would typically always want).
(The expression for the X coordinate of the replicated chart will depend on how wide it is. In my case, the chart is positioned at x=40 and is 300 wide, so I make each replication 350 apart to leave a 50 gap between.)
See help section AnyLogic Help > 2D and 3D Animation > Shape Replication for more details on replication (a very powerful capability applicable to several different types of element).
Upvotes: 1