alpar@1: /* Food Manufacture 1, section 12.1 in alpar@1: * Williams, "Model Building in Mathematical Programming" alpar@1: * alpar@1: * Sebastian Nowozin alpar@1: */ alpar@1: alpar@1: set oils; alpar@1: set month; alpar@1: alpar@1: /* Buying prices of the raw oils in the next six month. */ alpar@1: param buyingprices{month,oils}; alpar@1: alpar@1: /* Actual amount bought in each month. */ alpar@1: var buys{month,oils} >= 0; alpar@1: alpar@1: /* Stock for each oil. */ alpar@1: var stock{month,oils} >= 0; alpar@1: alpar@1: /* Price of the produced product */ alpar@1: param productprice >= 0; alpar@1: param storagecost; alpar@1: alpar@1: param oilhardness{oils} >= 0; alpar@1: alpar@1: /* Actual amount of output oil produced in each month */ alpar@1: var production{m in month} >= 0; alpar@1: var useoil{m in month, o in oils} >= 0; alpar@1: alpar@1: maximize totalprofit: alpar@1: sum{m in month} productprice*production[m] alpar@1: - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o] alpar@1: - sum{m in month, o in oils} storagecost*stock[m,o]; alpar@1: alpar@1: /* Constraints */ alpar@1: alpar@1: /* 1. Starting stock */ alpar@1: s.t. startstock{o in oils}: alpar@1: stock[1,o] = 500; alpar@1: s.t. endstock{o in oils}: alpar@1: stock[6,o] + buys[6,o] - useoil[6,o] >= 500; alpar@1: alpar@1: /* 2. Stock constraints */ alpar@1: s.t. stocklimit{m in month, o in oils}: alpar@1: stock[m,o] <= 1000; alpar@1: alpar@1: s.t. production1{m in month, o in oils}: alpar@1: useoil[m,o] <= stock[m,o] + buys[m,o]; alpar@1: s.t. production2{m1 in month, m2 in month, o in oils : m2 = m1+1}: alpar@1: stock[m2,o] = stock[m1,o] + buys[m1,o] - useoil[m1,o]; alpar@1: alpar@1: s.t. production3a{m in month}: alpar@1: sum{o in oils} oilhardness[o]*useoil[m,o] >= 3*production[m]; alpar@1: s.t. production3b{m in month}: alpar@1: sum{o in oils} oilhardness[o]*useoil[m,o] <= 6*production[m]; alpar@1: alpar@1: s.t. production4{m in month}: alpar@1: production[m] = sum{o in oils} useoil[m,o]; alpar@1: alpar@1: /* 3. Refining constraints */ alpar@1: s.t. refine1{m in month}: alpar@1: useoil[m,"VEG1"]+useoil[m,"VEG2"] <= 200; alpar@1: s.t. refine2{m in month}: alpar@1: useoil[m,"OIL1"]+useoil[m,"OIL2"]+useoil[m,"OIL3"] <= 250; alpar@1: alpar@1: solve; alpar@1: alpar@1: for {m in month} { alpar@1: printf "Month %d\n", m; alpar@1: printf "PRODUCE %4.2f tons, hardness %4.2f\n", production[m], alpar@1: (sum{o in oils} oilhardness[o]*useoil[m,o]) / (sum{o in oils} useoil[m,o]); alpar@1: alpar@1: printf "\tVEG1\tVEG2\tOIL1\tOIL2\tOIL3\n"; alpar@1: printf "STOCK"; alpar@1: printf "%d", m; alpar@1: for {o in oils} { alpar@1: printf "\t%4.2f", stock[m,o]; alpar@1: } alpar@1: printf "\nBUY"; alpar@1: for {o in oils} { alpar@1: printf "\t%4.2f", buys[m,o]; alpar@1: } alpar@1: printf "\nUSE"; alpar@1: printf "%d", m; alpar@1: for {o in oils} { alpar@1: printf "\t%4.2f", useoil[m,o]; alpar@1: } alpar@1: printf "\n"; alpar@1: printf "\n"; alpar@1: } alpar@1: printf "Total profit: %4.2f\n", alpar@1: (sum{m in month} productprice*production[m] alpar@1: - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o] alpar@1: - sum{m in month, o in oils} storagecost*stock[m,o]); alpar@1: printf " turnover: %4.2f\n", alpar@1: sum{m in month} productprice*production[m]; alpar@1: printf " buying costs: %4.2f\n", alpar@1: sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]; alpar@1: printf " storage costs: %4.2f\n", alpar@1: sum{m in month, o in oils} storagecost*stock[m,o]; alpar@1: alpar@1: alpar@1: data; alpar@1: alpar@1: param : oils : oilhardness := alpar@1: VEG1 8.8 alpar@1: VEG2 6.1 alpar@1: OIL1 2.0 alpar@1: OIL2 4.2 alpar@1: OIL3 5.0 ; alpar@1: alpar@1: set month := 1 2 3 4 5 6; alpar@1: alpar@1: param buyingprices alpar@1: alpar@1: : VEG1 VEG2 OIL1 OIL2 OIL3 := alpar@1: alpar@1: 1 110 120 130 110 115 alpar@1: 2 130 130 110 90 115 alpar@1: 3 110 140 130 100 95 alpar@1: 4 120 110 120 120 125 alpar@1: 5 100 120 150 110 105 alpar@1: 6 90 100 140 80 135 ; alpar@1: alpar@1: param productprice := 150; alpar@1: param storagecost := 5; alpar@1: alpar@1: end;