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.

72 lines
2.2 KiB

2 months ago
  1. /* TRICK, A Transportation Design Problem */
  2. /* Translated from the Mosel modeling language to GNU MathProg by
  3. Andrew Makhorin <mao@gnu.org> */
  4. /* This example model is described in the article "Formulations and
  5. Reformulations in Integer Programming" by Michael Trick (it is
  6. publicly available at http://mat.gsia.cmu.edu/trick/formul04.pdf).
  7. This model demonstrates an amazing effect when including in the
  8. formulation an additional constraint, which is redundant even for
  9. LP relaxation, makes the model easy for solving with the B&B. */
  10. set TRUCKS := 1..10;
  11. set PACKAGES := 1..20;
  12. param capacity{TRUCKS};
  13. param size{PACKAGES};
  14. param cost{TRUCKS};
  15. param can_use{PACKAGES, TRUCKS};
  16. var x{PACKAGES, TRUCKS}, binary;
  17. var y{TRUCKS}, binary;
  18. minimize total: sum{i in TRUCKS} cost[i] * y[i];
  19. f1{i in TRUCKS}:
  20. sum{j in PACKAGES} size[j] * x[j,i] <= capacity[i] * y[i];
  21. f2{i in TRUCKS, j in PACKAGES}:
  22. x[j,i] <= y[i];
  23. f3{j in PACKAGES}:
  24. sum{i in TRUCKS} can_use[j,i] * x[j,i] = 1;
  25. redundant_constraint:
  26. sum{i in TRUCKS} capacity[i] * y[i] >= sum{j in PACKAGES} size[j];
  27. data;
  28. param capacity :=
  29. [1] 100 [2] 200 [3] 100 [4] 200 [5] 100 [6] 200 [7] 100 [8] 200
  30. [9] 100 [10] 200;
  31. param size :=
  32. [1] 17 [2] 21 [3] 54 [4] 45 [5] 87 [6] 34 [7] 23 [8] 45 [9] 12
  33. [10] 43 [11] 54 [12] 39 [13] 31 [14] 26 [15] 75 [16] 48 [17] 16
  34. [18] 32 [19] 45 [20] 55;
  35. param cost :=
  36. [1] 1 [2] 1.8 [3] 1 [4] 1.8 [5] 1 [6] 1.8 [7] 1 [8] 1.8 [9] 1
  37. [10] 1.8;
  38. param can_use (tr):
  39. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 :=
  40. 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0
  41. 2 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 0
  42. 3 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
  43. 4 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0
  44. 5 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 0
  45. 6 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0
  46. 7 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0
  47. 8 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1
  48. 9 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1
  49. 10 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1;
  50. end;