You are on page 1of 11

30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France

intlinprog
Mixed-integer linear programming (MILP)

Mixed-integer linear programming solver.

Finds the minimum of a problem specified by




x(intcon) are integers


Axb
min f T x subject to
x
Aeq x = beq

lb x ub.
f, x, intcon, b, beq, lb, and ub are vectors, and A and Aeq are matrices.

You can specify f, intcon, lb, and ub as vectors or arrays. See Matrix Arguments.

Syntax

x = intlinprog(f,intcon,A,b)
x = intlinprog(f,intcon,A,b,Aeq,beq)
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub,options)
x = intlinprog(problem)
[x,fval,exitflag,output] = intlinprog( ___ )

Description
x = intlinprog(f,intcon,A,b) solves min f'*x such that the components of x in intcon are integers, and A*x b. example

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 range lb 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

Solve the problem


Try this Example

Write the objective function vector and vector of integer variables.

f = [8;1];
intcon = 2;

Convert all inequalities into the form A*x <= b by multiplying "greater than" inequalities by -1.

https://fr.mathworks.com/help/optim/ug/intlinprog.html 1/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France

A = [-1,-2;
-4,-1;
2,1];
b = [14;-33;20];

Call intlinprog.

x = intlinprog(f,intcon,A,b)

LP: Optimal objective value is 59.000000.

Optimal solution found.

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, optio
x =

6.5000
7.0000

Solve an MILP with All Types of Constraints

Solve the problem


Try this Example

Write the objective function vector and vector of integer variables.

f = [-3;-2;-1];
intcon = 3;

Write the linear inequality constraints.

A = [1,1,1];
b = 7;

Write the linear equality constraints.

Aeq = [4,2,1];
beq = 12;

Write the bound constraints.

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)

LP: Optimal objective value is -12.000000.

Optimal solution found.

https://fr.mathworks.com/help/optim/ug/intlinprog.html 2/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France

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, optio
x =

0
5.5000
1.0000

Solve an MILP with Nondefault Options

Solve the problem


Try this Example

without showing iterative display.

Specify the solver inputs.

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');

Run the solver.

x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub,options)

x =

0
5.5000
1.0000

Use a Problem Structure

Solve the problem


Try this Example

using iterative display. Use a problem structure as the intlinprog input.

Specify the solver inputs.

https://fr.mathworks.com/help/optim/ug/intlinprog.html 3/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France

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');

Run the solver.

x = intlinprog(problem)

x =

0
5.5000
1.0000

Examine the MILP Solution and Process

Call intlinprog with more outputs to see solution details and process.
Try this Example
The goal is to solve the problem

Specify the solver inputs.

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 with all outputs.

[x,fval,exitflag,output] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)

LP: Optimal objective value is -12.000000.

Optimal solution found.

https://fr.mathworks.com/help/optim/ug/intlinprog.html 4/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France

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, optio
x =

0
5.5000
1.0000

fval = -12.0000
exitflag = 1
output = struct with fields:
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.

Input Arguments collapse all

f Coefficient vector
real vector | real array

Coefficient vector, specified as a real vector or real array. The coefficient vector represents the objective function f'*x. The notation assumes that f is a column vector, but you are free to use a row vector or array. Internally, linprog converts f to the column
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];

Data Types: double

intcon Vector of integer constraints


vector of integers

Vector of integer constraints, specified as a vector of positive integers. The values in intcon indicate the components of the decision variable x that are integer-valued. intcon has values from 1 through numel(f).

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.

Data Types: double

A Linear inequality constraint matrix


real matrix

Linear inequality constraint matrix, specified as a matrix of doubles. A represents the linear coefficients in the constraints A*x b. A has size M-by-N, where M is the number of constraints and N = numel(f). To save memory, A can be sparse.

Example: A = [4,3;2,0;4,-1]; means three linear inequalities (three rows) for two decision variables (two columns).

Data Types: double

b Linear inequality constraint vector


real vector

https://fr.mathworks.com/help/optim/ug/intlinprog.html 5/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France

Linear inequality constraint vector, specified as a vector of doubles. b represents the constant vector in the constraints A*x b. b has length M, where A is M-by-N.

Example: [4,0]

Data Types: double

Aeq Linear equality constraint matrix


[] (default) | real matrix

Linear equality constraint matrix, specified as a matrix of doubles. Aeq represents the linear coefficients in the constraints Aeq*x = beq. Aeq has size Meq-by-N, where Meq is the number of constraints and N = numel(f). To save memory, Aeq can be sparse.

Example: A = [4,3;2,0;4,-1]; means three linear inequalities (three rows) for two decision variables (two columns).

Data Types: double

beq Linear equality constraint vector


[] (default) | real vector

Linear equality constraint vector, specified as a vector of doubles. beq represents the constant vector in the constraints Aeq*x = beq. beq has length Meq, where Aeq is Meq-by-N.

Example: [4,0]

Data Types: double

lb Lower bounds
[] (default) | real vector or array

Lower bounds, specified as a vector or array of doubles. lb represents the lower bounds elementwise in lb x ub.

Internally, intlinprog converts an array lb to the vector lb(:).

Example: lb = [0;-Inf;4] means x(1) 0, x(3) 4.

Data Types: double

ub Upper bounds
[] (default) | real vector or array

Upper bounds, specified as a vector or array of doubles. ub represents the upper bounds elementwise in lb x ub.

Internally, intlinprog converts an array ub to the vector ub(:).

Example: ub = [Inf;4;10] means x(2) 4, x(3) 10.

Data Types: double

options Options for intlinprog


options created using optimoptions

Options for intlinprog, specified as the output of optimoptions.

Some options are absent from the optimoptions display. These options are listed in italics. For details, see View Options.

Option Description Default

https://fr.mathworks.com/help/optim/ug/intlinprog.html 6/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France
AbsoluteGapTolerance Nonnegative real. intlinprog stops if the difference between the internally calculated upper (U) and lower (L) bounds on the objective function is less than or equal 0
to AbsoluteGapTolerance:
U L <= AbsoluteGapTolerance.

BranchRule Rule for choosing the component for branching: 'maxpscost'


'maxpscost' The fractional component with maximum pseudocost. See Branch and Bound.
'mostfractional' The component whose fractional part is closest to 1/2.
'maxfun' The fractional component with maximal corresponding component in the absolute value of objective vector f.

ConstraintTolerance Real from 1e-9 through 1e-3 that is the maximum discrepancy that linear constraints can have and still be considered satisfied. ConstraintTolerance is not a 1e-4
stopping criterion.

CutGeneration Level of cut generation (see Cut Generation): 'basic'


'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 branch-and-bound phase, an integer from 1 through 50. Disable cut generation by setting 10
the CutGeneration option to 'none'.

Display Level of display (see Iterative Display): 'iter'


'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 Feasible Solutions): 'basic'
'basic'
'intermediate'
'advanced'
'rss'
'rins'
'round'
'diving'
'rss-diving'
'rins-diving'
'round-diving'
'none'

HeuristicsMaxNodes Strictly positive integer that bounds the number of nodes intlinprog can explore in its branch-and-bound search for feasible points. Applies only to 'rss' and 50
'rins'. See Heuristics for Finding Feasible Solutions.

IntegerPreprocess Types of integer preprocessing (see Mixed-Integer Program Preprocessing): 'basic'


'none' Use very few integer preprocessing steps.
'basic' Use a moderate number of integer preprocessing steps.
'advanced' Use all available integer preprocessing steps.

IntegerTolerance Real from 1e-6 through 1e-3, where the maximum deviation from integer that a component of the solution x can have and still be considered an integer. 1e-5
IntegerTolerance is not a stopping criterion.

LPMaxIterations Strictly positive integer, the maximum number of simplex algorithm iterations per node during the branch-and-bound process. 3e4

LPOptimalityTolerance Nonnegative real where reduced costs must exceed LPOptimalityTolerance for a variable to be taken into the basis. 1e-7

LPPreprocess Type of preprocessing for the solution to the relaxed linear program (see Linear Program Preprocessing): 'basic'
'none' No preprocessing.
'basic' Use preprocessing.

MaxNodes Strictly positive integer that is the maximum number of nodes intlinprog explores in its branch-and-bound process. 1e7

MaxFeasiblePoints Strictly positive integer. intlinprog stops if it finds MaxFeasiblePoints integer feasible points. Inf

MaxTime Positive real that is the maximum time in seconds that intlinprog runs. 7200

https://fr.mathworks.com/help/optim/ug/intlinprog.html 7/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France
NodeSelection Choose the node to explore next. 'simplebestproj'
'simplebestproj' Best projection. See Branch and Bound.
'minobj' Explore the node with the minimum objective function.
'mininfeas' Explore the node with the minimal sum of integer infeasibilities. See Branch and Bound.

ObjectiveCutOff Real greater than -Inf. During the branch-and-bound calculation, intlinprog discards any node where the linear programming solution has an objective value Inf
exceeding ObjectiveCutOff.

ObjectiveImprovementThreshold Nonnegative real. intlinprog changes the current feasible solution only when it locates another with an objective function value that is at least 1e-4
ObjectiveImprovementThreshold lower: (fold fnew)/(1 + fold) > ObjectiveImprovementThreshold.

OutputFcn Specify one or more functions that an optimization function calls at events, either as a function handle or as a cell array of function handles. []

@savemilpsolutions collects the integer-feasible points in the xIntSol matrix in your workspace, where each column is one integer feasible point.

For information on writing a custom output function, see intlinprog Output Functions and Plot Functions.

PlotFcn Plots various measures of progress while the algorithm executes, select from predefined plots or write your own. Pass a function handle or a cell array of function []
handles.

@optimplotmilp plots the internally-calculated upper and lower bounds on the objective value of the solution.

For information on writing a custom plot function, see intlinprog Output Functions and Plot Functions.

RelativeGapTolerance Real from 0 through 1. intlinprog stops if the relative difference between the internally calculated upper (U) and lower (L) bounds on the objective function is less 1e-4
than or equal to RelativeGapTolerance:
(U L) / (abs(U) + 1) <= RelativeGapTolerance.

intlinprog automatically modifies the tolerance for large L magnitudes:

tolerance = min(1/(1+|L|), RelativeGapTolerance)

Note: While you specify RelativeGapTolerance as a decimal number, the iterative display and output.relativegap report the gap in percentage, meaning 100 times the
measured relative gap. If the exit message refers to the relative gap, this value is the measured relative gap, not a percentage.

RootLPAlgorithm Algorithm for solving linear programs: 'dual-simplex'


'dual-simplex' Dual simplex algorithm
'primal-simplex' Primal simplex algorithm

RootLPMaxIterations Nonnegative integer that is the maximum number of simplex algorithm iterations to solve the initial linear programming problem. max(3e4, 10*(numberOfEqualities +
numberOfInequalities + numberOfVariables))

In this expression, numberOfEqualities means the number of


rows of Aeq, numberOfInequalities means the number of rows
of A, and numberOfVariables means the number of elements of
f.

Example: options = optimoptions('intlinprog','MaxTime',120)

problem Structure encapsulating inputs and options


structure

Structure encapsulating the inputs and options, specified with the following fields.

f Vector representing objective f'*x (required)

intcon Vector indicating variables that take integer values (required)

Aineq Matrix in linear inequality constraints Aineq*x bineq

bineq Vector in linear inequality constraints Aineq*x bineq

Aeq Matrix in linear equality constraints Aeq*x = beq

beq Vector in linear equality constraints Aeq*x = beq

lb Vector of lower bounds

ub Vector of upper bounds

solver 'intlinprog' (required)

https://fr.mathworks.com/help/optim/ug/intlinprog.html 8/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France
options Options created using optimoptions (required)

You must specify at least these fields in the problem structure. Other fields are optional:

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';

Data Types: struct

Output Arguments collapse all

x Solution
real vector

Solution, returned as a vector that minimizes f'*x subject to all bounds, integer constraints, and linear constraints.

When a problem is infeasible or unbounded, x is [].

fval Objective value


real scalar

Objective value, returned as the scalar value f'*x at the solution x.

When a problem is infeasible or unbounded, fval is [].

exitflag Algorithm stopping condition


integer

Algorithm stopping condition, returned as an integer identifying the reason the algorithm stopped. The following lists the values of exitflag and the corresponding reasons intlinprog stopped.

2 intlinprog stopped prematurely. Integer feasible point found.

1 intlinprog converged to the solution x.

0 intlinprog stopped prematurely. No integer feasible point found.

-1 intlinprog stopped by an output function or plot function.

-2 No feasible point found.

-3 Root LP problem is unbounded.

The exit message can give more detailed information on the reason intlinprog stopped, such as exceeding a tolerance.

output Solution process summary


structure

Solution process summary, returned as a structure containing information about the optimization process.

https://fr.mathworks.com/help/optim/ug/intlinprog.html 9/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France
relativegap Relative percentage difference between upper (U) and lower (L) bounds of the objective function that intlinprog calculates in its branch-and-bound algorithm.

relativegap = 100*(U - L) / (abs(U) + 1)

If intcon = [], relativegap = [].

Note: While you specify RelativeGapTolerance as a decimal number, the iterative display and output.relativegap report the gap in percentage, meaning 100 times the
measured relative gap. If the exit message refers to the relative gap, this value is the measured relative gap, not a percentage.

absolutegap Difference between upper and lower bounds of the objective function that intlinprog calculates in its branch-and-bound algorithm.

If intcon = [], absolutegap = [].

numfeaspoints Number of integer feasible points found.

If intcon = [], numfeaspoints = []. Also, if the initial relaxed problem is infeasible, numfeaspoints = [].

numnodes Number of nodes in branch-and-bound algorithm. If the solution was found during preprocessing or during the initial cuts, numnodes = 0.

If intcon = [], numnodes = [].

constrviolation Constraint violation that is positive for violated constraints.

constrviolation = max([0; norm(Aeq*x-beq, inf); (lb-x); (x-ub); (Ai*x-bi)])

message Exit message.

Limitations
Often, some supposedly integer-valued components of the solution x(intCon) are not precisely integers. intlinprog deems as integers all solution values within IntegerTolerance of an integer.
To round all supposed integers to be exactly integers, use the round function.

x(intcon) = round(x(intcon));

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, intlinprog warns 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.

MILP means find the minimum of a problem specified by




x(intcon) are integers


T
Axb
min f x subject to
x
Aeq x = beq

lb x ub.
f, x, intcon, b, beq, lb, and ub are vectors, and A and Aeq are matrices.

You can specify f, intcon, lb, and ub as vectors or arrays. See Matrix Arguments.

Tips

https://fr.mathworks.com/help/optim/ug/intlinprog.html 10/11
30/08/2017 Mixed-integer linear programming (MILP) - MATLAB intlinprog - MathWorks France
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:

Set intcon to 1:numVars, where numVars is the number of variables in your problem.
Set lb to zeros(numVars,1).
Set ub to ones(numVars,1).
Update any relevant options. Use optimoptions to create options for intlinprog.
Change your call to bintprog as follows:

[x,fval,exitflag,output] = bintprog(f,A,b,Aeq,Beq,x0,options)
% Change your call to:
[x,fval,exitflag,output] = intlinprog(f,intcon,A,b,Aeq,Beq,lb,ub,options)

See Also
linprog | mpsread | optimoptions

Topics
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
Mixed-Integer Linear Programming Algorithms
Tuning Integer Linear Programming
Optimization Problem Setup

Introduced in R2014a

https://fr.mathworks.com/help/optim/ug/intlinprog.html 11/11

You might also like