1

Using a python based Genetic Algorithm i am able to get routes for a vehicle routing problem with a heterogeneous fleet. These have to be evaluated in anylogic using discrete event simulation. I used the following blocks:

enter image description here

In the main, I call the python communicator and store the routes in a parameter of the type "List", then I add these routes to the agent 'Order' (of population type) such that each order agent contains a unique route and vehicle.

However, after seizing, each separate stop embedded within the parameter route from the order agent needs to be visited by the vehicle. Currently I have the moveTo block where I defined to agent with an agent 'main.Stops'. But this gives me the error that I cannot convert from int to agent.

The idea I had is to count the routes and count the elements in the routes via the parameter 'routeID' and variable 'OrderCount' respectively. These are updated after each visit and are initialized at zero. Does anybody know how I can ensure that each integer element in the route can be visited via a moveTo block (or other solution).

Jaco-Ben Vosloo
  • 3,770
  • 2
  • 16
  • 33

1 Answers1

1

I would implement something as follows: This is an example from a previous similar project

  1. Create a Java class for every stop that contains at least two fields, latitude longitude, or some other way of identifying the location. (In the example below called Order)

  2. Create a collection of Order inside your agent that does the movement (E.g. Truck)

  3. Inside the MoveTo block you make the Truck agent move to the first location in the list and then you remove that order from the list when it finished moving.

  4. There is a SelectOutput block at the end of each delivery to check if there are more stops/orders. If there are the process continues, if not then you can stop or do something else.

enter image description here

Jaco-Ben Vosloo
  • 3,770
  • 2
  • 16
  • 33
  • Hi, the answer works for a single route. But preferably after each stops in a route has been visited, the vehicle returns to the depot. I thought I could solve this by the following entering in the condition of the select output: 'agent.route.isEmpty();' and in the on exit (true) 'agent.moveTo(release);' By removing each element of a given route, it is empty afterwards, which is what I want. However, once all the stops are visited I receive the error the index 0 is out of bounds for length 0. The condition should imply that the agent continues right? Or does remove, remove the entire agent? – Bas Lindeboom Dec 21 '21 at 16:13
  • 1
    I am not sure what you want to achieve with the code `agent.moveTo(release)` ? On the select output as you rightfully said you just need it to move out of the true output if `agent.route.isEmpty()` and then the agent will continue on its way, in my example, it will be disposed of. You are welcome to post a new question if we cant resolve it here in the comments – Jaco-Ben Vosloo Dec 22 '21 at 04:09
  • Ah I see, you purposely dispose of the agent. This is a significant difference. But I already managed to adapt my model using your solution. So thanks! – Bas Lindeboom Dec 22 '21 at 10:17