]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/test/rcsp_custom_vertex_id.cpp
1 //=======================================================================
2 // Copyright (c) 2013 Alberto Santini
3 // Author: Alberto Santini <alberto@santini.in>
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //=======================================================================
10 #include <boost/config.hpp>
13 // Without disabling this we get hard errors about initialialized pointers:
14 #pragma warning(disable:4703)
17 #include <boost/graph/graph_traits.hpp>
18 #include <boost/graph/adjacency_list.hpp>
19 #include <boost/graph/r_c_shortest_paths.hpp>
20 #include <boost/graph/iteration_macros.hpp>
26 using namespace boost
;
28 class VertexProperty
{
34 VertexProperty(const int property1
, const int property2
) : property1(property1
), property2(property2
) {}
42 EdgeProperty(const int cost
) : cost(cost
) {}
45 typedef adjacency_list
<listS
, listS
, bidirectionalS
, VertexProperty
, EdgeProperty
> Graph
;
46 typedef graph_traits
<Graph
>::vertex_descriptor Vertex
;
47 typedef graph_traits
<Graph
>::edge_descriptor Edge
;
52 ResourceCont(const int res
= 5) : res(res
) {}
53 bool operator==(const ResourceCont
& rc
) const { return (res
== rc
.res
); }
54 bool operator<(const ResourceCont
& rc
) const { return (res
> rc
.res
); }
59 bool operator()(const Graph
& g
, ResourceCont
& rc
, const ResourceCont
& old_rc
, Edge e
) const {
60 rc
.res
= old_rc
.res
- g
[e
].cost
;
67 bool operator()(const ResourceCont
& rc1
, const ResourceCont
& rc2
) const {
68 return (rc1
== rc2
|| rc1
< rc2
);
73 VertexProperty
vp1(1, 1);
74 VertexProperty
vp2(5, 9);
75 VertexProperty
vp3(4, 3);
81 Vertex v1
= add_vertex(g
); g
[v1
] = vp1
;
82 Vertex v2
= add_vertex(g
); g
[v2
] = vp2
;
83 Vertex v3
= add_vertex(g
); g
[v3
] = vp3
;
85 add_edge(v1
, v2
, e12
, g
);
86 add_edge(v2
, v3
, e23
, g
);
89 BGL_FORALL_VERTICES(v
, g
, Graph
) {
93 BGL_FORALL_EDGES(e
, g
, Graph
) {
97 typedef vector
<vector
<Edge
> > OptPath
;
98 typedef vector
<ResourceCont
> ParetoOpt
;
103 r_c_shortest_paths( g
,
104 get(&VertexProperty::id
, g
),
105 get(&EdgeProperty::id
, g
),
113 allocator
<r_c_shortest_paths_label
<Graph
, ResourceCont
> >(),
114 default_r_c_shortest_paths_visitor());