(!****************************************************** Xpress-SP Example ====================== `````````````````` FILE: AnalysisOfFarmerProblem.mos DESCRIPTION: Farm production planning TYPE: Stochastic 2-stage linear model A farmer needs to make decisions regarding the devotion of available land to different products: wheat, corn and sugar beet, during the winter season. The yield is realized in the summer and depends on the overall weather during the year (e.g., bad, ok, good). The farmer must produce a certain amount of products for the cattle feed. Then the farmer must also decide how much of each product needs to be purchased or sold depending on the yield. There is an additional restriction on the selling price of sugar beet because of quota restriction. MODEL: • Sets o Stages: {Winter, Summer} o Products: {Wheat, Corn, Sugar Beet} • Constraints o Minimum production for cattle feed o Quota restriction on sugar beet production • Variables o x(i): acres of land devoted to product i o w(wheat), w(corn): tons of wheat and corn sold respectively o y(wheat), y(corn): tons of wheat and corn purchased respectively o w(favor), w(unfavor): tons of sugar beet sold at favorable and unfavorable price respectively FURTHER INFO: see J.R.Birge and Francois Louveaux (97) - “A farmer’s problem”- Introduction to Stochastic Programming, 4-10 see Xpress-SP guide DATE: Mar 2006 (c) 2006 Dash Associates Author: Nitin Verma Dash Optimization Inc, NJ *******************************************************!) model farmer uses 'mmsp' parameters Explicit=false !explicitly create tree or use the joint distribution feature end-parameters forward procedure Analyse(prob:string) declarations !ALL Products={"Wheat","Corn","Sugar Beet Favorable","Sugar Beet Unfavorable"} AllProducts={"Wht","Crn","SugBtFav","SugBtUnfav"} Products={"Wht","Crn","SugBt"} WheatAndCorn={"Wht","Crn"} PlantingCost:array(Products) of real SellingPrice:array(AllProducts) of real PurchasePrice:array(WheatAndCorn) of real MinimumRequirement:array(WheatAndCorn) of real TotalAvailableLand:real MaxSugarBeetQuota:real end-declarations ! Data PlantingCost:=[150,230,260] SellingPrice:=[170,150,36,10] PurchasePrice:=[238,210] MinimumRequirement:=[200,240] TotalAvailableLand:=500 MaxSugarBeetQuota:=6000 declarations Stages={"Wint","Summ"} yield:array(Products) of sprand x:array(Products) of spvar y:array(WheatAndCorn) of spvar w:array(AllProducts) of spvar TotalCost:splinctr LandUtilized:splinctr MinCattleFeedRequirement:array(WheatAndCorn) of splinctr SugarBeetProduction:splinctr SugarBeetQuota:splinctr end-declarations !stages spsetstages(Stages) forall(p in Products) spsetstage(yield(p),"Summ") !scenarios declarations S=3 Values:array(Products,1..S) of real end-declarations forall(s in 1..S) prob(s):=1/3 Values:=[3,2.5,2, 3.6,3,2.4, 24,20,16] if Explicit then ! if build scenarios explictly spcreatetree(S) spsetprobcond(2,prob) forall(p in Products,s in 1..S) spsetrandatnode(yield(p),s,Values(p,s)) spgentree else !alternatively use distributions spsetdist(union(p in Products) {yield(p)},Values,prob) spgenexhtree end-if !model TotalCost:=sum(p in Products) PlantingCost(p)*x(p)- sum(p in AllProducts) SellingPrice(p)*w(p)+ sum(p in WheatAndCorn)PurchasePrice(p)*y(p) LandUtilized:=sum(p in Products) x(p)<=TotalAvailableLand forall(p in WheatAndCorn) MinCattleFeedRequirement(p):=yield(p)*x(p)+y(p)- w(p)>=MinimumRequirement(p) SugarBeetProduction:=sum(p in {"SugBtFav","SugBtUnfav"}) w(p)<=yield("SugBt")*x("SugBt") SugarBeetQuota:=w("SugBtFav")<=MaxSugarBeetQuota forall(p in Products) spsetstage(x(p),"Wint") forall(p in WheatAndCorn) spsetstage(y(p),"Summ") forall(p in AllProducts) spsetstage(w(p),"Summ") !Analysis declarations Problem={"Rec","Exp Val","Exp Val w/t Rec","Perf Inf", "Perf Inf w/t Rec"} end-declarations setparam('xsp_scen_based',false) setparam('xsp_verbose',true) setparam('xsp_disp_warnings',false) !setparam('xsp_ive_enable',false) !scenario tree is not popped up evertime an optimization run happens forall(problem in Problem) Analyse(problem) procedure Analyse(problem:string) write(" Solving "+problem+" Problem") case problem of "Exp Val" : minimize(TotalCost,XSP_EV) "Exp Val w/t Rec" : minimize(TotalCost,XSP_EV+XSP_REC) "Perf Inf": minimize(TotalCost,XSP_PI) "Perf Inf w/t Rec":minimize(TotalCost,XSP_PI+XSP_REC) "Rec":minimize(TotalCost,XSP_REC) end-case writeln writeln("------------------------------------------") write("Culture |");forall(p in Products) write(strfmt(p,7)) writeln writeln("------------------------------------------") if(problem="Perf Inf") then forall(s in 1..spgetscencount) do write("Surface (acres) ",s," |"); forall(p in Products) write(strfmt(getsolinscen(x(p),s),7,2)); writeln end-do else write("Surface (acres) |"); forall(p in Products) write(strfmt(speval(x(p)),7,2)) writeln end-if writeln("TotalProfit=$",-getobjval, " [constant value in objective function=",spgetobjconst,"]") writeln("------------------------------------------") case problem of "Exp Val w/t Rec","Perf Inf w/t Rec": do forall(p in Products) spunfix(x(p)) spsethidden(LandUtilized,false) end-do end-case writeln end-procedure end-model