The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

127 lines
3.3 KiB

2 months ago
  1. /* Food Manufacture 1, section 12.1 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. /* Actual amount of output oil produced in each month */
  19. var production{m in month} >= 0;
  20. var useoil{m in month, o in oils} >= 0;
  21. maximize totalprofit:
  22. sum{m in month} productprice*production[m]
  23. - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
  24. - sum{m in month, o in oils} storagecost*stock[m,o];
  25. /* Constraints */
  26. /* 1. Starting stock */
  27. s.t. startstock{o in oils}:
  28. stock[1,o] = 500;
  29. s.t. endstock{o in oils}:
  30. stock[6,o] + buys[6,o] - useoil[6,o] >= 500;
  31. /* 2. Stock constraints */
  32. s.t. stocklimit{m in month, o in oils}:
  33. stock[m,o] <= 1000;
  34. s.t. production1{m in month, o in oils}:
  35. useoil[m,o] <= stock[m,o] + buys[m,o];
  36. s.t. production2{m1 in month, m2 in month, o in oils : m2 = m1+1}:
  37. stock[m2,o] = stock[m1,o] + buys[m1,o] - useoil[m1,o];
  38. s.t. production3a{m in month}:
  39. sum{o in oils} oilhardness[o]*useoil[m,o] >= 3*production[m];
  40. s.t. production3b{m in month}:
  41. sum{o in oils} oilhardness[o]*useoil[m,o] <= 6*production[m];
  42. s.t. production4{m in month}:
  43. production[m] = sum{o in oils} useoil[m,o];
  44. /* 3. Refining constraints */
  45. s.t. refine1{m in month}:
  46. useoil[m,"VEG1"]+useoil[m,"VEG2"] <= 200;
  47. s.t. refine2{m in month}:
  48. useoil[m,"OIL1"]+useoil[m,"OIL2"]+useoil[m,"OIL3"] <= 250;
  49. solve;
  50. for {m in month} {
  51. printf "Month %d\n", m;
  52. printf "PRODUCE %4.2f tons, hardness %4.2f\n", production[m],
  53. (sum{o in oils} oilhardness[o]*useoil[m,o]) / (sum{o in oils} useoil[m,o]);
  54. printf "\tVEG1\tVEG2\tOIL1\tOIL2\tOIL3\n";
  55. printf "STOCK";
  56. printf "%d", m;
  57. for {o in oils} {
  58. printf "\t%4.2f", stock[m,o];
  59. }
  60. printf "\nBUY";
  61. for {o in oils} {
  62. printf "\t%4.2f", buys[m,o];
  63. }
  64. printf "\nUSE";
  65. printf "%d", m;
  66. for {o in oils} {
  67. printf "\t%4.2f", useoil[m,o];
  68. }
  69. printf "\n";
  70. printf "\n";
  71. }
  72. printf "Total profit: %4.2f\n",
  73. (sum{m in month} productprice*production[m]
  74. - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
  75. - sum{m in month, o in oils} storagecost*stock[m,o]);
  76. printf " turnover: %4.2f\n",
  77. sum{m in month} productprice*production[m];
  78. printf " buying costs: %4.2f\n",
  79. sum{m in month, o in oils} buyingprices[m,o]*buys[m,o];
  80. printf " storage costs: %4.2f\n",
  81. sum{m in month, o in oils} storagecost*stock[m,o];
  82. data;
  83. param : oils : oilhardness :=
  84. VEG1 8.8
  85. VEG2 6.1
  86. OIL1 2.0
  87. OIL2 4.2
  88. OIL3 5.0 ;
  89. set month := 1 2 3 4 5 6;
  90. param buyingprices
  91. : VEG1 VEG2 OIL1 OIL2 OIL3 :=
  92. 1 110 120 130 110 115
  93. 2 130 130 110 90 115
  94. 3 110 140 130 100 95
  95. 4 120 110 120 120 125
  96. 5 100 120 150 110 105
  97. 6 90 100 140 80 135 ;
  98. param productprice := 150;
  99. param storagecost := 5;
  100. end;