You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

2 months ago
  1. /* TODD, a class of hard instances of zero-one knapsack problems */
  2. /* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
  3. /* Chvatal describes a class of instances of zero-one knapsack problems
  4. due to Todd. He shows that a wide class of algorithms - including all
  5. based on branch and bound or dynamic programming - find it difficult
  6. to solve problems in the Todd class. More exactly, the time required
  7. by these algorithms to solve instances of problems that belong to the
  8. Todd class grows as an exponential function of the problem size.
  9. Reference:
  10. Chvatal V. (1980), Hard knapsack problems, Op. Res. 28, 1402-1411. */
  11. param n > 0 integer;
  12. param log2_n := log(n) / log(2);
  13. param k := floor(log2_n);
  14. param a{j in 1..n} := 2 ** (k + n + 1) + 2 ** (k + n + 1 - j) + 1;
  15. param b := 0.5 * floor(sum{j in 1..n} a[j]);
  16. var x{1..n} binary;
  17. maximize obj: sum{j in 1..n} a[j] * x[j];
  18. s.t. cap: sum{j in 1..n} a[j] * x[j] <= b;
  19. data;
  20. param n := 15;
  21. /* change this parameter to choose a particular instance */
  22. end;