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