Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/example/subgraph_properties.cpp @ 30

Last change on this file since 30 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.2 KB
Line 
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
38int main(int,char*[])
39{
40  using namespace boost;
41  //typedef adjacency_list_traits<vecS, vecS, directedS> Traits;// Does nothing?
42  typedef property<   vertex_color_t, int,
43    property< vertex_name_t, std::string > > VertexProperty;
44 
45  typedef subgraph< adjacency_list<  vecS, vecS, directedS,
46    VertexProperty, 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  property_map<Graph, vertex_name_t>::type name = get(vertex_name_t(), G0);
53  name[A] = "A";
54  name[B] = "B";
55  name[C] = "C";
56  name[D] = "D";
57  name[E] = "E";
58  name[F] = "F";
59 
60  Graph& G1 = G0.create_subgraph();
61  enum { A1, B1, C1 };          // for conveniently refering to vertices in G1
62 
63  add_vertex(C, G1); // global vertex C becomes local A1 for G1
64  add_vertex(E, G1); // global vertex E becomes local B1 for G1
65  add_vertex(F, G1); // global vertex F becomes local C1 for G1
66 
67  property_map<Graph, vertex_name_t>::type name1 = get(vertex_name_t(), G1);
68  name1[A1] = "A1";
69 
70  std::cout << std::endl << "After initializing properties for G1:" << std::endl;
71  std::cout << "  Global and local properties for vertex G0[C]..." << std::endl;
72  std::cout << "    G0[C]= " << boost::get(vertex_name, G0, C) << std::endl;// prints: "G0[C]= C"
73  std::cout << "    G1[A1]= " << boost::get(vertex_name, G1, A1) << std::endl;// prints: "G1[A1]= A1"
74 
75  name1[B1] = "B1";
76 
77  std::cout << "  Global and local properties for vertex G0[E]..." << std::endl;
78  std::cout << "    G0[E]= " << boost::get(vertex_name, G0, E) << std::endl;// prints: "G0[E]= E"
79  std::cout << "    G1[B1]= " << boost::get(vertex_name, G1, B1) << std::endl;// prints: "G1[B1]= B1"
80 
81  name1[C1] = "C1";
82 
83  std::cout << "  Global and local properties for vertex G0[F]..." << std::endl;
84  std::cout << "    G0[F]= " << boost::get(vertex_name, G0, F) << std::endl;// prints: "G0[F]= F"
85  std::cout << "    G1[C1]= " << boost::get(vertex_name, G1, C1) << std::endl;// prints: "G1[C1]= C1"
86 
87  Graph& G2 = G0.create_subgraph();
88  enum { A2, B2 };              // for conveniently refering to vertices in G2
89 
90  add_vertex(A, G2); // global vertex A becomes local A2 for G2
91  add_vertex(C, G2); // global vertex C becomes local B2 for G2
92 
93  property_map<Graph, vertex_name_t>::type name2 = get(vertex_name_t(), G2);
94  name2[A2] = "A2";
95 
96  std::cout << std::endl << std::endl << "After initializing properties for G2:" << std::endl;
97  std::cout << "  Global and local properties for vertex G0[A]" << std::endl;
98  std::cout << "    G0[A]= " << boost::get(vertex_name, G0, A) << std::endl;// prints: "G0[A]= A"
99  std::cout << "    G2[A2]= " << boost::get(vertex_name, G2, A2) << std::endl;// prints: "G2[A2]= A2"
100 
101  name2[B2] = "B2";
102 
103  std::cout << "  Global and local properties for vertex G0[C]..." << std::endl;
104  std::cout << "    G0[C]= " << boost::get(vertex_name, G0, C) << std::endl;// prints: "G0[C]= C"
105  std::cout << "    G1[A1]= " << boost::get(vertex_name, G1, A1) << std::endl;// prints: "G1[A1]= A1"
106  std::cout << "    G2[B2]= " << boost::get(vertex_name, G2, B2) << std::endl;// prints: "G2[B2]= B2"
107 
108  return 0;
109}
Note: See TracBrowser for help on using the repository browser.