AMPL Integer Linear Programming And Sensitivity Analysis for LP ORLAB Operations Research Laboratory Borzou Rostami Politecnico di Milano, Italy December 6, 2012
Integer Programming: Many linear programming problems require certain variables to have whole number, or integer, values. Such a requirement arises naturally when the variables represent entities like packages or people that cannot be fractionally divided - at least, not in a meaningful way for the situation being modeled. Integer variables also play a role in formulating equation systems that model logical conditions. Integer variables Consider the diet problem in session 2. ampl: model diet.mod; data diet.dat; ampl: solve; CPLEX 11.2.0: optimal solution; objective 3.37 1 dual simplex iterations (0 in phase I) ampl: print{j in J} (j,x[j]); Bread 4 Milk 3 Eggs 1 Meat 1.5000000000000002 Cake 0 We want the foods to be purchased in integral amounts.
By adding the keyword integer to the qualifying phrases of a var declaration, you restrict the declared variables to integer values. (var x{j in J} integer >= 0, <= q[j];) We can then try to re-solve: ampl: model diet.mod; data diet.dat; solve; CPLEX 11.2.0: optimal integer solution; objective 3.62 1 MIP simplex iterations 0 branch-and-bound nodes ampl: print {j in J} (j,x[j]); Bread 2 Milk 3 Eggs 1 Meat 2 Cake 0 Comparing this solution to the previous one, we see a few features typical of integer programming.
The minimum cost has increased from 3.37 to 3.62; because integrality is an additional constraint on the values of the variables, it can only make the objective less favorable. The amounts of the different foods in the diet have also changed. Meat that had fractional amounts in the original optimum, have increased from 1.5000000000000002 to 2. Bread has dropped from the upper limit of 4 to 2. Note: Clearly, you cannot always deduce the integer optimum by rounding the noninteger optimum to the closest integer values.
Binary Variables: Set covering Problem: In the set covering problem, we are given a universe U, such that U = n, and the sets,..., U. Set Cover: A set cover is a collection S of some of the sets from,..., whose union is the entire universe U. Formally, S is a set cover if. If be the cost associated to set e would like to select a set cover S with the minimum cost.
Example: Suppose U= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and = {1, 2, 3, 8, 9, 10}, = {1, 2, 3, 4, 5}, = {4, 5, 7}, = {5, 6, 7}, and = {6, 7, 8, 9, 10}. Find a set cover with a minimum cost.
{ { Formulation: S.t. { }
AMPL model file (Setcovering.mod)
AMPL data file (Setcovering.dat)
Fixed Cost problem: Gandy Cloth Company is capable of manufacturing three types of clothing: Shirts, shorts, and pants. The manufacture of each type of clothing requires that Gandy have the appropriate type of machinery available. This machinery can be rented at the following rates: shirt machinery, $200/week; shorts machinery, $150/week; pants machinery, $100/week. Each type of clothing requires the amount of cloth and labor given in the table below. The sales price and variable cost are also given in the table. Labor Hours Cloth (sq. m) Sales Price Variable Cost Shirts 3 4 $12 $6 Shorts 2 3 $8 $4 Pants 6 4 $15 $8 Available: 150 hours 160 sq. m Given an integer linear programming formulation for the problem
Formulation: : The quantity of clothing of type j { { }
AMPL data file (Fixedcost.dat)
Assignment Problem: A company has 4 machines available for assignment to 4 tasks. Any machine can be assigned to any task, and each task requires processing by one machine. The time required to set up each machine for the processing of each task is given in the table below. TIME (Hours) Task1 Task2 Task3 Task4 Machine1 13 4 7 6 Machine2 1 11 5 4 Machine3 6 7 2 8 Machine4 1 3 5 9 The company wants to minimize the total setup time needed for the processing of all four tasks.
{ Formulation: S.t. { }
AMPL model file (assignment.mod)
AMPL data file (assignment.dat)
MINOS 5.5: ignoring integrality of 16 variables MINOS 5.5: optimal solution found. 8 iterations, objective 11 ampl: option solver cplex; ampl: solve; CPLEX 11.2.0: optimal integer solution; objective 11 5 MIP simplex iterations 0 branch-and-bound nodes ampl: option omit_zero_rows 1; ampl: display x; x := Machine1 Task2 1 Machine2 Task4 1 Machine3 Task3 1 Machine4 Task1 1 ;
Uncapacitated Facility Location (UFL) Given a set of potential depots and a set of clients (or customers), suppose there is a fixed cost associated with the use of depot j, and a transportation cost if all of client i s order is delivered from depot j. The problem is to decide which depots to open, and which depots serves each client so as to minimize the sum of fixed and transportation cost.
AMPL commands for Sensitivity Analysis -------------------------------------- option presolve 0; option solver cplex; option cplex_options sensitivity presolve=0 ; 1- display <var name>.rc; Displays the reduced cost of the variable named <var name>. 2- display <var name>.down ; Displays, respectively, the lower and upper endpoints of display <var name>.up; the range of the objective-function coefficient of the variable named <var name> for which the current basis remains optimal.
3- display <var name>.current; Displays the current value of the objective-function coefficient of the variable named <var name>. 4- display <constr name>; Displays the shadow price of the constraint <constr name>. 5- display <constr name>.down; Displays, respectively, the lower and upper endpoints of display <constr name>.up; the range of the right-hand-side of the constraint named <constr name> for which the current basis remains feasible, and hence optimal. 6- display <constr name>.current; Displays the current value of the right-hand-side of the constraint named <constr name>.
7- display <constr name>.slack; Displays the slack in the constraint named <constr name>. 8- let <name>:=<value>; Assigns the variable or parameter named <name> the <value>. Useful for making small changes to the LP For larger changes, use "reset data; data <new data-file>;" Remember that the theory of sensitivity analysis is developed only for linear programs. If integer variables are present, it can only be carried out for the corresponding continuous relaxation. In such case, add the command option relax integrality 1 ;
Some useful AMPL commands ------------------------- expand; Displays the current LP model with the instantiated data. Useful for debugging and in sensitivity analysis to know which LP AMPL is really solving. Can also type "expand <name>;", where <name> is the name of a constraint or objective function to display only the given constraint or objective function instantiated with data. show; Displays the names of the sets, parameters, variables, constraints, and objective function of current LP model. Can also type "show <name>;" where <name> is the name of a set, parameter, variable, constraint or objective function.
reset; AMPL always works with a current LP model, and "reset;" resets the current AMPL LP to the empty LP. Useful if you want to solve multiple LPs in the same session. reset data; Resets only the data of the current LP model retaining the model.
Downloading AMPL Student Edition Software http://www.ampl.com/downloads/ My Email Address rostami@elet.polimi.it Lab session web site http://home.dei.polimi.it/rostami/lab2012/lab4como.pdf http://home.dei.polimi.it/rostami/lab2012/lab4como2.pdf