15 #ifndef PAAL_FILL_KNAPSACK_DYNAMIC_TABLE_HPP
16 #define PAAL_FILL_KNAPSACK_DYNAMIC_TABLE_HPP
46 template <
typename ValueIterator,
typename Objects,
typename ObjectSizeFunctor,
47 typename Combine,
typename Compare,
typename Init,
48 typename GetPositionRange>
49 detail::FunctorOnRangePValue<ObjectSizeFunctor, Objects>
51 Objects &&objects, ObjectSizeFunctor size,
52 Combine combine, Compare compare, Init init,
53 GetPositionRange get_range) {
54 using Size = detail::FunctorOnRangePValue<ObjectSizeFunctor, Objects>;
56 Size maxSize = std::distance(valuesBegin, valuesEnd);
58 std::fill(valuesBegin + 1, valuesEnd, boost::none);
61 auto posRange = get_range(0, maxSize);
63 auto objIter = std::begin(objects);
64 auto oEnd = std::end(objects);
65 for (; objIter != oEnd; ++objIter) {
66 auto &&obj = *objIter;
67 auto objSize = size(obj);
69 for (
auto pos : posRange) {
70 auto stat = *(valuesBegin + pos);
72 if (stat != boost::none) {
73 Size newPos = pos + objSize;
74 auto &newStat = *(valuesBegin + newPos);
76 if (newPos < maxSize) {
77 auto newValue = combine(stat, objIter);
79 if (newStat == boost::none || compare(newStat, newValue)) {
91 #endif // PAAL_FILL_KNAPSACK_DYNAMIC_TABLE_HPP
detail::FunctorOnRangePValue< ObjectSizeFunctor, Objects > fill_knapsack_dynamic_table(ValueIterator valuesBegin, ValueIterator valuesEnd, Objects &&objects, ObjectSizeFunctor size, Combine combine, Compare compare, Init init, GetPositionRange get_range)
Computes dynamic algorithm table (valuesBegin, valuesEnd) The values collection has element type Valu...