15 #ifndef PAAL_KNAPSACK_0_1_TWO_APP_HPP
16 #define PAAL_KNAPSACK_0_1_TWO_APP_HPP
23 #include <boost/iterator/counting_iterator.hpp>
24 #include <boost/iterator/filter_iterator.hpp>
25 #include <boost/range/algorithm/find_if.hpp>
26 #include <boost/range/algorithm/sort.hpp>
28 #include <type_traits>
34 template <
typename KnapsackData,
35 typename ObjectIter =
typename KnapsackData::object_iter,
36 typename ObjectRef =
typename KnapsackData::object_ref,
37 typename Size =
typename KnapsackData::size,
38 typename Value =
typename KnapsackData::value>
39 std::tuple<Value, Size, boost::iterator_range<ObjectIter>>
40 get_greedy_fill(KnapsackData knap_data, zero_one_tag) {
42 auto density = knap_data.get_density();
45 auto &objects = knap_data.get_objects();
48 boost::sort(objects, compare);
52 auto range = boost::find_if<boost::return_begin_found>(
53 objects, [ =, &sizeSum, &valueSum](ObjectRef obj) {
54 auto newSize = sizeSum + knap_data.get_size(obj);
55 if (newSize > knap_data.get_capacity()) {
59 valueSum += knap_data.get_value(obj);
62 return std::make_tuple(valueSum, sizeSum, range);
65 template <
typename ObjectsRange,
typename OutputIter>
66 void greedy_to_output(ObjectsRange range, OutputIter & out, zero_one_tag) {
67 for (
auto obj : range) {
76 template <
typename OutputIterator,
typename Objects,
typename ObjectSizeFunctor,
77 typename ObjectValueFunctor,
79 typename std::enable_if<
80 !detail::is_range_const<Objects>::value>::type * =
nullptr>
81 typename detail::knapsack_base<Objects, ObjectSizeFunctor,
82 ObjectValueFunctor>::return_type
85 typename detail::FunctorOnRangePValue<ObjectSizeFunctor, Objects> capacity,
86 OutputIterator out, ObjectValueFunctor value, ObjectSizeFunctor size) {
87 return detail::knapsack_general_two_app(
88 detail::make_knapsack_data(std::forward<Objects>(objects), capacity,
93 #endif // PAAL_KNAPSACK_0_1_TWO_APP_HPP
auto make_functor_to_comparator(Functor functor, Compare compare=Compare())
make for functor to comparator
This file contains set of simple useful functors or functor adapters.
detail::knapsack_base< Objects, ObjectSizeFunctor, ObjectValueFunctor >::return_type knapsack_0_1_two_app(Objects &&objects, typename detail::FunctorOnRangePValue< ObjectSizeFunctor, Objects > capacity, OutputIterator out, ObjectValueFunctor value, ObjectSizeFunctor size)
detail