Chris@16: // Copyright 2004 The Trustees of Indiana University. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // Authors: Douglas Gregor Chris@16: // Andrew Lumsdaine Chris@16: Chris@16: #ifndef BOOST_GRAPH_PARALLEL_PROPERTIES_HPP Chris@16: #define BOOST_GRAPH_PARALLEL_PROPERTIES_HPP Chris@16: Chris@16: #ifndef BOOST_GRAPH_USE_MPI Chris@16: #error "Parallel BGL files should not be included unless has been included" Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: /*************************************************************************** Chris@16: * Property map reduction operations Chris@16: ***************************************************************************/ Chris@16: /** Chris@16: * Metafunction that produces a reduction operation for the given Chris@16: * property. The default behavior merely forwards to @ref Chris@16: * basic_reduce, but it is expected that this class template will be Chris@16: * specified for important properties. Chris@16: */ Chris@16: template Chris@16: struct property_reduce Chris@16: { Chris@16: template Chris@16: class apply : public parallel::basic_reduce {}; Chris@16: }; Chris@16: Chris@16: /** Chris@16: * Reduction of vertex colors can only darken, not lighten, the Chris@16: * color. Black cannot turn black, grey can only turn black, and Chris@16: * white can be changed to either color. The default color is white. Chris@16: */ Chris@16: template<> Chris@16: struct property_reduce Chris@16: { Chris@16: template Chris@16: class apply Chris@16: { Chris@16: typedef color_traits traits; Chris@16: Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT(bool, non_default_resolver = true); Chris@16: Chris@16: template Chris@16: Color operator()(const Key&) const { return traits::white(); } Chris@16: Chris@16: template Chris@16: Color operator()(const Key&, Color local, Color remote) const { Chris@16: if (local == traits::white()) return remote; Chris@16: else if (remote == traits::black()) return remote; Chris@16: else return local; Chris@16: } Chris@16: }; Chris@16: }; Chris@16: Chris@16: /** Chris@16: * Reduction of a distance always takes the shorter distance. The Chris@16: * default distance value is the maximum value for the data type. Chris@16: */ Chris@16: template<> Chris@16: struct property_reduce Chris@16: { Chris@16: template Chris@16: class apply Chris@16: { Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT(bool, non_default_resolver = true); Chris@16: Chris@16: template Chris@16: T operator()(const Key&) const { return (std::numeric_limits::max)(); } Chris@16: Chris@16: template Chris@16: T operator()(const Key&, T x, T y) const { return x < y? x : y; } Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct property_reduce Chris@16: { Chris@16: template Chris@16: class apply Chris@16: { Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT(bool, non_default_resolver = true); Chris@16: Chris@16: T operator()(T key) const { return key; } Chris@16: T operator()(T key, T, T y) const { return y; } Chris@16: }; Chris@16: }; Chris@16: Chris@16: template Chris@16: inline void set_property_map_role(Property p, PropertyMap pm) Chris@16: { Chris@16: typedef typename property_traits::value_type value_type; Chris@16: typedef property_reduce property_red; Chris@16: typedef typename property_red::template apply reduce; Chris@16: Chris@16: pm.set_reduce(reduce()); Chris@16: } Chris@16: Chris@16: } // end namespace boost Chris@16: #endif // BOOST_GRAPH_PARALLEL_PROPERTIES_HPP