Search code examples
anylogic

How to track the order generated in agent population in Anylogic?


I have an agent population named parcelstationses with population number 3. I am generating demand of the Parcelstation using Event. Please check the image below,

enter image description here

In the Main agent, I want to track the order generated for each Parcelstation. How can I achieve that?

I tried using parcelstationses.get(0).amount;. But since the order generated is of type Order (another agent type). I get the following error,

cannot convert from order to double.


Solution

  • Just track the number of orders?

    1. add a variable of type int to Main, called counter
    2. in your generateDemand event, add a line main.counter++

    To keep full details?

    1. add a variable of type LinkedHashMap<Order, ParcelStation> named myOrders with initial value new LinkedHashMap<Order, ParcelStation>()
    2. in your generateDemand event, add a line main.myOrders.put(order, center);

    In any case, start understanding data types, model hierarchy and how to use access them, see https://anylogic.help/advanced/code/access.html#where-am-i-and-how-do-i-get-to and the help on data types in general