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.

Answer

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