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.

150 lines
4.0 KiB

  1. /* Food Manufacture 2, section 12.2 in
  2. * Williams, "Model Building in Mathematical Programming"
  3. *
  4. * Sebastian Nowozin <nowozin@gmail.com>
  5. */
  6. set oils;
  7. set month;
  8. /* Buying prices of the raw oils in the next six month. */
  9. param buyingprices{month,oils};
  10. /* Actual amount bought in each month. */
  11. var buys{month,oils} >= 0;
  12. /* Stock for each oil. */
  13. var stock{month,oils} >= 0;
  14. /* Price of the produced product */
  15. param productprice >= 0;
  16. param storagecost;
  17. param oilhardness{oils} >= 0;
  18. param M >= 0;
  19. /* Actual amount of output oil produced in each month */
  20. var production{m in month} >= 0;
  21. var useoil{m in month, o in oils} >= 0, <= M;
  22. var useoilb{m in month, o in oils}, binary;
  23. maximize totalprofit:
  24. sum{m in month} productprice*production[m]
  25. - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
  26. - sum{m in month, o in oils} storagecost*stock[m,o];
  27. /* Constraints */
  28. /* 1. Starting stock */
  29. s.t. startstock{o in oils}:
  30. stock[1,o] = 500;
  31. s.t. endstock{o in oils}:
  32. stock[6,o] + buys[6,o] - useoil[6,o] >= 500;
  33. /* 2. Stock constraints */
  34. s.t. stocklimit{m in month, o in oils}:
  35. stock[m,o] <= 1000;
  36. s.t. production1{m in month, o in oils}:
  37. useoil[m,o] <= stock[m,o] + buys[m,o];
  38. s.t. production2{m1 in month, m2 in month, o in oils : m2 = m1+1}:
  39. stock[m2,o] = stock[m1,o] + buys[m1,o] - useoil[m1,o];
  40. s.t. production3a{m in month}:
  41. sum{o in oils} oilhardness[o]*useoil[m,o] >= 3*production[m];
  42. s.t. production3b{m in month}:
  43. sum{o in oils} oilhardness[o]*useoil[m,o] <= 6*production[m];
  44. s.t. production4{m in month}:
  45. production[m] = sum{o in oils} useoil[m,o];
  46. /* 3. Refining constraints */
  47. s.t. refine1{m in month}:
  48. useoil[m,"VEG1"]+useoil[m,"VEG2"] <= 200;
  49. s.t. refine2{m in month}:
  50. useoil[m,"OIL1"]+useoil[m,"OIL2"]+useoil[m,"OIL3"] <= 250;
  51. /* 4. Additional conditions:
  52. * i) The food may never be made up of more than three oils every month
  53. */
  54. s.t. useoilb_calc{m in month, o in oils}:
  55. M*useoilb[m,o] >= useoil[m,o];
  56. s.t. useoilb_limit{m in month}:
  57. sum{o in oils} useoilb[m,o] <= 3;
  58. /* ii) If an oil is used in a month, at least 20 tons must be used.
  59. */
  60. s.t. useminimum{m in month, o in oils}:
  61. 20*useoilb[m,o] <= useoil[m,o];
  62. /* iii) If either of VEG1 or VEG2 is used in a month, OIL2 must also be used
  63. */
  64. s.t. use_oil2a{m in month}:
  65. useoilb[m,"VEG1"] <= useoilb[m,"OIL3"];
  66. s.t. use_oil2b{m in month}:
  67. useoilb[m,"VEG2"] <= useoilb[m,"OIL3"];
  68. solve;
  69. for {m in month} {
  70. printf "Month %d\n", m;
  71. printf "PRODUCE %4.2f tons, hardness %4.2f\n", production[m],
  72. (sum{o in oils} oilhardness[o]*useoil[m,o]) / (sum{o in oils} useoil[m,o]);
  73. printf "\tVEG1\tVEG2\tOIL1\tOIL2\tOIL3\n";
  74. printf "STOCK";
  75. printf "%d", m;
  76. for {o in oils} {
  77. printf "\t%4.2f", stock[m,o];
  78. }
  79. printf "\nBUY";
  80. for {o in oils} {
  81. printf "\t%4.2f", buys[m,o];
  82. }
  83. printf "\nUSE";
  84. printf "%d", m;
  85. for {o in oils} {
  86. printf "\t%4.2f", useoil[m,o];
  87. }
  88. printf "\n";
  89. printf "\n";
  90. }
  91. printf "Total profit: %4.2f\n",
  92. (sum{m in month} productprice*production[m]
  93. - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
  94. - sum{m in month, o in oils} storagecost*stock[m,o]);
  95. printf " turnover: %4.2f\n",
  96. sum{m in month} productprice*production[m];
  97. printf " buying costs: %4.2f\n",
  98. sum{m in month, o in oils} buyingprices[m,o]*buys[m,o];
  99. printf " storage costs: %4.2f\n",
  100. sum{m in month, o in oils} storagecost*stock[m,o];
  101. data;
  102. param : oils : oilhardness :=
  103. VEG1 8.8
  104. VEG2 6.1
  105. OIL1 2.0
  106. OIL2 4.2
  107. OIL3 5.0 ;
  108. set month := 1 2 3 4 5 6;
  109. param buyingprices
  110. : VEG1 VEG2 OIL1 OIL2 OIL3 :=
  111. 1 110 120 130 110 115
  112. 2 130 130 110 90 115
  113. 3 110 140 130 100 95
  114. 4 120 110 120 120 125
  115. 5 100 120 150 110 105
  116. 6 90 100 140 80 135 ;
  117. param productprice := 150;
  118. param storagecost := 5;
  119. param M := 1000;
  120. end;