Distance and time costs in multi-objective VRP

223 views
Skip to first unread message

Ahmed Heakl

unread,
Nov 8, 2023, 5:48:22 AM11/8/23
to or-tools-discuss
Hello everyone,

I am developing a route optimization system with the following constraints:
1. Capacities and demands
2. Time windows
3. Vehicles work time
4. Orders priorities
5. Vehicles speed
6. Orders service time


I am currently using time as the main dimension to set cost. I do not have an explicit ArcCostEvaluator though (example below)

routing.SetArcCostEvaluatorOfAllVehicles(time_evaluator_index)

But rather I just set time as a dimension as follows

def set_cost_constraints(self):
"""Set time constraints for each vehicle"""

def create_vehicle_travel_callback(
cost_matrix,
serivce_matrix,
vehicle_speed_factor,
):
def time_callback(from_index, to_index):
from_node = self.manager.IndexToNode(from_index)
to_node = self.manager.IndexToNode(to_index)

return int(
(cost_matrix[from_node][to_node] / vehicle_speed_factor)
+ serivce_matrix[from_node][to_node]
)

return time_callback

time_callback_indices = []
for vehicle_id in range(self.data["num_vehicles"]):
time_callback = create_vehicle_travel_callback(
self.data["cost_matrix"],
self.data["service_time_matrix"],
self.data["vehicles_speed_factors"][vehicle_id],
)
time_callback_indices.append(
self.routing.RegisterTransitCallback(time_callback)
)

self.routing.AddDimensionWithVehicleTransits(
time_callback_indices,
cfg.WAITING_TIME,
cfg.MAXIMUM_TIME_PER_VEHICLE,
False,
cfg.COST,
)

My question:
Is it advisable to set a distance dimension as the `ArcCostEvaluatorForAllVehicles`? If so, what is the benefit of doing so?

Any assistance would be appreciated :)

Ahmed Heakl

unread,
Nov 9, 2023, 3:07:21 AM11/9/23
to or-tools-discuss
Any help, please?

blind.lin...@gmail.com

unread,
Nov 9, 2023, 4:23:35 PM11/9/23
to 'Ahmed Heakl' via or-tools-discuss

Short answer, yes, you need to provide a function to one of the
"SetArcCostEvaluator..." API calls.

If you do not do that, then you haven't really told the solver what
your primary minimization goal is.

If your goal is minimizing time, then use time.

If your goal is minimizing distance, then use distance.

If you have some other variable that accumulates with each node visit
and that is your primary objective, then use that function.

The function can also be used in a dimension, but that is not
required.

Hope that helps,

James

ArcCostEvaluatorForAllVehicles? If so, what is the benefit of doing so?

Any assistance would be appreciated :)

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/ac807e34-a6a5-4c03-adfc-a931d51b7975n%40googlegroups.com.

--
James E. Marca  
Activimetrics LLC  
signature.asc
Reply all
Reply to author
Forward
0 new messages