All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
knapsack_0_1_on_size_fptas_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  using Objects = std::vector<std::pair<int, int>>;
24  Objects objects{ { 1, 3 }, { 2, 2 }, { 3, 65 }, { 1, 1 }, { 2, 2 },
25  { 4, 3 }, { 1, 1 }, { 10, 23 } };
26  const int capacity = 6;
27  auto size = [](std::pair<int, int> object) { return object.first; }
28  ;
29  auto value = [](std::pair<int, int> object) { return object.second; }
30  ;
31 
32  Objects result;
33  std::cout << "Knapsack unbounded FPTAS on size" << std::endl;
34 
35  double epsilon = 1. / 4.;
36  auto maxValue = paal::knapsack_0_1_on_size_fptas(
37  epsilon, objects, capacity, std::back_inserter(result), size, value);
38 
39  std::cout << "Max value " << maxValue.first << ", Total size "
40  << maxValue.second << std::endl;
41  for (auto o : result) {
42  std::cout << "{ size = " << o.first << ", value = " << o.second << "} ";
43  }
44  std::cout << std::endl;
45 
46 
47  return 0;
48 }
int main()
[Knapsack Example]