[英]Find the cost of all paths in a matrix using Dijkstra's Algorithm in Python
I'm trying to create a program that from a starting coordinate finds the lowest cost path of traveling to all of the other coordinates in a matrix using Dijkstra's Algorithm.我正在尝试创建一个程序,该程序使用 Dijkstra 算法从起始坐标找到前往矩阵中所有其他坐标的最低成本路径。 Any coordinate that has an infinite value is avoided when traversing.遍历时避免任何具有无限值的坐标。
You are confusing node
and current_node
:你混淆了node
和current_node
:
x_check = node[0] + move[0]
y_check = node[1] + move[1]
should be应该
x_check = current_node[0] + move[0]
y_check = current_node[1] + move[1]
By the way, in Python, you are allowed to write顺便说一句,在 Python 中,你可以写
if 0 <= x_check <= N-1 and 0 <= y_check <= N-1:
which is much more readable !这更具可读性!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.