All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
fl_algo.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_FL_ALGO_HPP
16 #define PAAL_FL_ALGO_HPP
17 
20 #include "paal/utils/functors.hpp"
21 
22 
23 namespace paal {
24 namespace simple_algo {
25 
38 template <typename Metric, typename FCosts, typename FLSolution>
39 typename data_structures::metric_traits<Metric>::DistanceType
40 get_cfl_cost(const Metric &m, const FCosts &fcosts, const FLSolution &fls) {
41  auto const &ch = fls.get_chosen_facilities();
42 
43  typedef data_structures::metric_traits<Metric> MT;
44  typedef typename MT::DistanceType Dist;
45 
46  //TODO use sum_functor when appears
47  Dist d = accumulate_functor(ch, Dist(0), fcosts);
48 
49  for (auto && f : ch) {
50  for (auto && v : fls.get_clients_for_facility(f)) {
51  d += m(v.first, f) * v.second;
52  }
53  }
54 
55  return d;
56 }
57 
70 template <typename Metric, typename FCosts, typename FLSolution>
71 typename data_structures::metric_traits<Metric>::DistanceType
72 get_fl_cost(const Metric &m, const FCosts &fcosts, const FLSolution &fls) {
73  auto const &ch = fls.get_chosen_facilities();
74 
75  typedef data_structures::metric_traits<Metric> MT;
76  typedef typename MT::DistanceType Dist;
77 
78  //TODO use sum_functor when appears
79  Dist d = accumulate_functor(ch, Dist(0), fcosts);
80 
81  for (auto && f : ch) {
82  for (auto && v : fls.get_clients_for_facility(f)) {
83  d += m(v, f);
84  }
85  }
86 
87  return d;
88 }
89 
100 template <typename Metric, typename FLSolution>
101 typename data_structures::metric_traits<Metric>::DistanceType
102 get_km_cost(const Metric &m, const FLSolution &fls) {
103  utils::return_zero_functor m_zero_func;
104  return paal::simple_algo::get_fl_cost(std::move(m), m_zero_func,
105  std::move(fls));
106 }
107 
108 }
109 }
110 #endif // PAAL_FL_ALGO_HPP
This file contains set of simple useful functors or functor adapters.
T accumulate_functor(const Range &rng, T init, Functor f, BinaryOperation bin_op=BinaryOperation{})
combination of boost::accumulate and boost::adaptors::transformed