You can specify f, intcon, lb, and ub as vectors or arrays. See Matrix Arguments.
Syntax
x = intlinprog(f,intcon,A,b)
example
x = intlinprog(f,intcon,A,b,Aeq,beq)
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
example
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub,options)
example
x = intlinprog(problem)
example
[x,fval,exitflag,output] = intlinprog(___)
example
Description
example
x = intlinprog(f,intcon,A,b) solves min f'*x such that the components of x in intcon are integers,
and A*x b.
x = intlinprog(f,intcon,A,b,Aeq,beq) solves the problem above while additionally satisfying the equality
constraints Aeq*x = beq. Set A = [] and b = []if no inequalities exist.
example
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design
variables, x, so that the solution is always in the rangelb x ub. Set Aeq = [] and beq = [] if no equalities
exist.
example
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub,options) minimizes using the optimization options
specified in options. Use optimoptions to set these options. Set lb = [] and ub = [] if no bounds exist.
example
x = intlinprog(problem) uses a problem structure to encapsulate all solver inputs. You can import
a problem structure from an MPS file using mpsread.
example
[x,fval,exitflag,output] = intlinprog(___), for any input arguments described above,
returns fval = f'*x, a value exitflag describing the exit condition, and a structure output containing
information about the optimization process.
Examples
collapse all
Solve an MILP with Linear Inequalities
Open This Example
f = [8;1];
intcon = 2;
Convert all inequalities into the form A*x <= b by multiplying "greater than" inequalities by -1.
A = [-1,-2;
-4,-1;
2,1];
b = [14;-33;20];
Call intlinprog.
x = intlinprog(f,intcon,A,b)
Intlinprog stopped at the root node because the objective value is within a gap
tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default
value). The intcon variables are integer within tolerance,
options.IntegerTolerance = 1e-05 (the default value).
x =
6.5000
7.0000
f = [-3;-2;-1];
intcon = 3;
A = [1,1,1];
b = 7;
Aeq = [4,2,1];
beq = 12;
lb = zeros(3,1);
ub = [Inf;Inf;1]; % Enforces x(3) is binary
Call intlinprog.
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
Intlinprog stopped at the root node because the objective value is within a gap
tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default
value). The intcon variables are integer within tolerance,
options.IntegerTolerance = 1e-05 (the default value).
x =
0
5.5000
1.0000
f = [-3;-2;-1];
intcon = 3;
A = [1,1,1];
b = 7;
Aeq = [4,2,1];
beq = 12;
lb = zeros(3,1);
ub = [Inf;Inf;1]; % enforces x(3) is binary
Specify no display.
options = optimoptions('intlinprog','Display','off');
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub,options)
x =
0
5.5000
1.0000
f = [-3;-2;-1];
intcon = 3;
A = [1,1,1];
b = 7;
Aeq = [4,2,1];
beq = 12;
lb = zeros(3,1);
ub = [Inf;Inf;1]; % enforces x(3) is binary
options = optimoptions('intlinprog','Display','off');
Insert the inputs into a problem structure. Include the solver name.
problem = struct('f',f,'intcon',intcon,...
'Aineq',A,'bineq',b,'Aeq',Aeq,'beq',beq,...
'lb',lb,'ub',ub,'options',options,...
'solver','intlinprog');
x = intlinprog(problem)
x =
0
5.5000
1.0000
Call intlinprog with more outputs to see solution details and process.
f = [-3;-2;-1];
intcon = 3;
A = [1,1,1];
b = 7;
Aeq = [4,2,1];
beq = 12;
lb = zeros(3,1);
ub = [Inf;Inf;1]; % enforces x(3) is binary
[x,fval,exitflag,output] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
Intlinprog stopped at the root node because the objective value is within a gap
tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default
value). The intcon variables are integer within tolerance,
options.IntegerTolerance = 1e-05 (the default value).
x =
0
5.5000
1.0000
fval =
-12.0000
exitflag =
output =
relativegap: 0
absolutegap: 0
numfeaspoints: 1
numnodes: 0
constrviolation: 1.7764e-15
message: 'Optimal solution found....'
The output structure shows numnodes is 0. This means intlinprog solved the problem before branching. This is
one indication that the result is reliable. Also, the absolutegap and relativegap fields are 0. This is another
indication that the result is reliable.
Related Examples
Mixed-Integer Linear Programming Basics
Factory, Warehouse, Sales Allocation Model
Travelling Salesman Problem
Solve Sudoku Puzzles Via Integer Programming
Mixed-Integer Quadratic Programming Portfolio Optimization
Optimal Dispatch of Power Generators
Input Arguments
collapse all
f Coefficient vectorreal vector
Coefficient vector, specified as a vector of doubles representing the objective function, f'*x. The notation assumes
that f is a column vector, but you are free to use a row vector.
f can also be an array. Internally, intlinprog converts an array f to the vector f(:).
If you specify f = [], intlinprog tries to find a feasible point without trying to minimize an objective function.
Example: f = [4;2;-1.7];
intcon can also be an array. Internally, intlinprog converts an array intcon to the vector intcon(:).
Example: intcon = [1,2,7] means x(1), x(2), and x(7) take only integer values.
Example: A = [4,3;2,0;4,-1]; means three linear inequalities (three rows) for two decision variables (two
columns).
Example: [4,0]
Example: A = [4,3;2,0;4,-1]; means three linear inequalities (three rows) for two decision variables (two
columns).
Example: [4,0]
Some options are absent from the optimoptions display. These options are listed in italics. For details, see View
Options.
Option Description
AbsoluteGapTolerance Nonnegative real. intlinprog stops if the difference between the internally ca
upper (U) and lower (L) bounds on the objective function is less than or equal
toAbsoluteGapTolerance:
U L <= AbsoluteGapTolerance .
BranchRule Rule for choosing the component for branching:
'maxpscost' The fractional component with maximum pseudocost. See B
Bound.
'mostfractional' The component whose fractional part is closest to 1/2.
'maxfun' The fractional component with maximal corresponding compone
absolute value of objective vector f.
ConstraintTolerance Real from 1e-9 through 1e-3 that is the maximum discrepancy that linear con
have and still be considered satisfied. ConstraintTolerance is not a stopping
CutGeneration Level of cut generation (see Cut Generation):
'none' No cuts. Makes CutGenMaxIter irrelevant.
'basic' Normal cut generation.
'intermediate' Use more cut types.
'advanced' Use most cut types.
CutMaxIterations Number of passes through all cut generation methods before entering the bran
bound phase, an integer from 1 through 50. Disable cut generation by setting
the CutGenerationoption to 'none'.
Display Level of display (see Iterative Display):
'off' or 'none' No iterative display
'final' Show final values only
'iter' Show iterative display
Heuristics Algorithm for searching for feasible points (see Heuristics for Finding Feasib
'none'
'rss'
'round'
'rins'
HeuristicsMaxNodes Strictly positive integer that bounds the number of nodes intlinprog can exp
branch-and-bound search for feasible points. See Heuristics for Finding Feasi
Solutions.
Option Description
f
intcon
solver
options
Example: problem.f = [1,2,3];
problem.intcon = [2,3];
problem.options = optimoptions('intlinprog');
problem.Aineq = [-3,-2,-1];
problem.bineq = -20;
problem.lb = [-6.1,-1.2,7.3];
problem.solver = 'intlinprog';
Output Arguments
collapse all
x Solutionreal vector
Solution, returned as a vector that minimizes f'*x subject to all bounds, integer constraints, and linear constraints.
relativegap Relative difference between upper (U) and lower (L) bounds of the objective function that int
and-bound algorithm.
relativegap = (U - L) / (abs(U) + 1)
Caution Rounding solutions can cause the solution to become infeasible. Check feasibility after rounding:
max(A*x - b) % See if entries are not too positive, so have small infeasibility
max(abs(Aeq*x - beq)) % See if entries are near enough to zero
max(x - ub) % Positive entries are violated bounds
max(lb - x) % Positive entries are violated bounds
intlinprog does not enforce that solution components be integer-valued when their absolute values
exceed 2.1e9. When your solution has such components, intlinprogwarns you. If you receive this warning,
check the solution to see whether supposedly integer-valued components of the solution are close to integers.
intlinprog does not allow components of the problem, such as coefficients in f, A, or ub, to exceed 1e25 in
absolute value. If you try to run intlinprog with such a problem,intlinprog issues an error.
Currently, you cannot run intlinprog in the Optimization app.
More About
collapse all
MILP
Mixed-integer linear programming definition.
You can specify f, intcon, lb, and ub as vectors or arrays. See Matrix Arguments.
Tips
To specify binary variables, set the variables to be integers in intcon, and give them lower bounds of 0 and upper
bounds of 1.
Save memory by specifying sparse linear constraint matrices A and Aeq. However, you cannot use sparse matrices
for b and beq.
To provide logical indices for integer components, meaning a binary vector with 1 indicating an integer, convert
to intcon form using find. For example,
logicalindices = [1,0,0,1,1,0,0];
intcon = find(logicalindices)
intcon =
1 4 5
intlinprog replaces bintprog. To update old bintprog code to use intlinprog, make the following
changes:
o Set intcon to 1:numVars, where numVars is the number of variables in your problem.
o Set lb to zeros(numVars,1).
o Set ub to ones(numVars,1).
o Update any relevant options. Use optimoptions to create options for intlinprog.
o Change your call to bintprog as follows:
o [x,fval,exitflag,output] = bintprog(f,A,b,Aeq,Beq,x0,options)
o % Change your call to:
[x,fval,exitflag,output] = intlinprog(f,intcon,A,b,Aeq,Beq,lb,ub,options)
See Also
linprog | mpsread | optimoptions
Introduced in R2014a