15 #ifndef PAAL_KNAPSACK_UNBOUNDED_TWO_APP_HPP
16 #define PAAL_KNAPSACK_UNBOUNDED_TWO_APP_HPP
22 #include <boost/iterator/counting_iterator.hpp>
23 #include <boost/iterator/filter_iterator.hpp>
25 #include <type_traits>
31 template <
typename KnapsackData,
32 typename ObjectIter =
typename KnapsackData::object_iter,
33 typename Size =
typename KnapsackData::size,
34 typename Value =
typename KnapsackData::value>
35 std::tuple<Value, Size,
36 std::pair<ObjectIter, unsigned>>
37 get_greedy_fill(KnapsackData knap_data, unbounded_tag) {
39 auto density = knap_data.get_density();
41 knap_data.get_objects(), density).base();
43 unsigned nr = knap_data.get_capacity() / knap_data.get_size(*most_dense_iter);
44 Value value_sum = Value(nr) * knap_data.get_value(*most_dense_iter);
45 Size size_sum = Size (nr) * knap_data.get_size (*most_dense_iter);
46 return std::make_tuple(value_sum, size_sum,
47 std::make_pair(most_dense_iter, nr));
50 template <
typename ObjectsIterAndNr,
typename OutputIter>
51 void greedy_to_output(ObjectsIterAndNr most_dense_iter_and_nr, OutputIter & out,
53 auto nr = most_dense_iter_and_nr.second;
54 auto most_dense_iter = most_dense_iter_and_nr.first;
55 for (
unsigned i = 0; i < nr; ++i) {
56 *out = *most_dense_iter;
64 template <
typename OutputIterator,
typename Objects,
65 typename ObjectSizeFunctor,
typename ObjectValueFunctor,
67 typename std::enable_if<!detail::is_range_const<Objects>::value>::type * =
nullptr>
69 typename detail::knapsack_base<Objects, ObjectSizeFunctor,
70 ObjectValueFunctor>::return_type
73 typename detail::FunctorOnRangePValue<ObjectSizeFunctor, Objects> capacity,
74 OutputIterator out, ObjectValueFunctor value, ObjectSizeFunctor size) {
75 return detail::knapsack_general_two_app(
76 detail::make_knapsack_data(std::forward<Objects>(objects), capacity, size, value, out),
80 #endif // PAAL_KNAPSACK_UNBOUNDED_TWO_APP_HPP
auto max_element_functor(Range &&range, Functor f)
combination of boost::max_element and boost::adaptors::transformed
detail::knapsack_base< Objects, ObjectSizeFunctor, ObjectValueFunctor >::return_type knapsack_unbounded_two_app(Objects &&objects, typename detail::FunctorOnRangePValue< ObjectSizeFunctor, Objects > capacity, OutputIterator out, ObjectValueFunctor value, ObjectSizeFunctor size)
detail