stdcpp/tsrc/Boost_test/graph/src/property_iter.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 //=======================================================================
       
     2 //
       
     3 //  Copyright (c) 2003 Institute of Transport, 
       
     4 //                     Railway Construction and Operation, 
       
     5 //                     University of Hanover, Germany
       
     6 //
       
     7 //  Author: Jürgen 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  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
       
    16 */
       
    17 
       
    18 #include <boost/config.hpp>
       
    19 
       
    20 #include <iostream>
       
    21 #include <vector>
       
    22 #include <set>
       
    23 #include <utility>
       
    24 #include <algorithm>
       
    25 
       
    26 #define VERBOSE 0
       
    27 
       
    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>
       
    33 
       
    34 #include <boost/random/mersenne_twister.hpp>
       
    35 #ifdef __SYMBIAN32__
       
    36 #include "std_log_result.h"
       
    37 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    38 #endif
       
    39 
       
    40 enum vertex_id_t { vertex_id = 500 };
       
    41 enum edge_id_t { edge_id = 501 };
       
    42 namespace boost {
       
    43   BOOST_INSTALL_PROPERTY(vertex, id);
       
    44   BOOST_INSTALL_PROPERTY(edge, id);
       
    45 }
       
    46 
       
    47 
       
    48 #include "graph_type.hpp" // this provides a typedef for Graph
       
    49 
       
    50 using namespace boost;
       
    51 
       
    52 /*
       
    53   This program tests the property range iterators
       
    54  */
       
    55 
       
    56 #ifndef __SYMBIAN32__
       
    57 using std::cout;
       
    58 using std::endl;
       
    59 using std::cerr;
       
    60 #endif
       
    61 using std::find;
       
    62 
       
    63 using namespace std;
       
    64 int main(int, char* [])
       
    65 {
       
    66   int ret = 0;
       
    67   std::size_t N = 5, E = 0;
       
    68 
       
    69   Graph g;
       
    70   typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
       
    71   typedef boost::graph_traits<Graph>::edge_descriptor Edge;
       
    72 
       
    73   int i, j;
       
    74   std::size_t current_vertex_id = 0;
       
    75   std::size_t current_edge_id = 0;
       
    76 
       
    77   property_map<Graph, vertex_id_t>::type vertex_id_map = get(vertex_id, g);
       
    78 
       
    79   property_map<Graph, edge_id_t>::type edge_id_map = get(edge_id, g);
       
    80 
       
    81   for (std::size_t k = 0; k < N; ++k)
       
    82     add_vertex(current_vertex_id++, g);
       
    83 
       
    84   mt19937 gen;
       
    85 
       
    86   for (j=0; j < 10; ++j) {
       
    87 
       
    88     // add_edge
       
    89 #if VERBOSE
       
    90     cerr << "Testing add_edge ..." << endl;
       
    91 #endif
       
    92     for (i=0; i < 6; ++i) {
       
    93       Vertex a, b;
       
    94       a = random_vertex(g, gen);
       
    95       do {
       
    96         b = random_vertex(g, gen);
       
    97       } while ( a == b ); // don't do self edges
       
    98 #if VERBOSE
       
    99       cerr << "add_edge(" << vertex_id_map[a] << "," << vertex_id_map[b] <<")" << endl;
       
   100 #endif
       
   101       Edge e;
       
   102       bool inserted;
       
   103       boost::tie(e, inserted) = add_edge(a, b, current_edge_id++, g);
       
   104 #if VERBOSE
       
   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;
       
   112 #endif
       
   113       }
       
   114       ++E;
       
   115     }
       
   116 
       
   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;
       
   119 
       
   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;
       
   122 
       
   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;
       
   125 
       
   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;
       
   128 
       
   129   typedef std::pair<TLinkConstIterator, TLinkConstIterator> tLinkConstIteratorPair;
       
   130 
       
   131   TLinkIterator itEdgeBegin, itEdgeEnd;
       
   132 
       
   133   tie(itEdgeBegin, itEdgeEnd) = get_property_iter_range(g, edge_id);
       
   134 
       
   135   cout << "Edge iteration:" << endl;
       
   136   for (; itEdgeBegin != itEdgeEnd; ++itEdgeBegin)
       
   137   {
       
   138       cout << *itEdgeBegin;
       
   139   }
       
   140   cout << endl;
       
   141 
       
   142   TNodeIterator itVertexBegin, itVertexEnd;
       
   143 
       
   144   tie(itVertexBegin, itVertexEnd) = get_property_iter_range(g, vertex_id);
       
   145 
       
   146   cout << "Vertex iteration:" << endl;
       
   147   for (; itVertexBegin != itVertexEnd; ++itVertexBegin)
       
   148   {
       
   149       cout << *itVertexBegin;
       
   150   }
       
   151   cout << endl;
       
   152 
       
   153    
       
   154 #ifdef __SYMBIAN32__
       
   155 std_log(LOG_FILENAME_LINE,"[End Test Case ]");
       
   156 
       
   157 	testResultXml("property_iter");
       
   158 	close_log_file();
       
   159 #endif
       
   160   return ret;
       
   161 }