1 /* Food Manufacture 2, section 12.2 in
2 * Williams, "Model Building in Mathematical Programming"
4 * Sebastian Nowozin <nowozin@gmail.com>
10 /* Buying prices of the raw oils in the next six month. */
11 param buyingprices{month,oils};
13 /* Actual amount bought in each month. */
14 var buys{month,oils} >= 0;
16 /* Stock for each oil. */
17 var stock{month,oils} >= 0;
19 /* Price of the produced product */
20 param productprice >= 0;
23 param oilhardness{oils} >= 0;
26 /* Actual amount of output oil produced in each month */
27 var production{m in month} >= 0;
28 var useoil{m in month, o in oils} >= 0, <= M;
29 var useoilb{m in month, o in oils}, binary;
32 sum{m in month} productprice*production[m]
33 - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
34 - sum{m in month, o in oils} storagecost*stock[m,o];
38 /* 1. Starting stock */
39 s.t. startstock{o in oils}:
41 s.t. endstock{o in oils}:
42 stock[6,o] + buys[6,o] - useoil[6,o] >= 500;
44 /* 2. Stock constraints */
45 s.t. stocklimit{m in month, o in oils}:
48 s.t. production1{m in month, o in oils}:
49 useoil[m,o] <= stock[m,o] + buys[m,o];
50 s.t. production2{m1 in month, m2 in month, o in oils : m2 = m1+1}:
51 stock[m2,o] = stock[m1,o] + buys[m1,o] - useoil[m1,o];
53 s.t. production3a{m in month}:
54 sum{o in oils} oilhardness[o]*useoil[m,o] >= 3*production[m];
55 s.t. production3b{m in month}:
56 sum{o in oils} oilhardness[o]*useoil[m,o] <= 6*production[m];
58 s.t. production4{m in month}:
59 production[m] = sum{o in oils} useoil[m,o];
61 /* 3. Refining constraints */
62 s.t. refine1{m in month}:
63 useoil[m,"VEG1"]+useoil[m,"VEG2"] <= 200;
64 s.t. refine2{m in month}:
65 useoil[m,"OIL1"]+useoil[m,"OIL2"]+useoil[m,"OIL3"] <= 250;
67 /* 4. Additional conditions:
68 * i) The food may never be made up of more than three oils every month
70 s.t. useoilb_calc{m in month, o in oils}:
71 M*useoilb[m,o] >= useoil[m,o];
72 s.t. useoilb_limit{m in month}:
73 sum{o in oils} useoilb[m,o] <= 3;
75 /* ii) If an oil is used in a month, at least 20 tons must be used.
77 s.t. useminimum{m in month, o in oils}:
78 20*useoilb[m,o] <= useoil[m,o];
80 /* iii) If either of VEG1 or VEG2 is used in a month, OIL2 must also be used
82 s.t. use_oil2a{m in month}:
83 useoilb[m,"VEG1"] <= useoilb[m,"OIL3"];
84 s.t. use_oil2b{m in month}:
85 useoilb[m,"VEG2"] <= useoilb[m,"OIL3"];
90 printf "Month %d\n", m;
91 printf "PRODUCE %4.2f tons, hardness %4.2f\n", production[m],
92 (sum{o in oils} oilhardness[o]*useoil[m,o]) / (sum{o in oils} useoil[m,o]);
94 printf "\tVEG1\tVEG2\tOIL1\tOIL2\tOIL3\n";
98 printf "\t%4.2f", stock[m,o];
102 printf "\t%4.2f", buys[m,o];
107 printf "\t%4.2f", useoil[m,o];
112 printf "Total profit: %4.2f\n",
113 (sum{m in month} productprice*production[m]
114 - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
115 - sum{m in month, o in oils} storagecost*stock[m,o]);
116 printf " turnover: %4.2f\n",
117 sum{m in month} productprice*production[m];
118 printf " buying costs: %4.2f\n",
119 sum{m in month, o in oils} buyingprices[m,o]*buys[m,o];
120 printf " storage costs: %4.2f\n",
121 sum{m in month, o in oils} storagecost*stock[m,o];
126 param : oils : oilhardness :=
133 set month := 1 2 3 4 5 6;
137 : VEG1 VEG2 OIL1 OIL2 OIL3 :=
139 1 110 120 130 110 115
142 4 120 110 120 120 125
143 5 100 120 150 110 105
144 6 90 100 140 80 135 ;
146 param productprice := 150;
147 param storagecost := 5;