如何用图形绘制Google OR Tools车辆路线问题解决方案?

问题描述

我正在使用Google OR工具来解决Python中的一个简单的车辆路径问题。我想以类似于Google教程的方式绘制求解器返回的解决方案: Google OR Tools Vehicle Routing Problem Tutorial Solution

这是我在本教程中使用的代码:

def print_solution(data,manager,routing,solution):
"""Prints solution on console."""
max_route_distance = 0
for vehicle_id in range(data['num_vehicles']):
    index = routing.Start(vehicle_id)
    plan_output = 'Route for vehicle {}:\n'.format(vehicle_id)
    route_distance = 0
    while not routing.IsEnd(index):
        plan_output += ' {} -> '.format(manager.IndexToNode(index))
        previous_index = index
        index = solution.Value(routing.NextVar(index))
        route_distance += routing.GetArcCostForVehicle(
            previous_index,index,vehicle_id)
    plan_output += '{}\n'.format(manager.IndexToNode(index))
    plan_output += 'Distance of the route: {}m\n'.format(route_distance)
    print(plan_output)
    max_route_distance = max(route_distance,max_route_distance)
print('Maximum of the route distances: {}m'.format(max_route_distance))

这是我得到的解决方案:

车辆0的路线: 0-> 93-> 92-> 91-> 53-> 56-> 52-> 51-> 61-> 62-> 63-> 64-> 65-> 68-> 67-> 66-> 70- > 69-> 100-> 99-> 98-> 97-> 96-> 94-> 95-> 0 路线距离:530m

车辆1的路线: 0-> 4-> 5-> 10-> 9-> 90-> 89-> 83-> 82-> 81-> 87-> 41-> 44-> 47-> 49-> 50-> 14- > 17-> 19-> 18-> 20-> 22-> 23-> 26-> 31-> 33-> 0 路线距离:621m

车辆2的路线: 0-> 1-> 2-> 7-> 8-> 86-> 88-> 85-> 84-> 59-> 60-> 79-> 76-> 77-> 74-> 71-> 72- > 73-> 75-> 78-> 80-> 58-> 57-> 55-> 54-> 0 路线距离:614m

车辆3的路线: 0-> 3-> 6-> 43-> 42-> 46-> 45-> 48-> 11-> 12-> 15-> 13-> 16-> 25-> 27-> 29-> 28- > 30-> 35-> 36-> 40-> 37-> 39-> 38-> 34-> 32-> 24-> 21-> 0 路线距离:620m

如何绘制与图像相似的解决方案?

解决方法

此图片是使用python脚本生成的svg。 您可以在此处找到源: https://codesandbox.io/s/vuetify-playground-forked-gwtkc?file=/src/components/SpeedDial.vue

由外壳程序脚本调用: https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/doc/routing_svg.py

ps:请随时询问我们的不和谐之处(项目README.md中的链接)以获取更多详细信息...

,

它在这里使用程序:

https://github.com/google/or-tools/blob/stable/examples/python/cvrptw_plot.py

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...