$title Natural Gas Planning over 3 stages: stochastic LP. SJW 12/4/02 option limcol=0, limrow=0; $setglobal NSCENARIOS 4 set scenarios/1*%NSCENARIOS%/ ; alias (scenarios,scenarios2,scenarios3); * figure demands, purchase prices, and probability of each * scenario. Assume that these are the same at each of stages 2 and 3. parameter demand (scenarios) /1 75, 2 100, 3 125, 4 160/ purchasePrice (scenarios) /1 .80, 2 1.0, 3 1.3, 4 1.8/ probability (scenarios) /1 .10, 2 .5, 3 .25, 4 .15/ ; scalar demand1 demand at first stage /100/ purchasePrice1 purchase price at first stage /1.0/ storageCost cost of storing one unit for one period /.05/ ; positive variable purchase1 how much to purchase at first stage purchase2(scenarios2) how much extra to purchase at second stage purchase3(scenarios2,scenarios3) extra purchase at third stage storage1 how much carried over to second stage storage2(scenarios2) how much carried over to third stage useFromStorage2(scenarios2) how much to use from storage at second stage useFromStorage3(scenarios2, scenarios3) how much to use from storage at second stage ; * objective function is total cost of purchase and storage variable totalCost objective function ; equations meetDemand1 meet demand at first stage meetDemand2(scenarios2) meet demand at second stage in av cost model meetDemand3(scenarios2,scenarios3) meet demands at second stage under different scenarios storageBalance figure amt carried over to second stage storageBalance2(scenarios2) figure amt carried over to third stage useLessThanStored2(scenarios2) useLessThanStored3(scenarios2,scenarios3) objective ; * set up the equations for the stochastic model * buy enough to meet demand at stage 1 meetDemand1.. purchase1 =g= demand1; * buy enough to meet stage-2 demand, under each scenario meetDemand2(scenarios2).. purchase2(scenarios2) + useFromStorage2(scenarios2) =g= demand(scenarios2); * buy enough to meet stage-3 demand, under each scenario meetDemand3(scenarios2,scenarios3).. purchase3(scenarios2,scenarios3) + useFromStorage3(scenarios2,scenarios3) =g= demand(scenarios3); * figure amount to storage, after meeting stage-1 demand storageBalance.. storage1 =e= purchase1 - demand1; * figure amount to storage, after meeting stage-2 demand under each * scenario storageBalance2(scenarios2).. storage2(scenarios2) =e= purchase2(scenarios2) + storage1 - demand(scenarios2); * can't use more from storage than you have stored useLessThanStored2(scenarios2).. useFromStorage2(scenarios2) =l= storage1; useLessThanStored3(scenarios2,scenarios3).. useFromStorage3(scenarios2,scenarios3) =l= storage2(scenarios2); * note nested summation for second and third stage costs objective.. totalCost =e= purchase1*purchasePrice1 + storage1*storageCost + sum(scenarios2,probability(scenarios2)*(purchase2(scenarios2)*purchasePrice(scenarios2) + storage2(scenarios2)*storageCost + sum(scenarios3, probability(scenarios3)*purchase3(scenarios2,scenarios3)*purchasePrice(scenarios3)))); * formulate and solve the stochastic problem model gasplanning3/meetDemand1,meetDemand2,meetDemand3, storageBalance,storageBalance2, useLessThanStored2,useLessThanStored3, objective/; solve gasplanning3 using lp minimizing totalCost;