1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/graph/src/property_iter.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,161 @@
1.4 +//=======================================================================
1.5 +//
1.6 +// Copyright (c) 2003 Institute of Transport,
1.7 +// Railway Construction and Operation,
1.8 +// University of Hanover, Germany
1.9 +//
1.10 +// Author: Jürgen Hunold
1.11 +//
1.12 +// Use, modification and distribution are subject to the
1.13 +// Boost Software License, Version 1.0. (See accompanying file
1.14 +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1.15 +//
1.16 +//=======================================================================
1.17 +/*
1.18 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.19 +*/
1.20 +
1.21 +#include <boost/config.hpp>
1.22 +
1.23 +#include <iostream>
1.24 +#include <vector>
1.25 +#include <set>
1.26 +#include <utility>
1.27 +#include <algorithm>
1.28 +
1.29 +#define VERBOSE 0
1.30 +
1.31 +#include <boost/utility.hpp>
1.32 +#include <boost/graph/property_iter_range.hpp>
1.33 +#include <boost/graph/graph_utility.hpp>
1.34 +#include <boost/graph/random.hpp>
1.35 +#include <boost/pending/indirect_cmp.hpp>
1.36 +
1.37 +#include <boost/random/mersenne_twister.hpp>
1.38 +#ifdef __SYMBIAN32__
1.39 +#include "std_log_result.h"
1.40 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.41 +#endif
1.42 +
1.43 +enum vertex_id_t { vertex_id = 500 };
1.44 +enum edge_id_t { edge_id = 501 };
1.45 +namespace boost {
1.46 + BOOST_INSTALL_PROPERTY(vertex, id);
1.47 + BOOST_INSTALL_PROPERTY(edge, id);
1.48 +}
1.49 +
1.50 +
1.51 +#include "graph_type.hpp" // this provides a typedef for Graph
1.52 +
1.53 +using namespace boost;
1.54 +
1.55 +/*
1.56 + This program tests the property range iterators
1.57 + */
1.58 +
1.59 +#ifndef __SYMBIAN32__
1.60 +using std::cout;
1.61 +using std::endl;
1.62 +using std::cerr;
1.63 +#endif
1.64 +using std::find;
1.65 +
1.66 +using namespace std;
1.67 +int main(int, char* [])
1.68 +{
1.69 + int ret = 0;
1.70 + std::size_t N = 5, E = 0;
1.71 +
1.72 + Graph g;
1.73 + typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
1.74 + typedef boost::graph_traits<Graph>::edge_descriptor Edge;
1.75 +
1.76 + int i, j;
1.77 + std::size_t current_vertex_id = 0;
1.78 + std::size_t current_edge_id = 0;
1.79 +
1.80 + property_map<Graph, vertex_id_t>::type vertex_id_map = get(vertex_id, g);
1.81 +
1.82 + property_map<Graph, edge_id_t>::type edge_id_map = get(edge_id, g);
1.83 +
1.84 + for (std::size_t k = 0; k < N; ++k)
1.85 + add_vertex(current_vertex_id++, g);
1.86 +
1.87 + mt19937 gen;
1.88 +
1.89 + for (j=0; j < 10; ++j) {
1.90 +
1.91 + // add_edge
1.92 +#if VERBOSE
1.93 + cerr << "Testing add_edge ..." << endl;
1.94 +#endif
1.95 + for (i=0; i < 6; ++i) {
1.96 + Vertex a, b;
1.97 + a = random_vertex(g, gen);
1.98 + do {
1.99 + b = random_vertex(g, gen);
1.100 + } while ( a == b ); // don't do self edges
1.101 +#if VERBOSE
1.102 + cerr << "add_edge(" << vertex_id_map[a] << "," << vertex_id_map[b] <<")" << endl;
1.103 +#endif
1.104 + Edge e;
1.105 + bool inserted;
1.106 + boost::tie(e, inserted) = add_edge(a, b, current_edge_id++, g);
1.107 +#if VERBOSE
1.108 + std::cout << "inserted: " << inserted << std::endl;
1.109 + std::cout << "source(e,g)" << source(e,g) << endl;
1.110 + std::cout << "target(e,g)" << target(e,g) << endl;
1.111 + std::cout << "edge_id[e] = " << edge_id_map[e] << std::endl;
1.112 + print_edges2(g, vertex_id_map, edge_id_map);
1.113 + print_graph(g, vertex_id_map);
1.114 + std::cout << "finished printing" << std::endl;
1.115 +#endif
1.116 + }
1.117 + ++E;
1.118 + }
1.119 +
1.120 + typedef boost::graph_property_iter_range< Graph, vertex_id_t>::const_iterator TNodeConstIterator;
1.121 + typedef boost::graph_property_iter_range< Graph, vertex_id_t>::const_type TNodeConstIteratorType;
1.122 +
1.123 + typedef boost::graph_property_iter_range< Graph, vertex_id_t>::iterator TNodeIterator;
1.124 + typedef boost::graph_property_iter_range< Graph, vertex_id_t>::type TNodeIteratorType;
1.125 +
1.126 + typedef boost::graph_property_iter_range< Graph, edge_id_t>::const_iterator TLinkConstIterator;
1.127 + typedef boost::graph_property_iter_range< Graph, edge_id_t>::const_type TLinkConstIteratorType;
1.128 +
1.129 + typedef boost::graph_property_iter_range< Graph, edge_id_t>::iterator TLinkIterator;
1.130 + typedef boost::graph_property_iter_range< Graph, edge_id_t>::type TLinkIteratorType;
1.131 +
1.132 + typedef std::pair<TLinkConstIterator, TLinkConstIterator> tLinkConstIteratorPair;
1.133 +
1.134 + TLinkIterator itEdgeBegin, itEdgeEnd;
1.135 +
1.136 + tie(itEdgeBegin, itEdgeEnd) = get_property_iter_range(g, edge_id);
1.137 +
1.138 + cout << "Edge iteration:" << endl;
1.139 + for (; itEdgeBegin != itEdgeEnd; ++itEdgeBegin)
1.140 + {
1.141 + cout << *itEdgeBegin;
1.142 + }
1.143 + cout << endl;
1.144 +
1.145 + TNodeIterator itVertexBegin, itVertexEnd;
1.146 +
1.147 + tie(itVertexBegin, itVertexEnd) = get_property_iter_range(g, vertex_id);
1.148 +
1.149 + cout << "Vertex iteration:" << endl;
1.150 + for (; itVertexBegin != itVertexEnd; ++itVertexBegin)
1.151 + {
1.152 + cout << *itVertexBegin;
1.153 + }
1.154 + cout << endl;
1.155 +
1.156 +
1.157 +#ifdef __SYMBIAN32__
1.158 +std_log(LOG_FILENAME_LINE,"[End Test Case ]");
1.159 +
1.160 + testResultXml("property_iter");
1.161 + close_log_file();
1.162 +#endif
1.163 + return ret;
1.164 +}