Update contrib.
1 //=======================================================================
3 // Copyright (c) 2003 Institute of Transport,
4 // Railway Construction and Operation,
5 // University of Hanover, Germany
7 // Author: Jürgen Hunold
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)
13 //=======================================================================
15 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
18 #include <boost/config.hpp>
28 #include <boost/utility.hpp>
29 #include <boost/graph/property_iter_range.hpp>
30 #include <boost/graph/graph_utility.hpp>
31 #include <boost/graph/random.hpp>
32 #include <boost/pending/indirect_cmp.hpp>
34 #include <boost/random/mersenne_twister.hpp>
36 #include "std_log_result.h"
37 #define LOG_FILENAME_LINE __FILE__, __LINE__
40 enum vertex_id_t { vertex_id = 500 };
41 enum edge_id_t { edge_id = 501 };
43 BOOST_INSTALL_PROPERTY(vertex, id);
44 BOOST_INSTALL_PROPERTY(edge, id);
48 #include "graph_type.hpp" // this provides a typedef for Graph
50 using namespace boost;
53 This program tests the property range iterators
64 int main(int, char* [])
67 std::size_t N = 5, E = 0;
70 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
71 typedef boost::graph_traits<Graph>::edge_descriptor Edge;
74 std::size_t current_vertex_id = 0;
75 std::size_t current_edge_id = 0;
77 property_map<Graph, vertex_id_t>::type vertex_id_map = get(vertex_id, g);
79 property_map<Graph, edge_id_t>::type edge_id_map = get(edge_id, g);
81 for (std::size_t k = 0; k < N; ++k)
82 add_vertex(current_vertex_id++, g);
86 for (j=0; j < 10; ++j) {
90 cerr << "Testing add_edge ..." << endl;
92 for (i=0; i < 6; ++i) {
94 a = random_vertex(g, gen);
96 b = random_vertex(g, gen);
97 } while ( a == b ); // don't do self edges
99 cerr << "add_edge(" << vertex_id_map[a] << "," << vertex_id_map[b] <<")" << endl;
103 boost::tie(e, inserted) = add_edge(a, b, current_edge_id++, g);
105 std::cout << "inserted: " << inserted << std::endl;
106 std::cout << "source(e,g)" << source(e,g) << endl;
107 std::cout << "target(e,g)" << target(e,g) << endl;
108 std::cout << "edge_id[e] = " << edge_id_map[e] << std::endl;
109 print_edges2(g, vertex_id_map, edge_id_map);
110 print_graph(g, vertex_id_map);
111 std::cout << "finished printing" << std::endl;
117 typedef boost::graph_property_iter_range< Graph, vertex_id_t>::const_iterator TNodeConstIterator;
118 typedef boost::graph_property_iter_range< Graph, vertex_id_t>::const_type TNodeConstIteratorType;
120 typedef boost::graph_property_iter_range< Graph, vertex_id_t>::iterator TNodeIterator;
121 typedef boost::graph_property_iter_range< Graph, vertex_id_t>::type TNodeIteratorType;
123 typedef boost::graph_property_iter_range< Graph, edge_id_t>::const_iterator TLinkConstIterator;
124 typedef boost::graph_property_iter_range< Graph, edge_id_t>::const_type TLinkConstIteratorType;
126 typedef boost::graph_property_iter_range< Graph, edge_id_t>::iterator TLinkIterator;
127 typedef boost::graph_property_iter_range< Graph, edge_id_t>::type TLinkIteratorType;
129 typedef std::pair<TLinkConstIterator, TLinkConstIterator> tLinkConstIteratorPair;
131 TLinkIterator itEdgeBegin, itEdgeEnd;
133 tie(itEdgeBegin, itEdgeEnd) = get_property_iter_range(g, edge_id);
135 cout << "Edge iteration:" << endl;
136 for (; itEdgeBegin != itEdgeEnd; ++itEdgeBegin)
138 cout << *itEdgeBegin;
142 TNodeIterator itVertexBegin, itVertexEnd;
144 tie(itVertexBegin, itVertexEnd) = get_property_iter_range(g, vertex_id);
146 cout << "Vertex iteration:" << endl;
147 for (; itVertexBegin != itVertexEnd; ++itVertexBegin)
149 cout << *itVertexBegin;
155 std_log(LOG_FILENAME_LINE,"[End Test Case ]");
157 testResultXml("property_iter");