COIN-OR::LEMON - Graph Library

source: lemon-project-template-glpk/deps/glpk/examples/food2.mod

subpack-glpk
Last change on this file was 9:33de93886c88, checked in by Alpar Juttner <alpar@…>, 13 years ago

Import GLPK 4.47

File size: 4.0 KB
RevLine 
[9]1/* Food Manufacture 2, section 12.2 in
2 * Williams, "Model Building in Mathematical Programming"
3 *
4 * Sebastian Nowozin <nowozin@gmail.com>
5 */
6
7set oils;
8set month;
9
10/* Buying prices of the raw oils in the next six month. */
11param buyingprices{month,oils};
12
13/* Actual amount bought in each month. */
14var buys{month,oils} >= 0;
15
16/* Stock for each oil. */
17var stock{month,oils} >= 0;
18
19/* Price of the produced product */
20param productprice >= 0;
21param storagecost;
22
23param oilhardness{oils} >= 0;
24param M >= 0;
25
26/* Actual amount of output oil produced in each month */
27var production{m in month} >= 0;
28var useoil{m in month, o in oils} >= 0, <= M;
29var useoilb{m in month, o in oils}, binary;
30
31maximize 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 */
39s.t. startstock{o in oils}:
40    stock[1,o] = 500;
41s.t. endstock{o in oils}:
42    stock[6,o] + buys[6,o] - useoil[6,o] >= 500;
43
44/* 2. Stock constraints */
45s.t. stocklimit{m in month, o in oils}:
46    stock[m,o] <= 1000;
47
48s.t. production1{m in month, o in oils}:
49    useoil[m,o] <= stock[m,o] + buys[m,o];
50s.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
53s.t. production3a{m in month}:
54    sum{o in oils} oilhardness[o]*useoil[m,o] >= 3*production[m];
55s.t. production3b{m in month}:
56    sum{o in oils} oilhardness[o]*useoil[m,o] <= 6*production[m];
57
58s.t. production4{m in month}:
59    production[m] = sum{o in oils} useoil[m,o];
60
61/* 3. Refining constraints */
62s.t. refine1{m in month}:
63    useoil[m,"VEG1"]+useoil[m,"VEG2"] <= 200;
64s.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 */
70s.t. useoilb_calc{m in month, o in oils}:
71    M*useoilb[m,o] >= useoil[m,o];
72s.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 */
77s.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 */
82s.t. use_oil2a{m in month}:
83    useoilb[m,"VEG1"] <= useoilb[m,"OIL3"];
84s.t. use_oil2b{m in month}:
85    useoilb[m,"VEG2"] <= useoilb[m,"OIL3"];
86
87solve;
88
89for {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}
112printf "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]);
116printf "      turnover: %4.2f\n",
117    sum{m in month} productprice*production[m];
118printf "      buying costs: %4.2f\n",
119    sum{m in month, o in oils} buyingprices[m,o]*buys[m,o];
120printf "      storage costs: %4.2f\n",
121    sum{m in month, o in oils} storagecost*stock[m,o];
122
123
124data;
125
126param : oils : oilhardness :=
127    VEG1    8.8
128    VEG2    6.1
129    OIL1    2.0
130    OIL2    4.2
131    OIL3    5.0 ;
132
133set month := 1 2 3 4 5 6;
134
135param buyingprices
136
137:           VEG1    VEG2    OIL1    OIL2    OIL3    :=
138
1391           110     120     130     110     115
1402           130     130     110     90      115
1413           110     140     130     100     95
1424           120     110     120     120     125
1435           100     120     150     110     105
1446           90      100     140     80      135 ;
145
146param productprice := 150;
147param storagecost := 5;
148param M := 1000;
149
150end;
Note: See TracBrowser for help on using the repository browser.