Search code examples
anylogicagent-based-modelingdata-collection

calculating drivers salary in AnyLogic


In Anylogic I am trying to calculate the average driver salary based on some statistics that will be collected during the model run-time. I have figured out how to collect the required statistics. However I want to know how to create a function that gives the output of the following equation at the end of the simulation.
The salary equation is: (distance coefficient)(distance) + (pickup coefficient)(number of pickups) + (dropoff coefficient)*(number of dropoffs)


Solution

  • Collect statistics on agent population

    I assume you collect the three values for each driver agent inside each of these agents in a variable:

    Agent Definition

    Following the documentation, you probably created the three statistic elements on your poupulation of drivers:

    Agent population statistics

    Calculation function

    Finally to your question, a simple function that calls the statistic elements to retrieve the values and combine it with the factors. The factors are defined as static constant variables in Main, as well as the function:

    Function

    double averageDistance = drivers.distance();
    double averageNumberOfPickups = drivers.numberOfPickups();
    double averageNumberOfDropoffs = drivers.numberOfDropoffs();
    
    double salary =  distanceCoefficient * averageDistance 
                    + pickupCoefficient * averageNumberOfPickups 
                    + dropoffCoefficient * averageNumberOfDropoffs;
    
    return salary;
    

    You can trigger the function for example with the On destroy code of Main, or have it executed by a timed event and so on. You may print to console with traceln(calculateAverageSalary) or export to CSV, Excel or show in your model.