Mixed-integer linear programming in MATLAB

Post on 21-Nov-2021

11 views 0 download

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