Search code examples
routessimulationanylogicagent

Anylogic: How to add the choice of departure time and route?


In my Anylogic model I have 200 zones and I have these populations of agents:

  • Customers (parameters: name, GIS latitude, GIS longitude), one in every zone (except terminal zones)
  • Terminals (parameters: name, GIS latitude, GIS longitude), one in evert terminal zone (5)
  • Orders (parameters: customer (type: Customer), terminal (type: Terminal))
  • Trucks (receive an order (that is created by a customer) and then travel to that terminal and customer)

Now, since there are large waiting times at terminals during the day time, I want to add a hub that is open at night in between the terminals and customers and let the trucks decide if:

  1. They want to travel at day time directly from the terminal to the customer, or
  2. They want to travel at night time from the terminal to a hub, and then at day time from the hub to the customer

They should make this choice based on driving+waiting costs that differ per route(origin,destination) and per time of day (day/night). I have these costs in a database and I linked them to the routes by first adding a new Java class:

enter image description here

And then I added this function to assign the costs from my database:

enter image description here

Now my question is, how can I let the trucks, per order they receive, choose their departure times (day/night) and route (from terminal -> customer / from terminal -> hub -> customer) based on these costs?

I want to add something like this below (where Region102 is the hub) to choose the cheapest option per order (which was just to try but of course does not work like this..) and to let the trucks then choose their departure time and route?

enter image description here

Thank you for all the help!


Solution

  • You can create a function that has the customer and terminal as arguments and then find you the least costly option and return it. Here is a quick example where 'allPossibleRoutes' is just a collection where all the possible route combinations are stored as a list.

    enter image description here