Hi all,
I have outputs (as shown in the attachment), containing routes for the vehicles. Each route has a location ID. I later mapped these IDs to the addresses.
I have google map for each route. How do I output them in the same window, each route with a different color, please?
I appreciate any help please.
Thanks.
Sam
###########
def print_solution(data, routing, assignment):
"""Print routes on console."""
total_dist = 0
for vehicle_id in range(data["num_vehicles"]):
url = 'https://google.com/maps/dir'
index = routing.Start(vehicle_id)
plan_output = 'Route for vehicle {0}:\n'.format(vehicle_id)
route_dist = 0
route_load = 0
while not routing.IsEnd(index):
node_index = routing.IndexToNode(index)
next_node_index = routing.IndexToNode(assignment.Value(routing.NextVar(index)))
route_dist += routing.GetArcCostForVehicle(node_index, next_node_index, vehicle_id)
for item in loc1:
if item[2] == node_index:
url += '/' + str(item[3]) + str(item[4]) + str(item[5])
route_load = data["demands"][node_index]
plan_output += ' {0} Load({1}) -> '.format(node_index, route_load)
index = assignment.Value(routing.NextVar(index))
node_index = routing.IndexToNode(index)
total_dist += route_dist
time = (route_dist *10)/speed + service_time(data,node_index)
plan_output += ' {0} Load({1})\n'.format(node_index, route_load)
#plan_output += 'Distance of the route: {0}m\n'.format(route_dist)
#plan_output += 'Time of the route: {0}h\n'.format(time)
plan_output += 'Load of the route: {0}\n'.format(route_load)
print(plan_output)
print("url is: {}".format(url))
print('Total Distance of all routes: {0}m'.format(total_dist))