我知道 Dijkstra 的最短路径算法。但是,如果我要修改它,而不是找到最短路径,而是使用贪心算法找到最长的路径。我必须对下面的代码做什么:
这是我使用的:
作为比较函数在最短路径版本中选择正确的节点:
if (Cost(potential_node) > Cost(current_node) + cost(source , current_node)) then
cost (potential_node) = cost(current_node) + cost (source, current_node)
但是,另一方面,这是行不通的:
if (Cost(potential_node) < Cost(current_node) + cost(source , current_node)) then
cost (potential_node) = cost(current_node) + cost (source, current_node)
有点困惑,非常感谢一些反馈