0

I would like to create an algorithm with Boost Graph Library that expands a branch on a tree graph "on the fly" while the algorithm is running. Depending on some conditions the algorithm would explore branches with lower costs. These costs should also be created while the tree gets expanded. The reason I want to avoid creating the tree before running an algorithm is to avoid unnecesary vertices. Each vertex has data attached to it that requires a computation intense prediction step which takes a lot of time.

All the examples and in the documentation of boost show a given graph and then just apply an algorithm but none of them expands a graph while the algorithm is running.

I found a similar question here and the answer:

Adding vertices and edges is a dangerous thing to do inside an algorithm visitor. This is because doing that invalidates iterators that the algorithm is using. Also, the algorithm creates a mapping from vertices to colors (to mark which vertices have been processed), and adding vertices will mess up that mapping. Can you just record that you want to add vertices and do it after the BFS?

I also thought of creating an empty tree structure and changing the data attached to vertices when they are explored using dijkstra_shortest_paths. However, as far as I understand I need a cost map for the edges before running the algorithm which I dont have either. The weights should be adapted when a new vertex is discovered because this newly discovered vertex must be assigned some cost or reward first. Therefore the cost map should also be created on the fly.

Has someone tried adding vertices in an algorithm before or is there a better way to achieve such behavior? Maybe BGL is not the right library for this?

evolved
  • 1,850
  • 19
  • 40
  • Which algorithm exactly? Some algorithms in BGL do support this kind of expansion, for example A* search. I think, the answer will be very much algorithm-specific. – David Frank Jan 31 '19 at 20:59
  • Unfortunately, I don't have a heuristic. Therefore, I wanted to start using [dijkstra_shortest_path](https://www.boost.org/doc/libs/1_69_0/libs/graph/doc/dijkstra_shortest_paths.html). Is an expansion supported using Dijkstra? If so, could you please provide an example? I also read about function_property_map to change the weights but I couldn't find an example how to write this function and how to apply it to an algorithm. I am also not sure which visitor event point I should use in my case and what has to be taken care of to avoid invalidating the tree. – evolved Jan 31 '19 at 21:21
  • You can always set the heuristic to 0, in which case the A* algorithm is the same as dijkstra. – David Frank Jan 31 '19 at 21:49

0 Answers0