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