File: property_iter.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (150 lines) | stat: -rw-r--r-- 3,826 bytes parent folder | download | duplicates (10)
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
149
150
//=======================================================================
//
//  Copyright (c) 2003 Institute of Transport,
//                     Railway Construction and Operation,
//                     University of Hanover, Germany
//
//  Author: Juergen 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::cerr;
using std::cout;
using std::endl;
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);
    (void)vertex_id_map;

    property_map< Graph, edge_id_t >::type edge_id_map = get(edge_id, g);
    (void)edge_id_map;

    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 >::iterator
        TNodeIterator;

    typedef boost::graph_property_iter_range< Graph, edge_id_t >::iterator
        TLinkIterator;

    TLinkIterator itEdgeBegin, itEdgeEnd;

    boost::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;

    boost::tie(itVertexBegin, itVertexEnd)
        = get_property_iter_range(g, vertex_id);

    cout << "Vertex iteration:" << endl;
    for (; itVertexBegin != itVertexEnd; ++itVertexBegin)
    {
        cout << *itVertexBegin;
    }
    cout << endl;

    return ret;
}