1 // (C) Copyright Jeremy Siek 2004
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 /*
7 Sample output:
8
9 After initializing properties for G1:
10 Global and local properties for vertex G0[C]...
11 G0[C]= A1
12 G1[A1]= A1
13 Global and local properties for vertex G0[E]...
14 G0[E]= B1
15 G1[B1]= B1
16 Global and local properties for vertex G0[F]...
17 G0[F]= C1
18 G1[C1]= C1
19
20
21 After initializing properties for G2:
22 Global and local properties for vertex G0[A]
23 G0[A]= A2
24 G2[A2]= A2
25 Global and local properties for vertex G0[C]...
26 G0[C]= B2
27 G1[A1]= B2
28 G2[B2]= B2
29
30 */
31
32 #include <boost/config.hpp>
33 #include <iostream>
34 #include <boost/graph/subgraph.hpp>
35 #include <boost/graph/adjacency_list.hpp>
36 #include <boost/graph/graph_utility.hpp>
37
main(int,char * [])38 int main(int, char*[])
39 {
40 using namespace boost;
41 // typedef adjacency_list_traits<vecS, vecS, directedS> Traits;// Does
42 // nothing?
43 typedef property< vertex_color_t, int,
44 property< vertex_name_t, std::string > >
45 VertexProperty;
46
47 typedef subgraph< adjacency_list< vecS, vecS, directedS, VertexProperty,
48 property< edge_index_t, int > > >
49 Graph;
50
51 const int N = 6;
52 Graph G0(N);
53 enum
54 {
55 A,
56 B,
57 C,
58 D,
59 E,
60 F
61 }; // for conveniently refering to vertices in G0
62
63 property_map< Graph, vertex_name_t >::type name = get(vertex_name_t(), G0);
64 name[A] = "A";
65 name[B] = "B";
66 name[C] = "C";
67 name[D] = "D";
68 name[E] = "E";
69 name[F] = "F";
70
71 Graph& G1 = G0.create_subgraph();
72 enum
73 {
74 A1,
75 B1,
76 C1
77 }; // for conveniently refering to vertices in G1
78
79 add_vertex(C, G1); // global vertex C becomes local A1 for G1
80 add_vertex(E, G1); // global vertex E becomes local B1 for G1
81 add_vertex(F, G1); // global vertex F becomes local C1 for G1
82
83 property_map< Graph, vertex_name_t >::type name1 = get(vertex_name_t(), G1);
84 name1[A1] = "A1";
85
86 std::cout << std::endl
87 << "After initializing properties for G1:" << std::endl;
88 std::cout << " Global and local properties for vertex G0[C]..."
89 << std::endl;
90 std::cout << " G0[C]= " << boost::get(vertex_name, G0, vertex(C, G0))
91 << std::endl; // prints: "G0[C]= C"
92 std::cout << " G1[A1]= " << boost::get(vertex_name, G1, vertex(A1, G1))
93 << std::endl; // prints: "G1[A1]= A1"
94
95 name1[B1] = "B1";
96
97 std::cout << " Global and local properties for vertex G0[E]..."
98 << std::endl;
99 std::cout << " G0[E]= " << boost::get(vertex_name, G0, vertex(E, G0))
100 << std::endl; // prints: "G0[E]= E"
101 std::cout << " G1[B1]= " << boost::get(vertex_name, G1, vertex(B1, G1))
102 << std::endl; // prints: "G1[B1]= B1"
103
104 name1[C1] = "C1";
105
106 std::cout << " Global and local properties for vertex G0[F]..."
107 << std::endl;
108 std::cout << " G0[F]= " << boost::get(vertex_name, G0, vertex(F, G0))
109 << std::endl; // prints: "G0[F]= F"
110 std::cout << " G1[C1]= " << boost::get(vertex_name, G1, vertex(C1, G1))
111 << std::endl; // prints: "G1[C1]= C1"
112
113 Graph& G2 = G0.create_subgraph();
114 enum
115 {
116 A2,
117 B2
118 }; // for conveniently refering to vertices in G2
119
120 add_vertex(A, G2); // global vertex A becomes local A2 for G2
121 add_vertex(C, G2); // global vertex C becomes local B2 for G2
122
123 property_map< Graph, vertex_name_t >::type name2 = get(vertex_name_t(), G2);
124 name2[A2] = "A2";
125
126 std::cout << std::endl
127 << std::endl
128 << "After initializing properties for G2:" << std::endl;
129 std::cout << " Global and local properties for vertex G0[A]" << std::endl;
130 std::cout << " G0[A]= " << boost::get(vertex_name, G0, vertex(A, G0))
131 << std::endl; // prints: "G0[A]= A"
132 std::cout << " G2[A2]= " << boost::get(vertex_name, G2, vertex(A2, G2))
133 << std::endl; // prints: "G2[A2]= A2"
134
135 name2[B2] = "B2";
136
137 std::cout << " Global and local properties for vertex G0[C]..."
138 << std::endl;
139 std::cout << " G0[C]= " << boost::get(vertex_name, G0, vertex(C, G0))
140 << std::endl; // prints: "G0[C]= C"
141 std::cout << " G1[A1]= " << boost::get(vertex_name, G1, vertex(A1, G1))
142 << std::endl; // prints: "G1[A1]= A1"
143 std::cout << " G2[B2]= " << boost::get(vertex_name, G2, vertex(B2, G2))
144 << std::endl; // prints: "G2[B2]= B2"
145
146 return 0;
147 }
148