简体   繁体   中英

Can I use dijkstra_shortest_paths in BGL on "cyclic" directed graph

At first, Sorry for my english :(

my graph's spec is

  • cyclic
  • directed
  • edge weight is positive or zero

As I know dijsktra algorithm cannot find shortest path of "cyclic" graph. But there is no that restriction in BGL docs ( https://www.boost.org/doc/libs/1_77_0/libs/graph/doc/dijkstra_shortest_paths.html )

So I wonder I can find shortest paths of this graph by using dijkstra_shortest_paths in BGL.

thanks.

Yes, you can in fact use the method.

  1. Dijkstra works with cycles in graphs as long as they are positive
  2. The documentation of the method states, which does not apply given your specs:

Use the Bellman-Ford algorithm for the case when some edge weights are negative

See also https://cs.stackexchange.com/questions/101637/dijkstra-s-shortest-path-algorithm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM