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