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