+ All Categories
Home > Documents > Mixed-integer linear programming in MATLAB

Mixed-integer linear programming in MATLAB

Date post: 21-Nov-2021
Category:
Upload: others
View: 11 times
Download: 0 times
Share this document with a friend
15
1 © 2014 The MathWorks, Inc. Mixed-integer linear programming in MATLAB Seth DeLand
Transcript
Page 1: Mixed-integer linear programming in MATLAB

1 © 2014 The MathWorks, Inc.

Mixed-integer linear programming in

MATLAB

Seth DeLand

Page 2: Mixed-integer linear programming in MATLAB

2

Topics

Refresher on Mixed-integer linear programming (MILP)

Solving an MILP problem in MATLAB

MILP algorithms

Tuning the solver

Page 3: Mixed-integer linear programming in MATLAB

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

Page 4: Mixed-integer linear programming in MATLAB

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 (

$)

Page 5: Mixed-integer linear programming in MATLAB

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

≤ −𝑜𝑏𝑙𝑖𝑔𝑎𝑡𝑖𝑜𝑛𝑠

Page 6: Mixed-integer linear programming in MATLAB

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

Page 7: Mixed-integer linear programming in MATLAB

7

Demo: Index replication

C(i,j) : how closely is asset i related to asset j?

Correlation matrix

Page 8: Mixed-integer linear programming in MATLAB

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

Page 9: Mixed-integer linear programming in MATLAB

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)

Page 10: Mixed-integer linear programming in MATLAB

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

Page 11: Mixed-integer linear programming in MATLAB

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

Page 12: Mixed-integer linear programming in MATLAB

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

Page 13: Mixed-integer linear programming in MATLAB

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

Page 14: Mixed-integer linear programming in MATLAB

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

Page 15: Mixed-integer linear programming in MATLAB

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


Recommended