All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
steiner_utils.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Maciej Andrejczuk
3 // 2014 Piotr Wygocki
4 //
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 //=======================================================================
16 #ifndef PAAL_STEINER_UTILS_HPP
17 #define PAAL_STEINER_UTILS_HPP
18 
19 #define BOOST_RESULT_OF_USE_DECLTYPE
20 
23 #include "paal/utils/irange.hpp"
24 
25 #include <boost/graph/prim_minimum_spanning_tree.hpp>
26 #include <boost/range/join.hpp>
27 
28 namespace paal {
29 namespace ir {
30 
35  public:
39  template <typename Metric, typename Terminals, typename Result>
41  count_cost(const Result& steiner_vertices, const Terminals& terminals, const Metric& cost_map) {
42  using Vertex = typename data_structures::metric_traits<Metric>::VertexType;
44 
45  auto all_elements = boost::range::join(terminals, steiner_vertices);
48  all_elements, idx);
49  std::vector<std::size_t> pm(all_elements.size());
50  boost::prim_minimum_spanning_tree(g, &pm[0]);
51  auto idx_m = paal::data_structures::make_metric_on_idx(cost_map, idx);
52 
53  Dist cost{};
54  for (auto i : irange(pm.size())) {
55  cost += idx_m(i, pm[i]);
56  }
57  return cost;
58  }
59 };
60 
61 } // ir
62 } // paal
63 
64 #endif // PAAL_STEINER_UTILS_HPP
adjacency_matrix< Metric >::type metric_to_bgl_with_index(const Metric &m, Vertices &&vertices, bimap< typename boost::range_value< Vertices >::type > &idx)
produces graph from metric with index
metric_on_idx< Metric, Bimap, Strategy > make_metric_on_idx(Metric &&m, Bimap &&b)
make for metric_on_idx
static data_structures::metric_traits< Metric >::DistanceType count_cost(const Result &steiner_vertices, const Terminals &terminals, const Metric &cost_map)
auto irange(T begin, T end)
irange
Definition: irange.hpp:22
Terminals
enum indicates if given color represents terminal or NONTERMINAL.
puretype(std::declval< Metric >()(std::declval< VertexType >(), std::declval< VertexType >())) DistanceType
Distance type.