lemon-project-template-glpk
comparison deps/glpk/examples/food2.mod @ 9:33de93886c88
Import GLPK 4.47
author | Alpar Juttner <alpar@cs.elte.hu> |
---|---|
date | Sun, 06 Nov 2011 20:59:10 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4d219b13ab04 |
---|---|
1 /* Food Manufacture 2, section 12.2 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 param M >= 0; | |
25 | |
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; | |
30 | |
31 maximize totalprofit: | |
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]; | |
35 | |
36 /* Constraints */ | |
37 | |
38 /* 1. Starting stock */ | |
39 s.t. startstock{o in oils}: | |
40 stock[1,o] = 500; | |
41 s.t. endstock{o in oils}: | |
42 stock[6,o] + buys[6,o] - useoil[6,o] >= 500; | |
43 | |
44 /* 2. Stock constraints */ | |
45 s.t. stocklimit{m in month, o in oils}: | |
46 stock[m,o] <= 1000; | |
47 | |
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]; | |
52 | |
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]; | |
57 | |
58 s.t. production4{m in month}: | |
59 production[m] = sum{o in oils} useoil[m,o]; | |
60 | |
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; | |
66 | |
67 /* 4. Additional conditions: | |
68 * i) The food may never be made up of more than three oils every month | |
69 */ | |
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; | |
74 | |
75 /* ii) If an oil is used in a month, at least 20 tons must be used. | |
76 */ | |
77 s.t. useminimum{m in month, o in oils}: | |
78 20*useoilb[m,o] <= useoil[m,o]; | |
79 | |
80 /* iii) If either of VEG1 or VEG2 is used in a month, OIL2 must also be used | |
81 */ | |
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"]; | |
86 | |
87 solve; | |
88 | |
89 for {m in month} { | |
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]); | |
93 | |
94 printf "\tVEG1\tVEG2\tOIL1\tOIL2\tOIL3\n"; | |
95 printf "STOCK"; | |
96 printf "%d", m; | |
97 for {o in oils} { | |
98 printf "\t%4.2f", stock[m,o]; | |
99 } | |
100 printf "\nBUY"; | |
101 for {o in oils} { | |
102 printf "\t%4.2f", buys[m,o]; | |
103 } | |
104 printf "\nUSE"; | |
105 printf "%d", m; | |
106 for {o in oils} { | |
107 printf "\t%4.2f", useoil[m,o]; | |
108 } | |
109 printf "\n"; | |
110 printf "\n"; | |
111 } | |
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]; | |
122 | |
123 | |
124 data; | |
125 | |
126 param : oils : oilhardness := | |
127 VEG1 8.8 | |
128 VEG2 6.1 | |
129 OIL1 2.0 | |
130 OIL2 4.2 | |
131 OIL3 5.0 ; | |
132 | |
133 set month := 1 2 3 4 5 6; | |
134 | |
135 param buyingprices | |
136 | |
137 : VEG1 VEG2 OIL1 OIL2 OIL3 := | |
138 | |
139 1 110 120 130 110 115 | |
140 2 130 130 110 90 115 | |
141 3 110 140 130 100 95 | |
142 4 120 110 120 120 125 | |
143 5 100 120 150 110 105 | |
144 6 90 100 140 80 135 ; | |
145 | |
146 param productprice := 150; | |
147 param storagecost := 5; | |
148 param M := 1000; | |
149 | |
150 end; |