Question

Given an empty boost::graph g, I want to set the number of vertices in this graph and add some edges then. But from the documentation, I cannot find related functions. All examples I found defines the size of vertices in initialization (like Graph g(10) defines a graph with 10 vertices). But I don't know the size when I define the graph. I want to first define a Graph g, and set the size later.

Was it helpful?

Solution 2

The simplest approach is to call the boost::add_vertex( graph ) method for each vertex you want.

Here is a nice place to start Using C++ Boost's Graph Library

Note that you not HAVE to add the vertices one by one. If all you care about are the edges, then add_edge() will add missing vertices for you.

OTHER TIPS

You can probably try a little dirty trick like:

add_edge(0,4999,g);
remove_edge(0,4999,g);

It exploits the side-effect of add_edge for adjacency_list, namely, the fact that BGL extends the vector of vertices if necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top