Chris@16
|
1 //=======================================================================
|
Chris@16
|
2 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
|
Chris@16
|
3 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
6 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //=======================================================================
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_GRAPH_PROPERTIES_HPP
|
Chris@16
|
11 #define BOOST_GRAPH_PROPERTIES_HPP
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/config.hpp>
|
Chris@16
|
14 #include <boost/assert.hpp>
|
Chris@16
|
15 #include <boost/pending/property.hpp>
|
Chris@16
|
16 #include <boost/detail/workaround.hpp>
|
Chris@16
|
17
|
Chris@16
|
18 // Include the property map library and extensions in the BGL.
|
Chris@16
|
19 #include <boost/property_map/property_map.hpp>
|
Chris@16
|
20 #include <boost/graph/property_maps/constant_property_map.hpp>
|
Chris@16
|
21 #include <boost/graph/property_maps/null_property_map.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/graph/graph_traits.hpp>
|
Chris@16
|
24 #include <boost/type_traits.hpp>
|
Chris@16
|
25 #include <boost/limits.hpp>
|
Chris@16
|
26 #include <boost/mpl/and.hpp>
|
Chris@16
|
27 #include <boost/mpl/not.hpp>
|
Chris@16
|
28 #include <boost/mpl/if.hpp>
|
Chris@16
|
29
|
Chris@16
|
30 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
Chris@16
|
31 // Stay out of the way of the concept checking class
|
Chris@16
|
32 # define Graph Graph_
|
Chris@16
|
33 # define RandomAccessContainer RandomAccessContainer_
|
Chris@16
|
34 #endif
|
Chris@16
|
35
|
Chris@16
|
36 namespace boost {
|
Chris@16
|
37
|
Chris@16
|
38 enum default_color_type { white_color, gray_color, green_color, red_color, black_color };
|
Chris@16
|
39
|
Chris@16
|
40 template <class ColorValue>
|
Chris@16
|
41 struct color_traits {
|
Chris@16
|
42 static default_color_type white() { return white_color; }
|
Chris@16
|
43 static default_color_type gray() { return gray_color; }
|
Chris@16
|
44 static default_color_type green() { return green_color; }
|
Chris@16
|
45 static default_color_type red() { return red_color; }
|
Chris@16
|
46 static default_color_type black() { return black_color; }
|
Chris@16
|
47 };
|
Chris@16
|
48
|
Chris@16
|
49 // These functions are now obsolete, replaced by color_traits.
|
Chris@16
|
50 inline default_color_type white(default_color_type) { return white_color; }
|
Chris@16
|
51 inline default_color_type gray(default_color_type) { return gray_color; }
|
Chris@16
|
52 inline default_color_type green(default_color_type) { return green_color; }
|
Chris@16
|
53 inline default_color_type red(default_color_type) { return red_color; }
|
Chris@16
|
54 inline default_color_type black(default_color_type) { return black_color; }
|
Chris@16
|
55
|
Chris@16
|
56 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
Chris@16
|
57 template <>
|
Chris@16
|
58 struct property_traits<default_color_type*> {
|
Chris@16
|
59 typedef default_color_type value_type;
|
Chris@16
|
60 typedef std::ptrdiff_t key_type;
|
Chris@16
|
61 typedef default_color_type& reference;
|
Chris@16
|
62 typedef lvalue_property_map_tag category;
|
Chris@16
|
63 };
|
Chris@16
|
64 // get/put already defined for T*
|
Chris@16
|
65 #endif
|
Chris@16
|
66
|
Chris@16
|
67 struct graph_property_tag { };
|
Chris@16
|
68 struct vertex_property_tag { };
|
Chris@16
|
69 struct edge_property_tag { };
|
Chris@16
|
70
|
Chris@16
|
71 // See examples/edge_property.cpp for how to use this.
|
Chris@16
|
72 #define BOOST_INSTALL_PROPERTY(KIND, NAME) \
|
Chris@16
|
73 template <> struct property_kind<KIND##_##NAME##_t> { \
|
Chris@16
|
74 typedef KIND##_property_tag type; \
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 #define BOOST_DEF_PROPERTY(KIND, NAME) \
|
Chris@16
|
78 enum KIND##_##NAME##_t { KIND##_##NAME }; \
|
Chris@16
|
79 BOOST_INSTALL_PROPERTY(KIND, NAME)
|
Chris@16
|
80
|
Chris@16
|
81 // These three are defined in boost/pending/property.hpp
|
Chris@16
|
82 BOOST_INSTALL_PROPERTY(vertex, all);
|
Chris@16
|
83 BOOST_INSTALL_PROPERTY(edge, all);
|
Chris@16
|
84 BOOST_INSTALL_PROPERTY(graph, all);
|
Chris@16
|
85 BOOST_DEF_PROPERTY(vertex, index);
|
Chris@16
|
86 BOOST_DEF_PROPERTY(vertex, index1);
|
Chris@16
|
87 BOOST_DEF_PROPERTY(vertex, index2);
|
Chris@16
|
88 BOOST_DEF_PROPERTY(vertex, root);
|
Chris@16
|
89 BOOST_DEF_PROPERTY(edge, index);
|
Chris@16
|
90 BOOST_DEF_PROPERTY(edge, name);
|
Chris@16
|
91 BOOST_DEF_PROPERTY(edge, weight);
|
Chris@16
|
92 BOOST_DEF_PROPERTY(edge, weight2);
|
Chris@16
|
93 BOOST_DEF_PROPERTY(edge, color);
|
Chris@16
|
94 BOOST_DEF_PROPERTY(vertex, name);
|
Chris@16
|
95 BOOST_DEF_PROPERTY(graph, name);
|
Chris@16
|
96 BOOST_DEF_PROPERTY(vertex, distance);
|
Chris@16
|
97 BOOST_DEF_PROPERTY(vertex, distance2);
|
Chris@16
|
98 BOOST_DEF_PROPERTY(vertex, color);
|
Chris@16
|
99 BOOST_DEF_PROPERTY(vertex, degree);
|
Chris@16
|
100 BOOST_DEF_PROPERTY(vertex, in_degree);
|
Chris@16
|
101 BOOST_DEF_PROPERTY(vertex, out_degree);
|
Chris@16
|
102 BOOST_DEF_PROPERTY(vertex, current_degree);
|
Chris@16
|
103 BOOST_DEF_PROPERTY(vertex, priority);
|
Chris@16
|
104 BOOST_DEF_PROPERTY(vertex, discover_time);
|
Chris@16
|
105 BOOST_DEF_PROPERTY(vertex, finish_time);
|
Chris@16
|
106 BOOST_DEF_PROPERTY(vertex, predecessor);
|
Chris@16
|
107 BOOST_DEF_PROPERTY(vertex, rank);
|
Chris@16
|
108 BOOST_DEF_PROPERTY(vertex, centrality);
|
Chris@16
|
109 BOOST_DEF_PROPERTY(vertex, lowpoint);
|
Chris@16
|
110 BOOST_DEF_PROPERTY(vertex, potential);
|
Chris@16
|
111 BOOST_DEF_PROPERTY(vertex, update);
|
Chris@16
|
112 BOOST_DEF_PROPERTY(vertex, underlying);
|
Chris@16
|
113 BOOST_DEF_PROPERTY(edge, reverse);
|
Chris@16
|
114 BOOST_DEF_PROPERTY(edge, capacity);
|
Chris@16
|
115 BOOST_DEF_PROPERTY(edge, flow);
|
Chris@16
|
116 BOOST_DEF_PROPERTY(edge, residual_capacity);
|
Chris@16
|
117 BOOST_DEF_PROPERTY(edge, centrality);
|
Chris@16
|
118 BOOST_DEF_PROPERTY(edge, discover_time);
|
Chris@16
|
119 BOOST_DEF_PROPERTY(edge, update);
|
Chris@16
|
120 BOOST_DEF_PROPERTY(edge, finished);
|
Chris@16
|
121 BOOST_DEF_PROPERTY(edge, underlying);
|
Chris@16
|
122 BOOST_DEF_PROPERTY(graph, visitor);
|
Chris@16
|
123
|
Chris@16
|
124 // These tags are used for property bundles
|
Chris@16
|
125 // These three are defined in boost/pending/property.hpp
|
Chris@16
|
126 BOOST_INSTALL_PROPERTY(graph, bundle);
|
Chris@16
|
127 BOOST_INSTALL_PROPERTY(vertex, bundle);
|
Chris@16
|
128 BOOST_INSTALL_PROPERTY(edge, bundle);
|
Chris@16
|
129
|
Chris@16
|
130 // These tags are used to denote the owners and local descriptors
|
Chris@16
|
131 // for the vertices and edges of a distributed graph.
|
Chris@16
|
132 BOOST_DEF_PROPERTY(vertex, global);
|
Chris@16
|
133 BOOST_DEF_PROPERTY(vertex, owner);
|
Chris@16
|
134 BOOST_DEF_PROPERTY(vertex, local);
|
Chris@16
|
135 BOOST_DEF_PROPERTY(edge, global);
|
Chris@16
|
136 BOOST_DEF_PROPERTY(edge, owner);
|
Chris@16
|
137 BOOST_DEF_PROPERTY(edge, local);
|
Chris@16
|
138 BOOST_DEF_PROPERTY(vertex, local_index);
|
Chris@16
|
139 BOOST_DEF_PROPERTY(edge, local_index);
|
Chris@16
|
140
|
Chris@16
|
141 #undef BOOST_DEF_PROPERTY
|
Chris@16
|
142
|
Chris@16
|
143 namespace detail {
|
Chris@16
|
144
|
Chris@16
|
145 template <typename G, typename Tag>
|
Chris@16
|
146 struct property_kind_from_graph: property_kind<Tag> {};
|
Chris@16
|
147
|
Chris@16
|
148 #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
|
Chris@16
|
149 template <typename G, typename R, typename T>
|
Chris@16
|
150 struct property_kind_from_graph<G, R T::*> {
|
Chris@16
|
151 typedef typename boost::mpl::if_<
|
Chris@16
|
152 boost::is_base_of<T, typename vertex_bundle_type<G>::type>,
|
Chris@16
|
153 vertex_property_tag,
|
Chris@16
|
154 typename boost::mpl::if_<
|
Chris@16
|
155 boost::is_base_of<T, typename edge_bundle_type<G>::type>,
|
Chris@16
|
156 edge_property_tag,
|
Chris@16
|
157 typename boost::mpl::if_<
|
Chris@16
|
158 boost::is_base_of<T, typename graph_bundle_type<G>::type>,
|
Chris@16
|
159 graph_property_tag,
|
Chris@16
|
160 void>::type>::type>::type type;
|
Chris@16
|
161 };
|
Chris@16
|
162 #endif
|
Chris@16
|
163
|
Chris@16
|
164 struct dummy_edge_property_selector {
|
Chris@16
|
165 template <class Graph, class Property, class Tag>
|
Chris@16
|
166 struct bind_ {
|
Chris@16
|
167 typedef identity_property_map type;
|
Chris@16
|
168 typedef identity_property_map const_type;
|
Chris@16
|
169 };
|
Chris@16
|
170 };
|
Chris@16
|
171 struct dummy_vertex_property_selector {
|
Chris@16
|
172 template <class Graph, class Property, class Tag>
|
Chris@16
|
173 struct bind_ {
|
Chris@16
|
174 typedef identity_property_map type;
|
Chris@16
|
175 typedef identity_property_map const_type;
|
Chris@16
|
176 };
|
Chris@16
|
177 };
|
Chris@16
|
178
|
Chris@16
|
179 } // namespace detail
|
Chris@16
|
180
|
Chris@16
|
181 // Graph classes can either partially specialize property_map
|
Chris@16
|
182 // or they can specialize these two selector classes.
|
Chris@16
|
183 template <class GraphTag>
|
Chris@16
|
184 struct edge_property_selector {
|
Chris@16
|
185 typedef detail::dummy_edge_property_selector type;
|
Chris@16
|
186 };
|
Chris@16
|
187
|
Chris@16
|
188 template <class GraphTag>
|
Chris@16
|
189 struct vertex_property_selector {
|
Chris@16
|
190 typedef detail::dummy_vertex_property_selector type;
|
Chris@16
|
191 };
|
Chris@16
|
192
|
Chris@16
|
193 namespace detail {
|
Chris@16
|
194
|
Chris@16
|
195 template <typename A> struct return_void {typedef void type;};
|
Chris@16
|
196
|
Chris@16
|
197 template <typename Graph, typename Enable = void>
|
Chris@16
|
198 struct graph_tag_or_void {
|
Chris@16
|
199 typedef void type;
|
Chris@16
|
200 };
|
Chris@16
|
201
|
Chris@16
|
202 template <typename Graph>
|
Chris@16
|
203 struct graph_tag_or_void<Graph, typename return_void<typename Graph::graph_tag>::type> {
|
Chris@16
|
204 typedef typename Graph::graph_tag type;
|
Chris@16
|
205 };
|
Chris@16
|
206
|
Chris@16
|
207 template <class Graph, class PropertyTag>
|
Chris@16
|
208 struct edge_property_map
|
Chris@16
|
209 : edge_property_selector<
|
Chris@16
|
210 typename graph_tag_or_void<Graph>::type
|
Chris@16
|
211 >::type::template bind_<
|
Chris@16
|
212 Graph,
|
Chris@16
|
213 typename edge_property_type<Graph>::type,
|
Chris@16
|
214 PropertyTag>
|
Chris@16
|
215 {};
|
Chris@16
|
216 template <class Graph, class PropertyTag>
|
Chris@16
|
217 struct vertex_property_map
|
Chris@16
|
218 : vertex_property_selector<
|
Chris@16
|
219 typename graph_tag_or_void<Graph>::type
|
Chris@16
|
220 >::type::template bind_<
|
Chris@16
|
221 Graph,
|
Chris@16
|
222 typename vertex_property_type<Graph>::type,
|
Chris@16
|
223 PropertyTag>
|
Chris@16
|
224 {};
|
Chris@16
|
225 } // namespace detail
|
Chris@16
|
226
|
Chris@16
|
227 template <class Graph, class Property, class Enable = void>
|
Chris@16
|
228 struct property_map:
|
Chris@16
|
229 mpl::if_<
|
Chris@16
|
230 is_same<typename detail::property_kind_from_graph<Graph, Property>::type, edge_property_tag>,
|
Chris@16
|
231 detail::edge_property_map<Graph, Property>,
|
Chris@16
|
232 detail::vertex_property_map<Graph, Property> >::type
|
Chris@16
|
233 {};
|
Chris@16
|
234
|
Chris@16
|
235 // shortcut for accessing the value type of the property map
|
Chris@16
|
236 template <class Graph, class Property>
|
Chris@16
|
237 class property_map_value {
|
Chris@16
|
238 typedef typename property_map<Graph, Property>::const_type PMap;
|
Chris@16
|
239 public:
|
Chris@16
|
240 typedef typename property_traits<PMap>::value_type type;
|
Chris@16
|
241 };
|
Chris@16
|
242
|
Chris@16
|
243 template <class Graph, class Property>
|
Chris@16
|
244 class graph_property {
|
Chris@16
|
245 public:
|
Chris@16
|
246 typedef typename property_value<
|
Chris@16
|
247 typename boost::graph_property_type<Graph>::type, Property
|
Chris@16
|
248 >::type type;
|
Chris@16
|
249 };
|
Chris@16
|
250
|
Chris@16
|
251 template <typename Graph> struct vertex_property: vertex_property_type<Graph> {};
|
Chris@16
|
252 template <typename Graph> struct edge_property: edge_property_type<Graph> {};
|
Chris@16
|
253
|
Chris@16
|
254 template <typename Graph>
|
Chris@16
|
255 class degree_property_map
|
Chris@16
|
256 : public put_get_helper<typename graph_traits<Graph>::degree_size_type,
|
Chris@16
|
257 degree_property_map<Graph> >
|
Chris@16
|
258 {
|
Chris@16
|
259 public:
|
Chris@16
|
260 typedef typename graph_traits<Graph>::vertex_descriptor key_type;
|
Chris@16
|
261 typedef typename graph_traits<Graph>::degree_size_type value_type;
|
Chris@16
|
262 typedef value_type reference;
|
Chris@16
|
263 typedef readable_property_map_tag category;
|
Chris@16
|
264 degree_property_map(const Graph& g) : m_g(g) { }
|
Chris@16
|
265 value_type operator[](const key_type& v) const {
|
Chris@16
|
266 return degree(v, m_g);
|
Chris@16
|
267 }
|
Chris@16
|
268 private:
|
Chris@16
|
269 const Graph& m_g;
|
Chris@16
|
270 };
|
Chris@16
|
271 template <typename Graph>
|
Chris@16
|
272 inline degree_property_map<Graph>
|
Chris@16
|
273 make_degree_map(const Graph& g) {
|
Chris@16
|
274 return degree_property_map<Graph>(g);
|
Chris@16
|
275 }
|
Chris@16
|
276
|
Chris@16
|
277 //========================================================================
|
Chris@16
|
278 // Iterator Property Map Generating Functions contributed by
|
Chris@16
|
279 // Kevin Vanhorn. (see also the property map generating functions
|
Chris@16
|
280 // in boost/property_map/property_map.hpp)
|
Chris@16
|
281
|
Chris@16
|
282 #if !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
Chris@16
|
283 // A helper function for creating a vertex property map out of a
|
Chris@16
|
284 // random access iterator and the internal vertex index map from a
|
Chris@16
|
285 // graph.
|
Chris@16
|
286 template <class PropertyGraph, class RandomAccessIterator>
|
Chris@16
|
287 inline
|
Chris@16
|
288 iterator_property_map<
|
Chris@16
|
289 RandomAccessIterator,
|
Chris@16
|
290 typename property_map<PropertyGraph, vertex_index_t>::type,
|
Chris@16
|
291 typename std::iterator_traits<RandomAccessIterator>::value_type,
|
Chris@16
|
292 typename std::iterator_traits<RandomAccessIterator>::reference
|
Chris@16
|
293 >
|
Chris@16
|
294 make_iterator_vertex_map(RandomAccessIterator iter, const PropertyGraph& g)
|
Chris@16
|
295 {
|
Chris@16
|
296 return make_iterator_property_map(iter, get(vertex_index, g));
|
Chris@16
|
297 }
|
Chris@16
|
298
|
Chris@16
|
299 // Use this next function when vertex_descriptor is known to be an
|
Chris@16
|
300 // integer type, with values ranging from 0 to num_vertices(g).
|
Chris@16
|
301 //
|
Chris@16
|
302 template <class RandomAccessIterator>
|
Chris@16
|
303 inline
|
Chris@16
|
304 iterator_property_map<
|
Chris@16
|
305 RandomAccessIterator,
|
Chris@16
|
306 identity_property_map,
|
Chris@16
|
307 typename std::iterator_traits<RandomAccessIterator>::value_type,
|
Chris@16
|
308 typename std::iterator_traits<RandomAccessIterator>::reference
|
Chris@16
|
309 >
|
Chris@16
|
310 make_iterator_vertex_map(RandomAccessIterator iter)
|
Chris@16
|
311 {
|
Chris@16
|
312 return make_iterator_property_map(iter, identity_property_map());
|
Chris@16
|
313 }
|
Chris@16
|
314 #endif
|
Chris@16
|
315
|
Chris@16
|
316 template <class PropertyGraph, class RandomAccessContainer>
|
Chris@16
|
317 inline
|
Chris@16
|
318 iterator_property_map<
|
Chris@16
|
319 typename RandomAccessContainer::iterator,
|
Chris@16
|
320 typename property_map<PropertyGraph, vertex_index_t>::type,
|
Chris@16
|
321 typename RandomAccessContainer::value_type,
|
Chris@16
|
322 typename RandomAccessContainer::reference
|
Chris@16
|
323 >
|
Chris@16
|
324 make_container_vertex_map(RandomAccessContainer& c, const PropertyGraph& g)
|
Chris@16
|
325 {
|
Chris@16
|
326 BOOST_ASSERT(c.size() >= num_vertices(g));
|
Chris@16
|
327 return make_iterator_vertex_map(c.begin(), g);
|
Chris@16
|
328 }
|
Chris@16
|
329
|
Chris@16
|
330 template <class RandomAccessContainer> inline
|
Chris@16
|
331 iterator_property_map<
|
Chris@16
|
332 typename RandomAccessContainer::iterator,
|
Chris@16
|
333 identity_property_map,
|
Chris@16
|
334 typename RandomAccessContainer::value_type,
|
Chris@16
|
335 typename RandomAccessContainer::reference
|
Chris@16
|
336 >
|
Chris@16
|
337 make_container_vertex_map(RandomAccessContainer& c)
|
Chris@16
|
338 {
|
Chris@16
|
339 return make_iterator_vertex_map(c.begin());
|
Chris@16
|
340 }
|
Chris@16
|
341
|
Chris@16
|
342 #if defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
Chris@16
|
343 # define BOOST_GRAPH_NO_BUNDLED_PROPERTIES
|
Chris@16
|
344 #endif
|
Chris@16
|
345
|
Chris@16
|
346 #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590)) && !defined (BOOST_GRAPH_NO_BUNDLED_PROPERTIES)
|
Chris@16
|
347 // This compiler cannot define a partial specialization based on a
|
Chris@16
|
348 // pointer-to-member type, as seen in boost/graph/subgraph.hpp line 985 (as of
|
Chris@16
|
349 // trunk r53912)
|
Chris@16
|
350 # define BOOST_GRAPH_NO_BUNDLED_PROPERTIES
|
Chris@16
|
351 #endif
|
Chris@16
|
352
|
Chris@16
|
353 // NOTE: These functions are declared, but never defined since they need to
|
Chris@16
|
354 // be overloaded by graph implementations. However, we need them to be
|
Chris@16
|
355 // declared for the functions below.
|
Chris@16
|
356 template<typename Graph, typename Tag>
|
Chris@16
|
357 typename graph_property<Graph, graph_bundle_t>::type&
|
Chris@16
|
358 get_property(Graph& g, Tag);
|
Chris@16
|
359
|
Chris@16
|
360 template<typename Graph, typename Tag>
|
Chris@16
|
361 typename graph_property<Graph, graph_bundle_t>::type const&
|
Chris@16
|
362 get_property(Graph const& g, Tag);
|
Chris@16
|
363
|
Chris@16
|
364 #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
|
Chris@16
|
365 // NOTE: This operation is a simple adaptor over the overloaded get_property
|
Chris@16
|
366 // operations.
|
Chris@16
|
367 template<typename Graph>
|
Chris@16
|
368 inline typename graph_property<Graph, graph_bundle_t>::type&
|
Chris@16
|
369 get_property(Graph& g) {
|
Chris@16
|
370 return get_property(g, graph_bundle);
|
Chris@16
|
371 }
|
Chris@16
|
372
|
Chris@16
|
373 template<typename Graph>
|
Chris@16
|
374 inline typename graph_property<Graph, graph_bundle_t>::type const&
|
Chris@16
|
375 get_property(const Graph& g) {
|
Chris@16
|
376 return get_property(g, graph_bundle);
|
Chris@16
|
377 }
|
Chris@16
|
378 #endif
|
Chris@16
|
379
|
Chris@16
|
380 } // namespace boost
|
Chris@16
|
381
|
Chris@16
|
382 #endif /* BOOST_GRAPH_PROPERTIES_HPP */
|