Principles of Optimization
Principles of Optimization Math 364
Popular in Course
Popular in Mathematics (M)
This 3 page Class Notes was uploaded by Ashley Ernser II on Thursday September 17, 2015. The Class Notes belongs to Math 364 at Washington State University taught by B. Krishnamoorthy in Fall. Since its upload, it has received 68 views. For similar materials see /class/205963/math-364-washington-state-university in Mathematics (M) at Washington State University.
Reviews for Principles of Optimization
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 09/17/15
Math364 March 3 2005 1 Introduction to AMPL Details of how to download and start up the student version of AMPL are given in httpwwwiamplicom Download and install AMPL in your PC if you do not have a PC you can submit your models online at the above web page but this procedure is rather inconvenient To solve problems using AMPL you will also have to download a solver such as CPLEX For Windows the solver is included in the zip le that you download amplcmlizip For UnixLinux you need to download cpleX separately details are given in the web page too Cplex is the preferred solver The rst chapter from the AMPL book is available as a PDF document from the above web page Go through the rst chapter in detail You can also borrow the book from me for additional reference AMPL Basics You need to create a model le for example FarmerJonesimod and a data le FarmerJonesidat The model le declares the parameters the variables objective function and the constraints in a symbolic fashion All the numbers actual data are provided in the data le Note the following 0 Every declaration of a parameter variables objective function or a constraint ends with a semicolon This is true for both the model and the data le 0 You can specify values for a parameter in the data le only if it is already declared 0 Before solving problems you need to specify the solver It is a good practice to start each AMPL session by typing option solver cplex at the ampl prompt Example The Farmer Jones problem Model le FarmerJonesimod AMPL model file for the Farmer Jones problem The LP is max Z 30 x1 100 x2 total revenue st x1 x2 lt 7 land available 4 x1 10 x2 lt 40 labor hrs 10 x1 gt 30 min corn x1 x2 gt 0 non negativity set Crops corn wheat param Yield j in Crops yield per acre param Labor j in Crops labor hrs per acre param Price j in Crops selling price per bushel param MinCrop j in Crops min levels of corn and wheat bushels param MaxAcres total land available acres param MaxHours total labor hrs available var X j in Crops gt 0 xcorn acres of corn Xwheat acres of wheat maximize totalrevenue sum j in Crops Price jYieldjxj subject to landconstraint sum j in Crops xj lt MaxAcres subject to laborconstraint sum j in Crops Laborjxj lt MaxHours subject to mincropconstraint j in Crops Yield jx j gt MinCrop j Math364 March 3 2005 Data le FarmerJones dat set Crops corn wheat param Yield corn 10 wheat 25 param Labor corn 4 wheat 10 param Price corn 3 wheat 4 param MinCrop corn 30 wheat 0 No minimum level specified for wheat param MaxAcres 7 param MaxHours 40 Output from AMPL session sw ampl ampl option solver cplex ampl model FarmerJonesmod data FarmerJonesdat ampl expand landconstraint subject to landconstraint x corn x wheat lt 7 ampl expand mincropconstraint subject to mincropconstraint corn 10x corn gt 30 subject to mincropconstraint wheat 25x wheat gt 0 ampl solve CPLEX 800 optimal solution objective 370 1 dual simplex iterations 1 in phase I ampl display x x 1 corn 3 wheat 28 ampl display totalrevenue totalrevenue 370 ampl Math364 March 22 2005 Fquot AMPL Further Tips 1 Notice that sum j in 1n Xj is the same as sum k in 1n XEk Similarly sum 1 in 1 2 j in 1 3 5 gives 30 ie we just add the number 5 for each value of i and j 7 thus adding the same number 2 X 3 6 times The model should be as generic abstract as possible For example in the Leary Chemicals problem 3 in HW 6 you could declare a parameter for the number of products made AB and C apart from the number of processes 1 and 2 In this way the Yield can be declared as a matrix parameter as opposed to declaring one vector parameter for each product separately Thus you could say param nProd param nProc No of products 3 for ABC No of processes 2 for process1 and process2 param Yield 1 in 1nProd j in 1nProc param Demand 1 in 1 nProd The demand constraints for all three products can be written in a single line here Notice how we use two di erent index sets using indices j and i for obtaining the sum of the term Yield 1 jxj and to repeat the constraint for each element in the set 1 nProd subject to DemCon i in 1 nProd sum j in 1nProc Yieldijxj gt DemandEi Equivalently you could declare a set of products and a set of processes You should avoid including actual parameter values when writing constraints in the model le For example some of you have written the worstcase return constraint from the Solodrex problem 4 in HW 6 as follows subject to MinWorstRet sum j in Bonds WCRet j x j gt sum j in Bonds XEj 8 The quantity 8 should be declared as a parameter say minWCret and initialized appropriately in the data e en writing the constraint in the model le you should use the name 0 t e parameter rather than its actual value The same rule applies to the average return and other similar constraints subject to Min7Worst7Ret sum j in Bonds Wci et jxj gt sum j in Bonds XjminWCret The idea of multiple indices or indexing sets can be used to write all in diversi cation constraints in one line subject to Diversify i in Bonds xi lt sum j in Bonds XEj DiversifyPercent where DiversifyPercent is the parameter set at 04 Several of you seemed to have struggled with Problem 5 from HW 6 Here is a brief outline of the model le param nicakes No of cakes 2 1 W CC 2 W BF param nimonths No of months 3 param Demand i in 1 nicakes j in 1 nimonths demand for both cakes for all 3 months param Cost i in 1ncakes j in 1nmonths cost for both cakes for all 3 months param Hold7Cost i in 1 nicakes holding cost for each cake same for all months param MonthiBakeiLimit max No of cakes baked in a month var x i in 1ncakes j in 1nmonths gt 0 it No of cakes of each type baked in each month var s i in 1ncakes j in 0nmonths gt 0 it No of cakes of each type held in inventory M Notice that we declare the variable 5 for each cake for month 0 too i and set these si0 values to 0 These dummy variables help us to write the constraints it in a nice way minimize TotaLCost sum 1 in 1ncakes j in 1nmonths Cost ijxij HoldCost isij W Note here that the same value of HoldCost i is used for each value of the index j subject to SetDummyToZero i in 1ncakes si0 subject to MaxiBake j in 1 nimonths 0 sum i in 1 nicakes Xij lt MonthiBakeiLimit39 subject to InviBalance i in 1ncakes j in 1nmonths sij xij sij1 Demandij