So you may of seen previous posts on Boost Graph construction, here I present an easier way of constructing the graph but at a performance cost. This shouldn’t be used if can be avoided, but it may be useful if you want to adapt your edges on the fly.
So we start with the normal code:
So we start with a basic set of nodes, A->E with some connections between them. This is an example of a directed graph so “flow” can only go one direction.
The benefit of this is you define the construct of the graph and create the graph_t, object g.
An alternative way of constructing is to generate the nodes, then add in the weights as in:
This may seem easier but comes at a performance cost. In contrast even on this simple example there is a 0.001s time increase, scale this to a real solution you may suffer badly. As stated make sure your scenario makes sense.