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