1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/food.mod Mon Dec 06 13:09:21 2010 +0100
1.3 @@ -0,0 +1,127 @@
1.4 +/* Food Manufacture 1, section 12.1 in
1.5 + * Williams, "Model Building in Mathematical Programming"
1.6 + *
1.7 + * Sebastian Nowozin <nowozin@gmail.com>
1.8 + */
1.9 +
1.10 +set oils;
1.11 +set month;
1.12 +
1.13 +/* Buying prices of the raw oils in the next six month. */
1.14 +param buyingprices{month,oils};
1.15 +
1.16 +/* Actual amount bought in each month. */
1.17 +var buys{month,oils} >= 0;
1.18 +
1.19 +/* Stock for each oil. */
1.20 +var stock{month,oils} >= 0;
1.21 +
1.22 +/* Price of the produced product */
1.23 +param productprice >= 0;
1.24 +param storagecost;
1.25 +
1.26 +param oilhardness{oils} >= 0;
1.27 +
1.28 +/* Actual amount of output oil produced in each month */
1.29 +var production{m in month} >= 0;
1.30 +var useoil{m in month, o in oils} >= 0;
1.31 +
1.32 +maximize totalprofit:
1.33 + sum{m in month} productprice*production[m]
1.34 + - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
1.35 + - sum{m in month, o in oils} storagecost*stock[m,o];
1.36 +
1.37 +/* Constraints */
1.38 +
1.39 +/* 1. Starting stock */
1.40 +s.t. startstock{o in oils}:
1.41 + stock[1,o] = 500;
1.42 +s.t. endstock{o in oils}:
1.43 + stock[6,o] + buys[6,o] - useoil[6,o] >= 500;
1.44 +
1.45 +/* 2. Stock constraints */
1.46 +s.t. stocklimit{m in month, o in oils}:
1.47 + stock[m,o] <= 1000;
1.48 +
1.49 +s.t. production1{m in month, o in oils}:
1.50 + useoil[m,o] <= stock[m,o] + buys[m,o];
1.51 +s.t. production2{m1 in month, m2 in month, o in oils : m2 = m1+1}:
1.52 + stock[m2,o] = stock[m1,o] + buys[m1,o] - useoil[m1,o];
1.53 +
1.54 +s.t. production3a{m in month}:
1.55 + sum{o in oils} oilhardness[o]*useoil[m,o] >= 3*production[m];
1.56 +s.t. production3b{m in month}:
1.57 + sum{o in oils} oilhardness[o]*useoil[m,o] <= 6*production[m];
1.58 +
1.59 +s.t. production4{m in month}:
1.60 + production[m] = sum{o in oils} useoil[m,o];
1.61 +
1.62 +/* 3. Refining constraints */
1.63 +s.t. refine1{m in month}:
1.64 + useoil[m,"VEG1"]+useoil[m,"VEG2"] <= 200;
1.65 +s.t. refine2{m in month}:
1.66 + useoil[m,"OIL1"]+useoil[m,"OIL2"]+useoil[m,"OIL3"] <= 250;
1.67 +
1.68 +solve;
1.69 +
1.70 +for {m in month} {
1.71 + printf "Month %d\n", m;
1.72 + printf "PRODUCE %4.2f tons, hardness %4.2f\n", production[m],
1.73 + (sum{o in oils} oilhardness[o]*useoil[m,o]) / (sum{o in oils} useoil[m,o]);
1.74 +
1.75 + printf "\tVEG1\tVEG2\tOIL1\tOIL2\tOIL3\n";
1.76 + printf "STOCK";
1.77 + printf "%d", m;
1.78 + for {o in oils} {
1.79 + printf "\t%4.2f", stock[m,o];
1.80 + }
1.81 + printf "\nBUY";
1.82 + for {o in oils} {
1.83 + printf "\t%4.2f", buys[m,o];
1.84 + }
1.85 + printf "\nUSE";
1.86 + printf "%d", m;
1.87 + for {o in oils} {
1.88 + printf "\t%4.2f", useoil[m,o];
1.89 + }
1.90 + printf "\n";
1.91 + printf "\n";
1.92 +}
1.93 +printf "Total profit: %4.2f\n",
1.94 + (sum{m in month} productprice*production[m]
1.95 + - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
1.96 + - sum{m in month, o in oils} storagecost*stock[m,o]);
1.97 +printf " turnover: %4.2f\n",
1.98 + sum{m in month} productprice*production[m];
1.99 +printf " buying costs: %4.2f\n",
1.100 + sum{m in month, o in oils} buyingprices[m,o]*buys[m,o];
1.101 +printf " storage costs: %4.2f\n",
1.102 + sum{m in month, o in oils} storagecost*stock[m,o];
1.103 +
1.104 +
1.105 +data;
1.106 +
1.107 +param : oils : oilhardness :=
1.108 + VEG1 8.8
1.109 + VEG2 6.1
1.110 + OIL1 2.0
1.111 + OIL2 4.2
1.112 + OIL3 5.0 ;
1.113 +
1.114 +set month := 1 2 3 4 5 6;
1.115 +
1.116 +param buyingprices
1.117 +
1.118 +: VEG1 VEG2 OIL1 OIL2 OIL3 :=
1.119 +
1.120 +1 110 120 130 110 115
1.121 +2 130 130 110 90 115
1.122 +3 110 140 130 100 95
1.123 +4 120 110 120 120 125
1.124 +5 100 120 150 110 105
1.125 +6 90 100 140 80 135 ;
1.126 +
1.127 +param productprice := 150;
1.128 +param storagecost := 5;
1.129 +
1.130 +end;