#define HAVE_BOOST 1 #ifdef HAVE_BOOST #include #include using namespace std; using namespace boost; #endif int main() { // specify the graph type typedef adjacency_list< listS, listS, undirectedS, property, no_property > graph_t; int num_nodes=10; // construct a graph object graph_t G(num_nodes); // obtain a property map for the vertex_index property property_map::type index = get(vertex_index, G); // initialize the vertex_index property values graph_traits::vertex_iterator vi, vend; graph_traits::vertices_size_type cnt = 0; for(tie(vi,vend) = vertices(G); vi != vend; ++vi) put(index, *vi, cnt++); cout << num_vertices(G) << endl; for (unsigned int i = 0; i < num_nodes; ++i) { for (unsigned int j = i + 1; j < num_nodes; ++j) { add_edge(vertex(i,G), vertex(j,G), G); } } cout << "edges(g) = "; graph_traits::edge_iterator ei, ei_end; for (tie(ei, ei_end) = edges(G); ei != ei_end; ++ei) { cout << "(" << index[source(*ei, G)] << "," << index[target(*ei, G)] << ") "; } cout << num_edges(G) << std::endl; vector component(num_vertices(G)); int num_clusters = connected_components(G, &component[0], vertex_index_map(index)); }