Chris@16
|
1 // Copyright 2004 The Trustees of Indiana University.
|
Chris@16
|
2
|
Chris@16
|
3 // Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 // Authors: Douglas Gregor
|
Chris@16
|
8 // Andrew Lumsdaine
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_GRAPH_PARALLEL_PROPERTIES_HPP
|
Chris@16
|
11 #define BOOST_GRAPH_PARALLEL_PROPERTIES_HPP
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_GRAPH_USE_MPI
|
Chris@16
|
14 #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
|
Chris@16
|
15 #endif
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/graph/properties.hpp>
|
Chris@16
|
18 #include <boost/property_map/parallel/distributed_property_map.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 namespace boost {
|
Chris@16
|
21 /***************************************************************************
|
Chris@16
|
22 * Property map reduction operations
|
Chris@16
|
23 ***************************************************************************/
|
Chris@16
|
24 /**
|
Chris@16
|
25 * Metafunction that produces a reduction operation for the given
|
Chris@16
|
26 * property. The default behavior merely forwards to @ref
|
Chris@16
|
27 * basic_reduce, but it is expected that this class template will be
|
Chris@16
|
28 * specified for important properties.
|
Chris@16
|
29 */
|
Chris@16
|
30 template<typename Property>
|
Chris@16
|
31 struct property_reduce
|
Chris@16
|
32 {
|
Chris@16
|
33 template<typename Value>
|
Chris@16
|
34 class apply : public parallel::basic_reduce<Value> {};
|
Chris@16
|
35 };
|
Chris@16
|
36
|
Chris@16
|
37 /**
|
Chris@16
|
38 * Reduction of vertex colors can only darken, not lighten, the
|
Chris@16
|
39 * color. Black cannot turn black, grey can only turn black, and
|
Chris@16
|
40 * white can be changed to either color. The default color is white.
|
Chris@16
|
41 */
|
Chris@16
|
42 template<>
|
Chris@16
|
43 struct property_reduce<vertex_color_t>
|
Chris@16
|
44 {
|
Chris@16
|
45 template<typename Color>
|
Chris@16
|
46 class apply
|
Chris@16
|
47 {
|
Chris@16
|
48 typedef color_traits<Color> traits;
|
Chris@16
|
49
|
Chris@16
|
50 public:
|
Chris@16
|
51 BOOST_STATIC_CONSTANT(bool, non_default_resolver = true);
|
Chris@16
|
52
|
Chris@16
|
53 template<typename Key>
|
Chris@16
|
54 Color operator()(const Key&) const { return traits::white(); }
|
Chris@16
|
55
|
Chris@16
|
56 template<typename Key>
|
Chris@16
|
57 Color operator()(const Key&, Color local, Color remote) const {
|
Chris@16
|
58 if (local == traits::white()) return remote;
|
Chris@16
|
59 else if (remote == traits::black()) return remote;
|
Chris@16
|
60 else return local;
|
Chris@16
|
61 }
|
Chris@16
|
62 };
|
Chris@16
|
63 };
|
Chris@16
|
64
|
Chris@16
|
65 /**
|
Chris@16
|
66 * Reduction of a distance always takes the shorter distance. The
|
Chris@16
|
67 * default distance value is the maximum value for the data type.
|
Chris@16
|
68 */
|
Chris@16
|
69 template<>
|
Chris@16
|
70 struct property_reduce<vertex_distance_t>
|
Chris@16
|
71 {
|
Chris@16
|
72 template<typename T>
|
Chris@16
|
73 class apply
|
Chris@16
|
74 {
|
Chris@16
|
75 public:
|
Chris@16
|
76 BOOST_STATIC_CONSTANT(bool, non_default_resolver = true);
|
Chris@16
|
77
|
Chris@16
|
78 template<typename Key>
|
Chris@16
|
79 T operator()(const Key&) const { return (std::numeric_limits<T>::max)(); }
|
Chris@16
|
80
|
Chris@16
|
81 template<typename Key>
|
Chris@16
|
82 T operator()(const Key&, T x, T y) const { return x < y? x : y; }
|
Chris@16
|
83 };
|
Chris@16
|
84 };
|
Chris@16
|
85
|
Chris@16
|
86 template<>
|
Chris@16
|
87 struct property_reduce<vertex_predecessor_t>
|
Chris@16
|
88 {
|
Chris@16
|
89 template<typename T>
|
Chris@16
|
90 class apply
|
Chris@16
|
91 {
|
Chris@16
|
92 public:
|
Chris@16
|
93 BOOST_STATIC_CONSTANT(bool, non_default_resolver = true);
|
Chris@16
|
94
|
Chris@16
|
95 T operator()(T key) const { return key; }
|
Chris@16
|
96 T operator()(T key, T, T y) const { return y; }
|
Chris@16
|
97 };
|
Chris@16
|
98 };
|
Chris@16
|
99
|
Chris@16
|
100 template<typename Property, typename PropertyMap>
|
Chris@16
|
101 inline void set_property_map_role(Property p, PropertyMap pm)
|
Chris@16
|
102 {
|
Chris@16
|
103 typedef typename property_traits<PropertyMap>::value_type value_type;
|
Chris@16
|
104 typedef property_reduce<Property> property_red;
|
Chris@16
|
105 typedef typename property_red::template apply<value_type> reduce;
|
Chris@16
|
106
|
Chris@16
|
107 pm.set_reduce(reduce());
|
Chris@16
|
108 }
|
Chris@16
|
109
|
Chris@16
|
110 } // end namespace boost
|
Chris@16
|
111 #endif // BOOST_GRAPH_PARALLEL_PROPERTIES_HPP
|