0

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)

1 Answers1

0

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.

Florian
  • 962
  • 1
  • 5
  • 17
  • Thank you very much Florian for your answer. However, If I want to calculate the average salary for each driver separately, is it corresct to write in the function body for example: double averageDistance = drivers(0).distance() ?? Because I tries that but I get an error ( the method is undefined for the type Driver) – Abdullah Ayoub Abuhilal Jun 28 '19 at 08:12
  • 1
    This would not be correct, therefore the error. If you want separately by driver, you do not use the poulation statistics (such as drivers.distance())! Instead you use drivers.get(0).distance. While distance() refers to the poulation statistic element I created, whereas distance is directly accessing the variable of the individual agent. Another option you have is to have the function and static constant variables directly in the driver agents and directly refereing to the variables there, then just call drivers.get(0).calculateAverageSalary() for each driver individually. – Florian Jun 28 '19 at 08:34
  • drivers.get(0) gets you the same element as drivers(0), should be no difference – Florian Jun 28 '19 at 08:40
  • Ohhh i get it now!! thats why it did not work when I tried to create this function in the main using the variables defined in the driver agent directly ( I have tried this before posting my question), Thank you very much Florian !!! – Abdullah Ayoub Abuhilal Jun 29 '19 at 17:38