Post on 21-Nov-2021
transcript
1 ยฉ 2014 The MathWorks, Inc.
Mixed-integer linear programming in
MATLAB
Seth DeLand
2
Topics
Refresher on Mixed-integer linear programming (MILP)
Solving an MILP problem in MATLAB
MILP algorithms
Tuning the solver
3
MILP vs. LP
Linear Programming (linprog)
min๐ฅ
๐๐๐ฅ ๐ด๐ฅ โค ๐
๐ด๐๐๐ฅ = ๐๐๐๐๐ โค ๐ฅ โค ๐ข๐
s.t.
Mixed-integer LP (intlinprog)
min๐ฅ
๐๐๐ฅ ๐ด๐ฅ โค ๐
๐ด๐๐๐ฅ = ๐๐๐๐๐ โค ๐ฅ โค ๐ข๐
s.t.
Some (or all) ๐ฅ must be integers
[xopt,fval,eflag,output] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub,opts);
[xopt,fval,eflag,output] = linprog(f,A,b,Aeq,beq,lb,ub,opts);
4
Demo: Cash-flow matching
Idea: Buy bonds to cover pension
fund obligations
Variables: How many of each
bond to buy?
Constraints: Payments from
bonds must be greater than or
equal to pension fund obligations
Objective: Minimize the size of
the investment you make 1 2 3 4 5 6 7 80
20
40
60
80
100
120
Time Period
Ca
sh
Flo
w (
$)
1 2 3 4 5 6 7 80
5
10
15x 10
5
Time Period
Pa
ym
en
ts (
$)
5
๐1โฎ๐5
Extending the problem
โ๐๐๐ โ๐น๐๐๐ค๐
๐1โฎ๐5
โค โ๐๐๐๐๐๐๐ก๐๐๐๐
๐1โฎ๐5๐ฆ1โฎ๐ฆ5
1
0โฑ
0
1
โ1000
0โฑ
0
โ1000
๐1โฎ๐5๐ฆ1โฎ๐ฆ5
=0โฎ0
min๐ฅ
๐๐๐ฅ ๐ด๐ฅ โค ๐
๐ด๐๐๐ฅ = ๐๐๐๐๐ โค ๐ฅ โค ๐ข๐
s.t.
๐ฅ(intcon) must be integers ๐ฅ:
๐1 = 1000๐ฆ1
โฎ ๐5 = 1000๐ฆ5
โ๐๐๐ โ๐น๐๐๐ค๐ ๐ง๐๐๐๐ (8,5)
๐1โฎ
๐5๐ฆ1โฎ
๐ฆ5
โค โ๐๐๐๐๐๐๐ก๐๐๐๐
6
Recap
Better solution from intlinprog than rounding the
solution from linprog
Added binary variables
โ Allowed us to model โquantities of 1000โ
โ Updated sizes of constraint matrices and objective function
7
Demo: Index replication
C(i,j) : how closely is asset i related to asset j?
Correlation matrix
8
Index replication
Goal: pick a subset of assets based on correlations
โ If asset A is highly correlated with asset B, then we only need one
of them in our replicating portfolio
Each asset in the replicating portfolio represents one or
more assets in the universe
Optimization problem: select 20 assets for the
replicating portfolio that best represent the universe
9
Approach โ binary mask
1 0 0 0 0
0 0 0 1 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
x:
.*
1 0.18 0.71 0.48 0.23
0.18 1 0.33 0.54 0.44
0.71 0.33 1 0.12 0.31
0.48 0.54 0.12 1 0.63
0.23 0.44 0.31 0.63 1
C:
Constraints on x
Only a single 1 in each row
Only 2 columns that contain 1โs
Objective
Maximize sum(C.*x)
10
1 0 0 0 0
0 0 0 0.54 0
0.71 0 0 0 0
0 0 0 1 0
0 0 0 0.63 0
Approach โ binary mask
Constraints on x
Only a single 1 in each row
Only 2 columns that contain 1โs
Objective
Maximize sum(C.*x)
1 0 0 0 0
0 0 0 1 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
x:
.*
1 0.18 0.71 0.48 0.23
0.18 1 0.33 0.54 0.44
0.71 0.33 1 0.12 0.31
0.48 0.54 0.12 1 0.63
0.23 0.44 0.31 0.63 1
C: sum(C.*x) = 3.88
11
MILP formulation
Variables:
Constraints:
Objective:
๐ฅ๐,๐ 0 โ 1 is stock i represented by stock j ?
๐ฆ๐ 0 โ 1 is stock j in the replicating portfolio?
๐ฅ๐,๐ = 1
๐
๐=1
๐ฅ๐,๐ โ ๐ฆ๐ โค 0
๐
๐=1
max๐ฅ
๐ถ๐,๐๐ฅ๐,๐
๐
๐=1
๐
๐=1
๐ฆ๐ = 20
๐
๐=1
Only
one โ1โ
per row
Auxiliary
variables
12
MILP algorithm
LP
Preprocessing
Root LP
Cut Generation
Heuristics
Integer
Programming
Preprocessing
Branch and
Bound
Reduce the problem size
Solve the problem without integer constraints
Tighten LP relaxation
Further tighten LP relaxation
Try to find integer feasible solutions
Systematically search for optimal solution
13
Tuning options
LP
Preprocessing
Root LP
Cut Generation
Heuristics
Integer
Programming
Preprocessing
Branch and
Bound
LPPreprocess
RootLPAlgorithm, RootLPMaxIter
IPPreprocess
CutGeneration,
CutGenMaxIter
Heuristics,
HeuristicsMaxNodes
BranchingRule, LPMaxIter, MaxNodes,
MaxNumFeasPoints, NodeSelection
14
Recap
Found 20 assets that best represent universe
Large optimization problem: >100k binary variables
intlinprog algorithm consists of several steps
โ Change option values to tune solver
15
Key takeaways
intlinprog function for MILP (R2014a)
MILP gives better solutions than rounding LP solutions
Use auxiliary variables to expand scope of problems
Can solve large problems, but performance is problem
dependent