lemon-project-template-glpk

annotate deps/glpk/examples/food.mod @ 11:4fc6ad2fb8a6

Test GLPK in src/main.cc
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 21:43:29 +0100
parents
children
rev   line source
alpar@9 1 /* Food Manufacture 1, section 12.1 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
alpar@9 25 /* Actual amount of output oil produced in each month */
alpar@9 26 var production{m in month} >= 0;
alpar@9 27 var useoil{m in month, o in oils} >= 0;
alpar@9 28
alpar@9 29 maximize totalprofit:
alpar@9 30 sum{m in month} productprice*production[m]
alpar@9 31 - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
alpar@9 32 - sum{m in month, o in oils} storagecost*stock[m,o];
alpar@9 33
alpar@9 34 /* Constraints */
alpar@9 35
alpar@9 36 /* 1. Starting stock */
alpar@9 37 s.t. startstock{o in oils}:
alpar@9 38 stock[1,o] = 500;
alpar@9 39 s.t. endstock{o in oils}:
alpar@9 40 stock[6,o] + buys[6,o] - useoil[6,o] >= 500;
alpar@9 41
alpar@9 42 /* 2. Stock constraints */
alpar@9 43 s.t. stocklimit{m in month, o in oils}:
alpar@9 44 stock[m,o] <= 1000;
alpar@9 45
alpar@9 46 s.t. production1{m in month, o in oils}:
alpar@9 47 useoil[m,o] <= stock[m,o] + buys[m,o];
alpar@9 48 s.t. production2{m1 in month, m2 in month, o in oils : m2 = m1+1}:
alpar@9 49 stock[m2,o] = stock[m1,o] + buys[m1,o] - useoil[m1,o];
alpar@9 50
alpar@9 51 s.t. production3a{m in month}:
alpar@9 52 sum{o in oils} oilhardness[o]*useoil[m,o] >= 3*production[m];
alpar@9 53 s.t. production3b{m in month}:
alpar@9 54 sum{o in oils} oilhardness[o]*useoil[m,o] <= 6*production[m];
alpar@9 55
alpar@9 56 s.t. production4{m in month}:
alpar@9 57 production[m] = sum{o in oils} useoil[m,o];
alpar@9 58
alpar@9 59 /* 3. Refining constraints */
alpar@9 60 s.t. refine1{m in month}:
alpar@9 61 useoil[m,"VEG1"]+useoil[m,"VEG2"] <= 200;
alpar@9 62 s.t. refine2{m in month}:
alpar@9 63 useoil[m,"OIL1"]+useoil[m,"OIL2"]+useoil[m,"OIL3"] <= 250;
alpar@9 64
alpar@9 65 solve;
alpar@9 66
alpar@9 67 for {m in month} {
alpar@9 68 printf "Month %d\n", m;
alpar@9 69 printf "PRODUCE %4.2f tons, hardness %4.2f\n", production[m],
alpar@9 70 (sum{o in oils} oilhardness[o]*useoil[m,o]) / (sum{o in oils} useoil[m,o]);
alpar@9 71
alpar@9 72 printf "\tVEG1\tVEG2\tOIL1\tOIL2\tOIL3\n";
alpar@9 73 printf "STOCK";
alpar@9 74 printf "%d", m;
alpar@9 75 for {o in oils} {
alpar@9 76 printf "\t%4.2f", stock[m,o];
alpar@9 77 }
alpar@9 78 printf "\nBUY";
alpar@9 79 for {o in oils} {
alpar@9 80 printf "\t%4.2f", buys[m,o];
alpar@9 81 }
alpar@9 82 printf "\nUSE";
alpar@9 83 printf "%d", m;
alpar@9 84 for {o in oils} {
alpar@9 85 printf "\t%4.2f", useoil[m,o];
alpar@9 86 }
alpar@9 87 printf "\n";
alpar@9 88 printf "\n";
alpar@9 89 }
alpar@9 90 printf "Total profit: %4.2f\n",
alpar@9 91 (sum{m in month} productprice*production[m]
alpar@9 92 - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
alpar@9 93 - sum{m in month, o in oils} storagecost*stock[m,o]);
alpar@9 94 printf " turnover: %4.2f\n",
alpar@9 95 sum{m in month} productprice*production[m];
alpar@9 96 printf " buying costs: %4.2f\n",
alpar@9 97 sum{m in month, o in oils} buyingprices[m,o]*buys[m,o];
alpar@9 98 printf " storage costs: %4.2f\n",
alpar@9 99 sum{m in month, o in oils} storagecost*stock[m,o];
alpar@9 100
alpar@9 101
alpar@9 102 data;
alpar@9 103
alpar@9 104 param : oils : oilhardness :=
alpar@9 105 VEG1 8.8
alpar@9 106 VEG2 6.1
alpar@9 107 OIL1 2.0
alpar@9 108 OIL2 4.2
alpar@9 109 OIL3 5.0 ;
alpar@9 110
alpar@9 111 set month := 1 2 3 4 5 6;
alpar@9 112
alpar@9 113 param buyingprices
alpar@9 114
alpar@9 115 : VEG1 VEG2 OIL1 OIL2 OIL3 :=
alpar@9 116
alpar@9 117 1 110 120 130 110 115
alpar@9 118 2 130 130 110 90 115
alpar@9 119 3 110 140 130 100 95
alpar@9 120 4 120 110 120 120 125
alpar@9 121 5 100 120 150 110 105
alpar@9 122 6 90 100 140 80 135 ;
alpar@9 123
alpar@9 124 param productprice := 150;
alpar@9 125 param storagecost := 5;
alpar@9 126
alpar@9 127 end;