问题
The traditional* implementation of Dijkstra's does not handle this case well. I think I've come up with some solutions that will work, but they are not particularly elegant**. Is this is a known problem with a standard solution?
This is assuming the non-trivial solution i.e. a path like A->B->C->A rather than just A->A.
* When I say traditional I mean marking each node as visited.
** Storing the number of times each node has been visited and basing the terminating conditions on whether the end node is the start node.
回答1:
Split A into two nodes, called START and GOAL.
For any edge A->x add an edge START->x
For any edge y->A add an edge y->GOAL
Keep all other edges unchanged.
Then use normal Dijkstra to solve for the path from START to GOAL
来源:https://stackoverflow.com/questions/25408477/dijkstras-or-other-shortest-path-algorithm-where-end-node-can-be-start-node