15 #ifndef PAAL_GET_BOUND_HPP
16 #define PAAL_GET_BOUND_HPP
22 #include <boost/function_output_iterator.hpp>
27 template <
typename SizeType,
typename ValueType>
28 using GetIntegralTag =
typename std::conditional<
29 std::is_integral<SizeType>::value && std::is_integral<ValueType>::value,
30 integral_value_and_size_tag,
31 typename std::conditional<
32 std::is_integral<SizeType>::value, integral_size_tag,
33 typename std::conditional<
34 std::is_integral<ValueType>::value, integral_value_tag,
35 non_integral_value_and_size_tag>::type>::type>::type;
37 template <
typename SizeType>
38 using Getarithmetic_size_tag =
typename std::conditional<
39 std::is_arithmetic<SizeType>::value, arithmetic_size_tag,
40 Nonarithmetic_size_tag>::type;
52 template <
typename KnapsackData >
54 using Size =
typename KnapsackData::size;
55 using ObjectRef =
typename KnapsackData::object_ref;
56 auto density = knap_data.get_density();
60 auto not_zero_sizel = [=](ObjectRef obj) {
return knap_data.get_size(obj) > Size{};};
64 auto not_zeros = knap_data.get_objects() | boost::adaptors::filtered(not_zero_size);
65 auto zeros = knap_data.get_objects() | boost::adaptors::filtered(zeroSize );
68 return knap_data.get_capacity() * maxElement +
sum_functor(zeros, knap_data.get_value());
72 template <
typename KnapsackData,
74 typename KnapsackData::value get_value_bound(
75 KnapsackData knap_data,
76 Nonarithmetic_size_tag, Is_0_1_Tag, upper_tag) {
81 template <
typename KnapsackData,
typename Is_0_1_Tag>
82 typename KnapsackData::value get_value_bound(
83 KnapsackData knap_data,
84 arithmetic_size_tag, Is_0_1_Tag is_0_1_Tag, upper_tag) {
85 return std::min(2 * get_value_bound(knap_data, is_0_1_Tag, lower_tag{}),
90 template <
typename KnapsackData,
typename Is_0_1_Tag>
91 typename KnapsackData::value get_value_bound(KnapsackData knap_data,
92 Nonarithmetic_size_tag, Is_0_1_Tag, lower_tag) {
98 template <
typename KnapsackData,
typename Is_0_1_Tag>
99 typename KnapsackData::value get_value_bound(KnapsackData knap_data,
100 arithmetic_size_tag, Is_0_1_Tag is_0_1_Tag, lower_tag) {
102 return knapsack_general_two_app(detail::make_knapsack_data(knap_data.get_objects(),
103 knap_data.get_capacity(), knap_data.get_size(), knap_data.get_value(), out), is_0_1_Tag).first;
107 template <
typename KnapsackData,
typename Is_0_1_Tag,
typename BoundType>
108 typename KnapsackData::value get_value_bound(KnapsackData knap_data,
109 Is_0_1_Tag is_0_1_tag, BoundType bound_type_tag) {
110 return get_value_bound(std::move(knap_data),
111 Getarithmetic_size_tag<typename KnapsackData::size>{},
112 is_0_1_tag, bound_type_tag);
117 #endif // PAAL_GET_BOUND_HPP
auto max_element_functor(Range &&range, Functor f)
combination of boost::max_element and boost::adaptors::transformed
auto make_assignable_functor(Functor &f)
make function for assignable_functor
KnapsackData::value get_density_based_value_upper_bound(KnapsackData knap_data)
upper bound is computed as biggest density times capacity + values for all elements with size 0...
auto make_not_functor(Functor functor)
make for Not
density functor, for given value and size
auto sum_functor(const Range &rng, Functor f)
sum of functor values over the range elements