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