0
votes

I am creating an agent based model in Anylogic 8.7. I have a population of agents where they have attributes linked to an excel file as parameters meaning each row of the excel table represents an agent. I will break my case down as follows: There are some agents that share the same attribute value in one parameter called track. So I wanted to filter them and select each one and do some mathematical actions on each of the agents. I created a collection with ArrayList class and Agent elements using this code to seperate the agents:

collection.addAll(findAll(population,p -> p.track==Tracknum)

//Tracknum is a variable and track is a parameter representing the agent attributes.

The given collection will seperate them in its Array but what I do not know is how to retrieve each one of the listed agents from the collection and get another one of their attributes to do some mathematical work. I would be grateful if you help me through this process. Thanks.

1

1 Answers

0
votes

Loop across the ArrayList like with standard Java.

for (AgentyType currentAgent : collection ) {
    // access every agent in collection here, example:
    traceln(currentAgent.track);
}

Alternatively, google Java Streams to learn how to do it with less code