All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
set_cover.hpp
Go to the documentation of this file.
1 
8 #ifndef PAAL_SET_COVER_HPP
9 #define PAAL_SET_COVER_HPP
10 
13 #include "paal/utils/functors.hpp"
15 
16 #include <boost/function_output_iterator.hpp>
17 
18 #include <iterator>
19 #include <vector>
20 
21 namespace paal{
22 namespace greedy{
23 namespace detail{
24 template <typename SetRange,typename GetCostOfSet>
25 using set_range_cost_t = pure_result_of_t<
26  GetCostOfSet(typename boost::range_reference<SetRange>::type)>;
27 
28 }
29 
47 template<typename SetRange, class GetCostOfSet, class GetElementsOfSet, class OutputIterator,class GetElementIndex>
48 auto set_cover(SetRange && sets,
49  GetCostOfSet set_to_cost,
50  GetElementsOfSet set_to_elements,
51  OutputIterator result,
52  GetElementIndex get_el_index
53  ) {
54  using set_cost=typename detail::set_range_cost_t<SetRange,GetCostOfSet>;
55  //TODO use sum functor from r=Robert commit
56  auto cost_of_all_sets=accumulate_functor(sets, set_cost{}, set_to_cost);
57  set_cost cost_of_solution{};
59  set_to_cost,
60  set_to_elements,
61  boost::make_function_output_iterator([&](int set){
62  cost_of_solution += set_to_cost(set);
63  *result = set;
64  ++result;
65  }),
66  get_el_index,
67  cost_of_all_sets,
69  0
70  );
71  return cost_of_solution;
72 };
73 }
74 }
75 
76 #endif /* PAAL_SET_COVER_HPP */
auto budgeted_maximum_coverage(SetRange &&sets, GetCostOfSet set_to_cost, GetElementsOfSet set_to_elements, OutputIterator result, ElementIndex get_el_index, Budget budget, GetWeightOfElement element_to_weight=GetWeightOfElement(), const unsigned int initial_set_size=3)
detail
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
auto set_cover(SetRange &&sets, GetCostOfSet set_to_cost, GetElementsOfSet set_to_elements, OutputIterator result, GetElementIndex get_el_index)
detail
Definition: set_cover.hpp:48
typename std::decay< typename std::result_of< F >::type >::type pure_result_of_t
return pure type of function (decays const and reference)