All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
knapsack_0_1_two_app_example.cpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
18 
19 #include <vector>
20 #include <iostream>
21 
22 int main() {
23 
24  const int capacity = 6;
25  using Objects = std::vector<std::pair<int, int>>;
26  Objects objects{ { 1, 3 }, { 2, 2 }, { 3, 65 }, { 1, 1 }, { 2, 2 },
27  { 4, 3 }, { 1, 1 }, { 10, 23 } };
28  auto size = [](std::pair<int, int> object) { return object.first; }
29  ;
30  auto value = [](std::pair<int, int> object) { return object.second; }
31  ;
32 
33  Objects result;
34  std::cout << "Knapsack 0 / 1" << std::endl;
35  auto maxValue = paal::knapsack_0_1_two_app(
36  objects, capacity, std::back_inserter(result), value, size);
37 
38  std::cout << "Max value " << maxValue.first << ", Total size "
39  << maxValue.second << std::endl;
40  for (auto o : result) {
41  std::cout << "{ size = " << o.first << ", value = " << o.second << "} ";
42  }
43  std::cout << std::endl;
44 
45  return 0;
46 }
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
int main()
[Knapsack Example]