COIN-OR::LEMON - Graph Library

source: lemon-project-template-glpk/deps/glpk/examples/food.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: 3.3 KB
Line 
1/* Food Manufacture 1, section 12.1 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;
24
25/* Actual amount of output oil produced in each month */
26var production{m in month} >= 0;
27var useoil{m in month, o in oils} >= 0;
28
29maximize 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 */
37s.t. startstock{o in oils}:
38    stock[1,o] = 500;
39s.t. endstock{o in oils}:
40    stock[6,o] + buys[6,o] - useoil[6,o] >= 500;
41
42/* 2. Stock constraints */
43s.t. stocklimit{m in month, o in oils}:
44    stock[m,o] <= 1000;
45
46s.t. production1{m in month, o in oils}:
47    useoil[m,o] <= stock[m,o] + buys[m,o];
48s.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
51s.t. production3a{m in month}:
52    sum{o in oils} oilhardness[o]*useoil[m,o] >= 3*production[m];
53s.t. production3b{m in month}:
54    sum{o in oils} oilhardness[o]*useoil[m,o] <= 6*production[m];
55
56s.t. production4{m in month}:
57    production[m] = sum{o in oils} useoil[m,o];
58
59/* 3. Refining constraints */
60s.t. refine1{m in month}:
61    useoil[m,"VEG1"]+useoil[m,"VEG2"] <= 200;
62s.t. refine2{m in month}:
63    useoil[m,"OIL1"]+useoil[m,"OIL2"]+useoil[m,"OIL3"] <= 250;
64
65solve;
66
67for {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}
90printf "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]);
94printf "      turnover: %4.2f\n",
95    sum{m in month} productprice*production[m];
96printf "      buying costs: %4.2f\n",
97    sum{m in month, o in oils} buyingprices[m,o]*buys[m,o];
98printf "      storage costs: %4.2f\n",
99    sum{m in month, o in oils} storagecost*stock[m,o];
100
101
102data;
103
104param : oils : oilhardness :=
105    VEG1    8.8
106    VEG2    6.1
107    OIL1    2.0
108    OIL2    4.2
109    OIL3    5.0 ;
110
111set month := 1 2 3 4 5 6;
112
113param buyingprices
114
115:           VEG1    VEG2    OIL1    OIL2    OIL3    :=
116
1171           110     120     130     110     115
1182           130     130     110     90      115
1193           110     140     130     100     95
1204           120     110     120     120     125
1215           100     120     150     110     105
1226           90      100     140     80      135 ;
123
124param productprice := 150;
125param storagecost := 5;
126
127end;
Note: See TracBrowser for help on using the repository browser.