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
34 enum vertex_id_t { vertex_id = 500 };
35 enum edge_id_t { edge_id = 501 };
36 namespace boost {
37 BOOST_INSTALL_PROPERTY(vertex, id);
38 BOOST_INSTALL_PROPERTY(edge, id);
39 }
40
41
42 #include "graph_type.hpp" // this provides a typedef for Graph
43
44 using namespace boost;
45
46 /*
47 This program tests the property range iterators
48 */
49
50 using std::cout;
51 using std::endl;
52 using std::cerr;
53 using std::find;
54
55
main(int,char * [])56 int main(int, char* [])
57 {
58 int ret = 0;
59 std::size_t N = 5, E = 0;
60
61 typedef ::Graph Graph;
62 Graph g;
63 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
64 typedef boost::graph_traits<Graph>::edge_descriptor Edge;
65
66 int i, j;
67 std::size_t current_vertex_id = 0;
68 std::size_t current_edge_id = 0;
69
70 property_map<Graph, vertex_id_t>::type vertex_id_map = get(vertex_id, g);
71 (void)vertex_id_map;
72
73 property_map<Graph, edge_id_t>::type edge_id_map = get(edge_id, g);
74 (void)edge_id_map;
75
76 for (std::size_t k = 0; k < N; ++k)
77 add_vertex(current_vertex_id++, g);
78
79 mt19937 gen;
80
81 for (j=0; j < 10; ++j) {
82
83 // add_edge
84 #if VERBOSE
85 cerr << "Testing add_edge ..." << endl;
86 #endif
87 for (i=0; i < 6; ++i) {
88 Vertex a, b;
89 a = random_vertex(g, gen);
90 do {
91 b = random_vertex(g, gen);
92 } while ( a == b ); // don't do self edges
93 #if VERBOSE
94 cerr << "add_edge(" << vertex_id_map[a] << "," << vertex_id_map[b] <<")" << endl;
95 #endif
96 Edge e;
97 bool inserted;
98 boost::tie(e, inserted) = add_edge(a, b, current_edge_id++, g);
99 #if VERBOSE
100 std::cout << "inserted: " << inserted << std::endl;
101 std::cout << "source(e,g)" << source(e,g) << endl;
102 std::cout << "target(e,g)" << target(e,g) << endl;
103 std::cout << "edge_id[e] = " << edge_id_map[e] << std::endl;
104 print_edges2(g, vertex_id_map, edge_id_map);
105 print_graph(g, vertex_id_map);
106 std::cout << "finished printing" << std::endl;
107 #endif
108 }
109 ++E;
110 }
111
112 typedef boost::graph_property_iter_range< Graph, vertex_id_t>::iterator TNodeIterator;
113
114 typedef boost::graph_property_iter_range< Graph, edge_id_t>::iterator TLinkIterator;
115
116 TLinkIterator itEdgeBegin, itEdgeEnd;
117
118 boost::tie(itEdgeBegin, itEdgeEnd) = get_property_iter_range(g, edge_id);
119
120 cout << "Edge iteration:" << endl;
121 for (; itEdgeBegin != itEdgeEnd; ++itEdgeBegin)
122 {
123 cout << *itEdgeBegin;
124 }
125 cout << endl;
126
127 TNodeIterator itVertexBegin, itVertexEnd;
128
129 boost::tie(itVertexBegin, itVertexEnd) = get_property_iter_range(g, vertex_id);
130
131 cout << "Vertex iteration:" << endl;
132 for (; itVertexBegin != itVertexEnd; ++itVertexBegin)
133 {
134 cout << *itVertexBegin;
135 }
136 cout << endl;
137
138
139 return ret;
140 }
141