I am using this example:
https://developers.google.com/optimization/routing/routing_tasks
i've changed the units in the above program to meters and seconds
in my code i removed the capacity constraint since it is not relevant to my solution,
what i've tried:
in the main function ive changed costevaluator from SetArcCostEvaluatorOfAllVehicles to SetArcCostEvaluatorOfVehicle and implemented a differenct cost evaluator function with an efficiency variable that reduces the ditances in the distance matrix:
distance_evaluators = []
for veh_id in range(len(couriers_list)):
distance_evaluators.append(
deepcopy(
CreateDistanceEvaluator(data, veh_id).distance_evaluator))
routing.SetArcCostEvaluatorOfVehicle(distance_evaluators[-1], veh_id)
def distance_evaluator(self, from_node, to_node):
self._distances[from_node][to_node] = int(
data.distance_matrix[from_node][to_node]/data.vehicles[veh_id].efficiency)
that seemed to help a bit but still a bad division of labor, and times are not precise at all
the problem is that adding a dimension has only a callback of from node and to node, without a vehicle variable so i cant distinguish between vehicles...
i've read the documentation thoughtfully for the past 2 days and viewed tons of examples but just couldn't find anything for my problem
any help?
Thanks for the help
Here's the code if anyone would like an idea of how to use this
# Add Time Window constraint
time_evaluators = []
for veh_id in range(len(data.couriers)):
time_evaluators.append(data.vehicles[veh_id].time_evaluator)
time = "Time"
horizon = 24 * 3600
routing.AddDimensionWithVehicleTransits(
time_evaluators,
horizon, #
horizon, # vehicle shift time capacity
False, # don't force start cumul to zero since we are giving TW to start nodes
time)
time_dimension = routing.GetDimensionOrDie(time)
for vehicle_id in xrange(data.num_vehicles):
index = routing.Start(vehicle_id)
time_dimension.CumulVar(index).SetRange(data.vehicles[vehicle_id].start_time,
data.vehicles[vehicle_id].start_time)
index = routing.End(vehicle_id)
time_dimension.CumulVar(index).SetRange(data.vehicles[vehicle_id].end_time,
data.vehicles[vehicle_id].end_time)
for location_idx, time_window in enumerate(data.time_windows):
if time_window[0] == 0:
continue
index = routing.NodeToIndex(location_idx)
time_dimension.CumulVar(index).SetRange(time_window[0], time_window[1])