0
votes

I am creating an agent based model in Anylogic 8.7. I created a collection with ArrayList class and Agent elements using this code to separate some agents meeting a specific condition:

collection.addAll(findAll(population,p -> p.counter==variable); for (AgentyType p: collection ) { traceln(p.probability); }

The above code will store the probability attribute of the separated agents in the console. Is there a way to define a loop to retrieve the printed probability attributes from the console one by one and store them in a variable to operate on them? Or if there is a more efficient and optimized way of doing this I would be glad if you share this with me. Thank you all.

2

2 Answers

0
votes

I am not sure why you are following this methodology... Agent-Based Modeling already "stores" the parameters you are looking for, you do not need the console as an intermediate. I believe what you are trying to do is the following:

for( AgentType p : agentTypes)
{
   if( p.track == 1 )
   {
    sum = sum + p.probability * p.impact ;
   }
{

I recommend you read:

https://help.anylogic.com/topic/com.anylogic.help/html/code/for.html?resultof=%22%66%6f%72%22%20%22%6c%6f%6f%70%22%20

and

https://help.anylogic.com/topic/com.anylogic.help/html/agentbased/statistics.html?resultof=%22%73%74%61%74%69%73%74%69%63%73%22%20%22%73%74%61%74%69%73%74%22%20

The latter will give you a better idea on how to collect Agent statistics based on certain criteria.

0
votes

depending on the operations you want to perform you can use the following:

https://help.anylogic.com/index.jsp?topic=%2Fcom.anylogic.help%2Fhtml%2Fjavadoc%2Fcom%2Fanylogic%2Fengine%2FUtilitiesCollection.html&resultof=%22%75%74%69%6c%69%74%69%65%73%22%20%22%75%74%69%6c%22%20

you can use something like this to collect one by one the values of your probabilities.

collection.addAll(findAll(population,p -> p.counter==variable); 
LinkedList <Double> probabilities= new LinkedList();
for (AgentyType p: collection ) { 
    probabilities.add(p.probability); 
}