anylogictraffic-simulation

How to visualize distance travelled in AnyLogic


I'm trying to produce a histogram plotting distance travelled by pedestrian agents.

It is fairly easy to plot the time in the model, based on this tutorial from AnyLogic. But I couldn't find a way to plot the distance travelled. enter image description here I know you can see the the distance in the Database log, but is there a way to plot it during the simulation?


Solution

  • strangely, even though you see it on the log, you don't have any function to calculate it for pedestrians, only for transporters.

    In order to do it, you need to work manually... this means that you will need to check for instance every second capture the current position and then compare it to the previous position and the time it took to get there.

    Point currentPosition=new Point(getX(),getY());
    

    then something like this:

    Point previousPosition=currentPosition;//
    Point currentPosition=new Point(getX(),getY());
    double distancePx=sqrt((previousPosition.getX()-currentPosition.getX())^2+(previousPosition.getY()-currentPosition.getY())^2);
    double distanceMeters=scale.toLengthUnits(distancePx);
    double totalDistance+=distanceMeters;