I am trying to figure out the behaviour of the vertex creation when using the add_edge function. Here is an example:
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
using namespace boost;
typedef adjacency_list<> Graph;
typedef graph_traits<Graph>::vertex_iterator v_iter;
Graph g;
add_edge(1,2,g);
add_edge(1,4,g);
add_edge(2,3,g);
add_edge(2,6,g);
std::cout << "num edges: " << num_edges(g) << "; num vertices: " << num_vertices(g) << std::endl;
for (std::pair<v_iter,v_iter> vp = vertices(g); vp.first != vp.second; vp.first++) {
std::cout << *vp.first << " ";
}
returns:
bash-3.2$ ./main
num edges: 4; num vertices: 7
0 1 2 3 4 5 6
Why are these vertices being created? The graph has 1,2,3,4 and 6 as vertices, 5 in total not 7. It seems that the function creates vertices from 0 to the highest value of a vertice.
I really don"t know whats going on here, so any help is greatly appreciated.
Thank you very much in advance.