File: subgraph_props.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 (133 lines) | stat: -rw-r--r-- 4,496 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
// (C) Copyright Andrew Sutton 2009
// Distributed under 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 <iostream>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/subgraph.hpp>
#include "typestr.hpp"

using namespace boost;

struct TestProps
{
    typedef property< vertex_name_t, std::size_t > VertexProp;
    typedef property< edge_name_t, std::size_t > EdgeName;
    typedef property< edge_index_t, std::size_t, EdgeName > EdgeProp;

    typedef adjacency_list< vecS, vecS, bidirectionalS, VertexProp, EdgeProp >
        Graph;

    typedef subgraph< Graph > Subgraph;
    typedef graph_traits< Subgraph >::vertex_descriptor Vertex;
    typedef graph_traits< Subgraph >::edge_descriptor Edge;
    typedef graph_traits< Subgraph >::vertex_iterator VertexIter;
    typedef std::pair< VertexIter, VertexIter > VertexRange;

    static void run()
    {
        // Create a graph with some vertices.
        Subgraph g(5);
        VertexRange r = vertices(g);

        // Create a child subgraph and add some vertices.
        Subgraph& sg = g.create_subgraph();
        Vertex v = add_vertex(*r.first, sg);

        typedef property_map< Subgraph, vertex_name_t >::type DefaultMap;
        DefaultMap map = get(vertex_name, g);
        BOOST_ASSERT(get(map, v) == 0);
        put(map, v, 5);
        BOOST_ASSERT(get(map, v) == 5);

        typedef global_property< vertex_name_t > GlobalProp;
        typedef property_map< Subgraph, GlobalProp >::type GlobalVertMap;
        GlobalVertMap groot = get(global(vertex_name), g);
        GlobalVertMap gsub = get(global(vertex_name), sg);
        BOOST_ASSERT(get(groot, v) == 5);
        BOOST_ASSERT(get(gsub, v) == 5);
        put(gsub, v, 10);
        BOOST_ASSERT(get(groot, v) == 10);
        BOOST_ASSERT(get(gsub, v) == 10);
        BOOST_ASSERT(get(map, v) == 10);

        typedef local_property< vertex_name_t > LocalProp;
        typedef property_map< Subgraph, LocalProp >::type LocalVertMap;
        LocalVertMap lroot = get(local(vertex_name), g); // Actually global!
        LocalVertMap lsub = get(local(vertex_name), sg);
        BOOST_ASSERT(get(lroot, v) == 10); // Recall it's 10 from above!
        BOOST_ASSERT(get(lsub, v) == 0);
        put(lsub, v, 5);
        BOOST_ASSERT(get(lsub, v) == 5);
        BOOST_ASSERT(get(lroot, v) == 10); // Don't change the root prop
        BOOST_ASSERT(get(map, v) == 10); // Don't change the root prop

        //         typedef detail::subgraph_local_pmap::bind_<LocalProp,
        //         Subgraph, void> PM; std::cout << typestr<PM::TagType>() <<
        //         "\n"; std::cout << typestr<PM::PMap>() << "\n";
    }
};

struct TestBundles
{
    struct Node
    {
        Node() : value(-1) {}
        int value;
    };
    struct Arc
    {
        Arc() : value(-1) {}
        int value;
    };
    typedef property< edge_index_t, std::size_t, Arc > EdgeProp;

    typedef adjacency_list< vecS, vecS, bidirectionalS, Node, EdgeProp > Graph;

    typedef subgraph< Graph > Subgraph;
    typedef graph_traits< Subgraph >::vertex_descriptor Vertex;
    typedef graph_traits< Subgraph >::edge_descriptor Edge;
    typedef graph_traits< Subgraph >::vertex_iterator VertexIter;
    typedef std::pair< VertexIter, VertexIter > VertexRange;

    static void run()
    {
        // Create a graph with some vertices.
        Subgraph g(5);
        VertexRange r = vertices(g);

        // Create a child subgraph and add some vertices.
        Subgraph& sg = g.create_subgraph();
        Vertex v = add_vertex(*r.first, sg);

        sg[v].value = 1;
        BOOST_ASSERT(sg[v].value == 1);
        BOOST_ASSERT(sg[global(v)].value == 1);
        BOOST_ASSERT(sg[local(v)].value == -1);

        sg[local(v)].value = 5;
        BOOST_ASSERT(sg[local(v)].value == 5);
        BOOST_ASSERT(sg[global(v)].value == 1);
        BOOST_ASSERT(sg[v].value == 1);

        typedef property_map< Subgraph, local_property< int Node::* > >::type
            LocalVertMap;
        LocalVertMap lvm = get(local(&Node::value), sg);
        BOOST_ASSERT(get(lvm, v) == 5);

        typedef property_map< Subgraph, global_property< int Node::* > >::type
            GlobalVertMap;
        GlobalVertMap gvm = get(global(&Node::value), sg);
        BOOST_ASSERT(get(gvm, v) == 1);
    }
};

int main(int argc, char* argv[])
{
    TestProps::run();
    TestBundles::run();

    return 0;
}