Visualization of routing results in Google Map.

133 views
Skip to first unread message

Sampson

unread,
Apr 17, 2019, 5:35:26 PM4/17/19
to or-tools-discuss

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))
Output2.png

Vincent Furnon

unread,
Apr 18, 2019, 7:59:46 AM4/18/19
to or-tools...@googlegroups.com
You could display your routes with the Google Maps API using the DirectionsService and a DirectionsRenderer (see https://developers.google.com/maps/documentation/javascript/reference/directions).

--
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/b8596308-123d-4737-9c2e-7195427aebcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages