我想创建一个车辆路径优化程序。通过找到从A到B的最短路径,我将有多辆车行驶和交付物品。首先,我将简单地输出结果。我稍后可能会创建该程序的直观表示。
有人向我建议,我会发现在Python中最容易做到这一点。
我必须完成这项任务,但这看起来非常令人生畏。我不是最好的程序员,但也不是初学者,我擅长数学和快速学习。
关于如何分解这项任务的任何建议都会非常有帮助。 我应该使用Python吗? 任何特别适合此任务的Python模块?
答案 0 :(得分:0)
来自http://en.wikipedia.org/wiki/A*_search_algorithm
的A *算法的Psuedo代码function A*(start,goal)
closedset := the empty set // The set of nodes already evaluated.
openset := {start} // The set of tentative nodes to be evaluated, initially containing the start node
came_from := the empty map // The map of navigated nodes.
g_score[start] := 0 // Cost from start along best known path.
// Estimated total cost from start to goal through y.
f_score[start] := g_score[start] + heuristic_cost_estimate(start, goal)
while openset is not empty
current := the node in openset having the lowest f_score[] value
if current = goal
return reconstruct_path(came_from, goal)
remove current from openset
add current to closedset
for each neighbor in neighbor_nodes(current)
if neighbor in closedset
continue
tentative_g_score := g_score[current] + dist_between(current,neighbor)
if neighbor not in openset or tentative_g_score < g_score[neighbor]
came_from[neighbor] := current
g_score[neighbor] := tentative_g_score
f_score[neighbor] := g_score[neighbor] + heuristic_cost_estimate(neighbor, goal)
if neighbor not in openset
add neighbor to openset
return failure
function reconstruct_path(came_from,current)
total_path := [current]
while current in came_from:
current := came_from[current]
total_path.append(current)
return total_path
这是找到最短路径的最常见和最实用的方法。它基本上扫描周围区域,直到满足起点和检查点,并在任何障碍处停止
并且取决于 hefty 你的程序如何是python并不是最好的,因为与其他语言相比,它的执行速度较慢。如果你寻找简单的python是你最好的朋友。
答案 1 :(得分:0)
前几天我使用了networkx,它非常棒。非常容易使用,而且非常快。
因此,您需要将数据转换为某种可用格式,然后通过此算法运行算法。
Python通常是脚本编写和整合数据并进行分析的不错选择!