linprog
Solves a linear programming problem.
Calling Sequence
xopt = linprog(c,A,b) xopt = linprog(c,A,b,Aeq,beq) xopt = linprog(c,A,b,Aeq,beq,lb,ub) xopt = linprog(c,A,b,Aeq,beq,lb,ub,param) xopt = linprog(file) xopt = linprog(file,param) [xopt,fopt,exitflag,output,lambda] = linprog( ... )
Input Parameters
- c :
A vector of doubles, containing the coefficients of the variables in the objective function.
- A :
A matrix of doubles, containing the coefficients of linear inequality constraints of size (m X n) where 'm' is the number of linear inequality constraints.
- b :
A vector of doubles, related to 'A' and containing the the Right hand side equation of the linear inequality constraints of size (m X 1).
- Aeq :
A matrix of doubles, containing the coefficients of linear equality constraints of size (m1 X n) where 'm1' is the number of linear equality constraints.
- beq :
A vector of doubles, related to 'Aeq' and containing the the Right hand side equation of the linear equality constraints of size (m1 X 1).
- lb :
A vector of doubles, containing the lower bounds of the variables of size (1 X n) or (n X 1) where 'n' is the number of variables.
- ub :
A vector of doubles, containing the upper bounds of the variables of size (1 X n) or (n X 1) where 'n' is the number of variables.
- options :
A list, containing the option for user to specify. See below for details.
- file :
A string describing the path to the mps file.
Outputs
- xopt :
A vector of doubles, containing the computed solution of the optimization problem.
- fopt :
A double, containing the the function value at x.
- exitflag :
An integer, containing the flag which denotes the reason for termination of algorithm. See below for details.
- output :
A structure, containing the information about the optimization. See below for details.
- lambda :
A structure, containing the Lagrange multipliers of lower bound, upper bound and constraints at the optimized point. See below for details.
Description
Search the minimum of a constrained linear programming problem specified by :
OSI-CLP, an optimization library written in C++, is used for solving the linear programming problems.
Options
The options allow the user to set various parameters of the Optimization problem. The syntax for the options is given by:options= list("MaxIter", [---], "CpuTime", [---], "GradObj", ---, "Hessian", ---, "GradCon", ---);
The options should be defined as type "list" and consist of the following fields:
- MaxIter : A Scalar, specifying the Maximum Number of iterations that the solver should take.
The default values for the various items are given as:
options = list("MaxIter", [3000], "CpuTime", [600]);
The exitflag allows the user to know the status of the optimization which is returned by Ipopt. The values it can take and what they indicate is described below:
- 0 : Optimal Solution Found
- 1 : Primal Infeasible
- 2 : Dual Infeasible
- 3 : Maximum Number of Iterations Exceeded. Output may not be optimal.
- 4 : Solution Abandoned
- 5 : Primal objective limit reached.
- 6 : Dual objective limit reached.
The output data structure contains detailed information about the optimization process. It is of type "struct" and contains the following fields.
- output.Iterations: The number of iterations performed.
- output.constrviolation: The max-norm of the constraint violation.
The lambda data structure contains the Lagrange multipliers at the end of optimization. In the current version the values are returned only when the the solution is optimal. It has type "struct" and contains the following fields.
- lambda.lower: The Lagrange multipliers for variable lower bounds.
- lambda.eqlin: The Lagrange multipliers for the linear equality constraints.
- lambda.ineqlin: The Lagrange multipliers for the linear inequality constraints.
A few examples displaying the various functionalities of linprog have been provided below. You will find a series of problems and the appropriate code snippets to solve them.
Example
Here we solve a simple objective function, subjected to six linear inequality constraints.
Find x in R^2 such that it minimizes:
Example
Here we build up on the previous example by adding linear equality constraints. We add the following constraints to the problem specified above:
//Example 2: Linear program with Linear Inequalities and Equalities` c=[-1,-1/3]' A=[1,1;1,1/4;1,-1;-1/4,-1;-1,-1;-1,1] b=[2,1,2,1,-1,2] Aeq=[1,1/4] beq=[1/2] [xopt,fopt,exitflag,output,lambda]=linprog(c, A, b, Aeq, beq) // Press ENTER to continue |
Example
In this example, we proceed to add the upper and lower bounds to the objective function.
//Example 3: Linear program with all constraint types c=[-1,-1/3]' A=[1,1;1,1/4;1,-1;-1/4,-1;-1,-1;-1,1] b=[2,1,2,1,-1,2] Aeq=[1,1/4] beq=[1/2] lb=[-1,-0.5] ub=[1.5,1.25] [xopt,fopt,exitflag,output,lambda]=linprog(c, A, b, Aeq, beq, lb, ub) // Press ENTER to continue |
Example
Primal Infeasible Problems: Find x in R^3 such that it minimizes:
//Example 4: Primal Infeasible Problem c=[-1,-1,-1]' A=[1,2,-1] b=[-4] Aeq=[1,5,3;1,1,0] beq=[10,100] lb=[0,0,0] ub=[%inf,%inf,%inf] [xopt,fopt,exitflag,output,lambda]= linprog(c,A,b,Aeq,beq,lb,ub) // Press ENTER to continue |
Example
Unbounded Problems: Find x in R^3 such that it minimizes:
//Example 5: Unbounded Problem c=[3,5,-7]' A=[-1,-1,4;1,1,4] b=[-8,5] Aeq=[] beq=[] lb=[-%inf,-%inf,-%inf] ub=[%inf,%inf,%inf] [xopt,fopt,exitflag,output,lambda]= linprog(c,A,b,Aeq,beq,lb,ub) // Press ENTER to continue |
Example
filepath = get_absolute_file_path('linprog.dem.sce'); filepath = filepath + "exmip1.mps" [xopt,fopt,exitflag,output,lambda] =linprog(filepath) |
Authors
- Bhanu Priya Sayal, Guru Pradeep Reddy