Search code examples
anylogicagent

Static reference error for getDistanceTravelled() of transporter agent


I have an agent, called "AGV", which is used as a transporter in my model. It is the agent for my fleet named "OrderFleet".

How can I get the distance travelled at the end of my simulation runs for my AGVs?

If I put AGV.getDistanceTravelled(METER); into the "On destroy" of my main agent, called "main", I receive the error:

Cannot make a static reference to the non-static method getDistanceTravelled(Length Units) from the type AGV.


Solution

  • AGV is an agent type not an agent, so you cannot use the getDistanceTravelled() function on it. To resolve your issue, start by creating a population of agents of type AGV by dragging and dropping to Main the "Agent" element of the "Agent" Palette.

    enter image description here

    enter image description here

    Then, make sure the new transporters in your fleet block are added to that population by doing the following: enter image description here

    Now, in the On Destroy field you can write the following code:

    for( AGV a : AGVs ) {
      traceln(a.getDistanceTravelled(METER));
    }
    

    This will return the distance travelled of each AGV in that fleet.