#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; typedef graph_traits::vertex_descriptor Vertex; map< Vertex, unsigned int > index_std_map; int num_nodes=10; // construct a graph object graph_t G(num_nodes); typedef associative_property_map< map< Vertex, unsigned int > > IndexMap; IndexMap index( index_std_map ); vector v_component(num_vertices(G)); iterator_property_map< vector::iterator, IndexMap > component( v_component.begin(), index ); int num_clusters = connected_components(G, component, vertex_index_map(index)); cout << num_clusters << 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); } } for (unsigned int i = 0; i != num_nodes; ++i) { int num_neighbour = out_degree(vertex(i,G), G); cout << " i " << i << " num_neighbour " << num_neighbour << endl; } cout << num_edges(G) << std::endl; num_clusters = connected_components(G, component, vertex_index_map(index)); cout << num_clusters << endl; for (unsigned int i = 0; i != num_nodes; ++i) { clear_vertex(vertex(i,G), G); cout << connected_components(G, component, vertex_index_map(index)) << endl; } for (unsigned int i = 0; i != num_nodes; ++i) { int num_neighbour = out_degree(vertex(i,G), G); cout << " i " << i << " num_neighbour " << num_neighbour << endl; } // for (i = 0; i != num_nodes; ++i) // cout << "Vertex " << i <<" is in component " << component[i] << endl; // cout << endl; }