1 //=======================================================================
2 //
3 // Copyright (c) 2003 Institute of Transport,
4 // Railway Construction and Operation,
5 // University of Hanover, Germany
6 //
7 // Author: Juergen Hunold
8 //
9 // Use, modification and distribution are subject to the
10 // Boost Software License, Version 1.0. (See accompanying file
11 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 //
13 //=======================================================================
14
15 #include <boost/config.hpp>
16
17 #include <iostream>
18 #include <vector>
19 #include <set>
20 #include <utility>
21 #include <algorithm>
22
23 #define VERBOSE 0
24
25 #include <boost/utility.hpp>
26 #include <boost/graph/property_iter_range.hpp>
27 #include <boost/graph/graph_utility.hpp>
28 #include <boost/graph/random.hpp>
29 #include <boost/pending/indirect_cmp.hpp>
30
31 #include <boost/random/mersenne_twister.hpp>
32
33 enum vertex_id_t
34 {
35 vertex_id = 500
36 };
37 enum edge_id_t
38 {
39 edge_id = 501
40 };
41 namespace boost
42 {
43 BOOST_INSTALL_PROPERTY(vertex, id);
44 BOOST_INSTALL_PROPERTY(edge, id);
45 }
46
47 #include "graph_type.hpp" // this provides a typedef for Graph
48
49 using namespace boost;
50
51 /*
52 This program tests the property range iterators
53 */
54
55 using std::cerr;
56 using std::cout;
57 using std::endl;
58 using std::find;
59
main(int,char * [])60 int main(int, char*[])
61 {
62 int ret = 0;
63 std::size_t N = 5, E = 0;
64
65 typedef ::Graph Graph;
66 Graph g;
67 typedef boost::graph_traits< Graph >::vertex_descriptor Vertex;
68 typedef boost::graph_traits< Graph >::edge_descriptor Edge;
69
70 int i, j;
71 std::size_t current_vertex_id = 0;
72 std::size_t current_edge_id = 0;
73
74 property_map< Graph, vertex_id_t >::type vertex_id_map = get(vertex_id, g);
75 (void)vertex_id_map;
76
77 property_map< Graph, edge_id_t >::type edge_id_map = get(edge_id, g);
78 (void)edge_id_map;
79
80 for (std::size_t k = 0; k < N; ++k)
81 add_vertex(current_vertex_id++, g);
82
83 mt19937 gen;
84
85 for (j = 0; j < 10; ++j)
86 {
87
88 // add_edge
89 #if VERBOSE
90 cerr << "Testing add_edge ..." << endl;
91 #endif
92 for (i = 0; i < 6; ++i)
93 {
94 Vertex a, b;
95 a = random_vertex(g, gen);
96 do
97 {
98 b = random_vertex(g, gen);
99 } while (a == b); // don't do self edges
100 #if VERBOSE
101 cerr << "add_edge(" << vertex_id_map[a] << "," << vertex_id_map[b]
102 << ")" << endl;
103 #endif
104 Edge e;
105 bool inserted;
106 boost::tie(e, inserted) = add_edge(a, b, current_edge_id++, g);
107 #if VERBOSE
108 std::cout << "inserted: " << inserted << std::endl;
109 std::cout << "source(e,g)" << source(e, g) << endl;
110 std::cout << "target(e,g)" << target(e, g) << endl;
111 std::cout << "edge_id[e] = " << edge_id_map[e] << std::endl;
112 print_edges2(g, vertex_id_map, edge_id_map);
113 print_graph(g, vertex_id_map);
114 std::cout << "finished printing" << std::endl;
115 #endif
116 }
117 ++E;
118 }
119
120 typedef boost::graph_property_iter_range< Graph, vertex_id_t >::iterator
121 TNodeIterator;
122
123 typedef boost::graph_property_iter_range< Graph, edge_id_t >::iterator
124 TLinkIterator;
125
126 TLinkIterator itEdgeBegin, itEdgeEnd;
127
128 boost::tie(itEdgeBegin, itEdgeEnd) = get_property_iter_range(g, edge_id);
129
130 cout << "Edge iteration:" << endl;
131 for (; itEdgeBegin != itEdgeEnd; ++itEdgeBegin)
132 {
133 cout << *itEdgeBegin;
134 }
135 cout << endl;
136
137 TNodeIterator itVertexBegin, itVertexEnd;
138
139 boost::tie(itVertexBegin, itVertexEnd)
140 = get_property_iter_range(g, vertex_id);
141
142 cout << "Vertex iteration:" << endl;
143 for (; itVertexBegin != itVertexEnd; ++itVertexBegin)
144 {
145 cout << *itVertexBegin;
146 }
147 cout << endl;
148
149 return ret;
150 }
151