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