Finding the shortest path with possibility of ignoring 1(the longest) edge

倾然丶 夕夏残阳落幕 提交于 2019-12-11 05:54:26

问题


I was wondering if I can modify Dijkstra’a Alghorithm in this way: Let’s say there are 2 paths between two vertices with following lengths:

5, 8, 6, 9  // sum=28
2, 4, 8, 25 //sum=39

First path is shorter but after ignoring the longest edge in both I get the following sums: 19 and 14, so I choose the second path.

Maybe there is different way to solve it, without using Dijkstra?


回答1:


I'm not sure is this idea working, but on first it seems to me like it can.

For each visited node, beside distance D(n), store length of longest edge on the path to it, say L(v). Distance of unvisited neighbouring node is min D(n) + L(n) - max(L(n), weight(v,n)), for all neighbours n that are visited. L(v) of next visited node is max(L(n), weight(v,n)), if n is last node on a path to the v. If there are more paths to v (more n's) with same length, than choose one with largest L(v).



来源:https://stackoverflow.com/questions/14159787/finding-the-shortest-path-with-possibility-of-ignoring-1the-longest-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!