//======================================================================= // Copyright 2001 University of Notre Dame. // Author: Jeremy G. Siek // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //======================================================================= #include #include #include #include #include int main(int,char*[]) { using namespace boost; typedef adjacency_list_traits Traits; typedef subgraph< adjacency_list, property > > Graph; const int N = 10; Graph G0(N); enum { A, B, C, D, E, F}; // for conveniently referring to vertices in G0 Graph& G1 = G0.create_subgraph(); Graph& G2 = G0.create_subgraph(); enum { A1, B1, C1 }; // for conveniently referring to vertices in G1 enum { A2, B2 }; // for conveniently referring to vertices in G2 add_vertex(C, G1); // global vertex C becomes local A1 for G1 add_vertex(E, G1); // global vertex E becomes local B1 for G1 add_vertex(F, G1); // global vertex F becomes local C1 for G1 add_vertex(A, G2); // global vertex A becomes local A1 for G2 add_vertex(B, G2); // global vertex B becomes local B1 for G2 Graph::edge_descriptor Ed[7]; Ed[0] = add_edge(A, B, G0).first; Ed[1] = add_edge(B, C, G0).first; Ed[2] = add_edge(B, D, G0).first; Ed[3] = add_edge(E, B, G0).first; Ed[4] = add_edge(E, F, G0).first; Ed[5] = add_edge(F, D, G0).first; Ed[6] = add_edge(A1, C1, G1).first; // (A1,C1) is subgraph G1 local indices for (C,F). std::list graphlist; graphlist.push_back(G0); graphlist.push_back(G1); graphlist.push_back(G2); std::list graph_ptrlist; graph_ptrlist.push_back(&G0); graph_ptrlist.push_back(&G1); graph_ptrlist.push_back(&G2); std::cout << "From the stack: \n"; std::cout << "(root) graph: " ; print_edges2(G1, get(vertex_index, G1), get(edge_index, G1)); std::cout << "num_edges= " << num_edges(G1) << std::endl; std::cout << "subgraph: " ; print_edges2(G2, get(vertex_index, G2), get(edge_index, G2)); std::cout << "num_edges= " << num_edges(G2) << std::endl; std::cout << "subgraph: " ; print_edges2(G2, get(vertex_index, G2), get(edge_index, G2)); std::cout << "num_edges= " << num_edges(G2) << std::endl; std::cout << "\nFrom list: \n"; for (std::list::iterator it = graphlist.begin(); it != graphlist.end(); ++it) { std::cout << "graph: " ; print_edges2(*it, get(vertex_index, *it), get(edge_index, *it)); std::cout << "num_edges= " << num_edges(*it) << std::endl; } return 0; }