| 1 |
|
|---|
| 2 | //=======================================================================
|
|---|
| 3 | // Copyright 2001 University of Notre Dame.
|
|---|
| 4 | // Author: Jeremy G. Siek
|
|---|
| 5 | //
|
|---|
| 6 | // Distributed under the Boost Software License, Version 1.0. (See
|
|---|
| 7 | // accompanying file LICENSE_1_0.txt or copy at
|
|---|
| 8 | // http://www.boost.org/LICENSE_1_0.txt)
|
|---|
| 9 | //=======================================================================
|
|---|
| 10 |
|
|---|
| 11 | #include <boost/config.hpp>
|
|---|
| 12 | #include <iostream>
|
|---|
| 13 | #include <boost/graph/subgraph.hpp>
|
|---|
| 14 | #include <boost/graph/adjacency_list.hpp>
|
|---|
| 15 | #include <boost/graph/graph_utility.hpp>
|
|---|
| 16 |
|
|---|
| 17 | int main(int,char*[])
|
|---|
| 18 | {
|
|---|
| 19 |
|
|---|
| 20 | using namespace boost;
|
|---|
| 21 | typedef adjacency_list_traits<vecS, vecS, directedS> Traits;
|
|---|
| 22 | typedef subgraph< adjacency_list<vecS, vecS, directedS,
|
|---|
| 23 | property<vertex_color_t, int>, property<edge_index_t, int> > > Graph;
|
|---|
| 24 |
|
|---|
| 25 | const int N = 10;
|
|---|
| 26 | Graph G0(N);
|
|---|
| 27 | enum { A, B, C, D, E, F}; // for conveniently referring to vertices in G0
|
|---|
| 28 |
|
|---|
| 29 | Graph& G1 = G0.create_subgraph();
|
|---|
| 30 | Graph& G2 = G0.create_subgraph();
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | enum { A1, B1, C1 }; // for conveniently referring to vertices in G1
|
|---|
| 34 | enum { A2, B2 }; // for conveniently referring to vertices in G2
|
|---|
| 35 |
|
|---|
| 36 | add_vertex(C, G1); // global vertex C becomes local A1 for G1
|
|---|
| 37 | add_vertex(E, G1); // global vertex E becomes local B1 for G1
|
|---|
| 38 | add_vertex(F, G1); // global vertex F becomes local C1 for G1
|
|---|
| 39 |
|
|---|
| 40 | add_vertex(A, G2); // global vertex A becomes local A1 for G2
|
|---|
| 41 | add_vertex(B, G2); // global vertex B becomes local B1 for G2
|
|---|
| 42 |
|
|---|
| 43 | Graph::edge_descriptor Ed[7];
|
|---|
| 44 | Ed[0] = add_edge(A, B, G0).first;
|
|---|
| 45 | Ed[1] = add_edge(B, C, G0).first;
|
|---|
| 46 | Ed[2] = add_edge(B, D, G0).first;
|
|---|
| 47 | Ed[3] = add_edge(E, B, G0).first;
|
|---|
| 48 | Ed[4] = add_edge(E, F, G0).first;
|
|---|
| 49 | Ed[5] = add_edge(F, D, G0).first;
|
|---|
| 50 |
|
|---|
| 51 | Ed[6] = add_edge(A1, C1, G1).first;
|
|---|
| 52 | // (A1,C1) is subgraph G1 local indices for (C,F).
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | std::list<Graph> graphlist;
|
|---|
| 57 | graphlist.push_back(G0);
|
|---|
| 58 | graphlist.push_back(G1);
|
|---|
| 59 | graphlist.push_back(G2);
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | std::list<Graph*> graph_ptrlist;
|
|---|
| 63 | graph_ptrlist.push_back(&G0);
|
|---|
| 64 | graph_ptrlist.push_back(&G1);
|
|---|
| 65 | graph_ptrlist.push_back(&G2);
|
|---|
| 66 |
|
|---|
| 67 | std::cout << "From the stack: \n";
|
|---|
| 68 |
|
|---|
| 69 | std::cout << "(root) graph: " ;
|
|---|
| 70 | print_edges2(G1, get(vertex_index, G1), get(edge_index, G1));
|
|---|
| 71 | std::cout << "num_edges= " << num_edges(G1) << std::endl;
|
|---|
| 72 |
|
|---|
| 73 | std::cout << "subgraph: " ;
|
|---|
| 74 | print_edges2(G2, get(vertex_index, G2), get(edge_index, G2));
|
|---|
| 75 | std::cout << "num_edges= " << num_edges(G2) << std::endl;
|
|---|
| 76 |
|
|---|
| 77 | std::cout << "subgraph: " ;
|
|---|
| 78 | print_edges2(G2, get(vertex_index, G2), get(edge_index, G2));
|
|---|
| 79 | std::cout << "num_edges= " << num_edges(G2) << std::endl;
|
|---|
| 80 |
|
|---|
| 81 | std::cout << "\nFrom list: \n";
|
|---|
| 82 | for (std::list<Graph>::iterator it = graphlist.begin(); it != graphlist.end(); ++it)
|
|---|
| 83 | {
|
|---|
| 84 | std::cout << "graph: " ;
|
|---|
| 85 | print_edges2(*it, get(vertex_index, *it), get(edge_index, *it));
|
|---|
| 86 | std::cout << "num_edges= " << num_edges(*it) << std::endl;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | return 0;
|
|---|
| 90 | }
|
|---|