Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
Math Models of OR:
Modeling Piecewise Linear Functions
John E. Mitchell
Department of Mathematical Sciences
RPI, Troy, NY 12180 USA
November 2018
Mitchell Modeling Piecewise Linear Functions 1 / 18
Introduction
Outline
1 Introduction
2 Modeling the first line segment
3 Modeling the second line segment
4 Modeling the third line segment
5 Modeling the piecewise linear function
Mitchell Modeling Piecewise Linear Functions 2 / 18
Introduction
Piecewise linear functions
Piecewise linear functions can be modeled using variables that satisfy
what is known as a special order set (SOS) constraint of type 2, which
in turn can be modeled using binary variables.
Consider the following example of a continuous piecewise linear
function:
z =
8<
:
3 + 4x for 0 x 2
15 � 2x for 2 x 3
6 + x for 3 x 7.
The variable x is restricted to lie between 0 and 7.
Note that the function is nonconvex.
Mitchell Modeling Piecewise Linear Functions 3 / 18
[email protected]:Ix i l . 4 ¥ ! !
linesegment i t above c u r v e .
Ei.p÷÷÷÷÷÷÷÷:÷÷÷÷.m i n f(x) Equivalent
m i n 2
s - t . 2 3 6 - 2t o : 2 7 , 4 - x
OEXEG z ? - 5 t 2 x
r u i n 2 2 hs i ? z s , 6 -3x .
2 ? 4 - × 6 ): : : : : µ¥,i f
Introduction
Our function
x
z
0 2 3 7
3
9
11
13
(0,3)
(2,11)
(3,9)
(7,13)
z =
8<
:
3 + 4x for 0 x 2
15 � 2x for 2 x 3
6 + x for 3 x 7.
Mitchell Modeling Piecewise Linear Functions 4 / 18
io
n o nc o n v e x :
liec segment
i s below c u r v e .
Modeling the first line segment
Outline
1 Introduction
2 Modeling the first line segment
3 Modeling the second line segment
4 Modeling the third line segment
5 Modeling the piecewise linear function
Mitchell Modeling Piecewise Linear Functions 5 / 18
Modeling the first line segment
The first line segment
For 0 x 2, we have the linear function z = 3 + 4x .
Note that in this range, the points (x , z) on the line segment are
convex combinations of the two endpoints of the line segment, (0, 3)and (2, 11).
If we give a weight w1 to the point (0, 3) and a weight w2 to the point
(2, 11) then any point on the line segment can be expressed as
✓xz
◆= w1
✓0
3
◆+ w2
✓2
11
◆,
so x = 0w1 + 2w2
and z = 3w1 + 11w2.
The weights w1 and w2 must be nonnegative and they must add up to
one for this to be a convex combination.
Mitchell Modeling Piecewise Linear Functions 6 / 18
Modeling the first line segment
The first line segment graphically
x
z
0 2 3 7
3
9
11
13
(0,3)
(2,11)
x = w1 + 2w2, z = 3w1 + 11w2
Mitchell Modeling Piecewise Linear Functions 7 / 18
4=0,w e l
41=491*41WI,W L ?O
=w , t w >= /.
'u,= I ,w e 0
Modeling the second line segment
Outline
1 Introduction
2 Modeling the first line segment
3 Modeling the second line segment
4 Modeling the third line segment
5 Modeling the piecewise linear function
Mitchell Modeling Piecewise Linear Functions 8 / 18
Modeling the second line segment
The second line segment
For 2 x 3, we have the linear function z = 15 � 2x .
Note that in this range, the points (x , z) on the line segment are
convex combinations of the two endpoints of the line segment, (2, 11)and (3, 9).
If we give a weight w2 to the point (2, 11) and a weight w3 to the point
(3, 9) then any point on the line segment can be expressed as
✓xz
◆= w2
✓2
11
◆+ w3
✓3
9
◆,
so x = 2w2 + 3w3
and z = 11w2 + 9w3.
The weights w2 and w3 must be nonnegative and they must add up to
one for this to be a convex combination.
Mitchell Modeling Piecewise Linear Functions 9 / 18
Modeling the second line segment
The second line segment graphically
x
z
0 2 3 7
3
9
11
13
(2,11)
(3,9)
x = 2w2 + 3w3, z = 11w2 + 9w3
Mitchell Modeling Piecewise Linear Functions 10 / 18
(ft . K i l t u s(9)W ,i was7 0 , o ,#w,s /
Modeling the third line segment
Outline
1 Introduction
2 Modeling the first line segment
3 Modeling the second line segment
4 Modeling the third line segment
5 Modeling the piecewise linear function
Mitchell Modeling Piecewise Linear Functions 11 / 18
Modeling the third line segment
The third line segment
For 3 x 7, we have the linear function z = 6 + x .
Note that in this range, the points (x , z) on the line segment are
convex combinations of the two endpoints of the line segment, (3, 9)and (7, 13).
If we give a weight w3 to the point (3, 9) and a weight w4 to the point
(7, 13) then any point on the line segment can be expressed as
✓xz
◆= w3
✓3
9
◆+ w4
✓7
13
◆,
so x = 3w3 + 7w4
and z = 9w3 + 13w4.
The weights w3 and w4 must be nonnegative and they must add up to
one for this to be a convex combination.
Mitchell Modeling Piecewise Linear Functions 12 / 18
Modeling the third line segment
The third line segment graphically
x
z
0 2 3 7
3
9
11
13
(3,9)
(7,13)
x = 3w3 + 7w4, z = 9w3 + 13w4
Mitchell Modeling Piecewise Linear Functions 13 / 18
(1)= ↳ ({It-4lb)U s ,4470 , w ,-104= /
Modeling the piecewise linear function
Outline
1 Introduction
2 Modeling the first line segment
3 Modeling the second line segment
4 Modeling the third line segment
5 Modeling the piecewise linear function
Mitchell Modeling Piecewise Linear Functions 14 / 18
Modeling the piecewise linear function
Putting it all together
We can combine the three convex combination models for the three
line segments to give a model for the piecewise linear function.
A point on the piecewise linear function must be on one of the line
segments, so it is a convex combination of two of the four points (0, 3),(2, 11), (3, 9) and (7, 13).
One tricky part is that the two points must be adjacent.
Mitchell Modeling Piecewise Linear Functions 15 / 18
Modeling the piecewise linear function
Some constraints
We require (x , z) to be a convex combination of the four breakpoints.
So we need
✓xz
◆= w1
✓0
3
◆+ w2
✓2
11
◆+ w3
✓3
9
◆+ w4
✓7
13
◆.
We can express these two conditions as well as the requirement that
we have a convex combination using the following linear constraints in
the six variables x , z,w1,w2,w3,w4:
0w1 + 2w2 + 3w3 + 7w4 = x3w1 + 11w2 + 9w3 + 13w4 = zw1 + w2 + w3 + w4 = 1
The variables w1,w2,w3,w4 must also be nonnegative.
Mitchell Modeling Piecewise Linear Functions 16 / 18
V.¥÷÷÷*i÷:÷÷÷÷i.•
¥
w ,i wait, ( x4 = w ,⇒
:
2)= (3£)
Onlast linesegment,s oshould
have : 2 = 6e x = 9 4
Modeling the piecewise linear function
SOS-2 constraints
The calculated value of z is not accurate if, for example, w1 = 0.5 and
w4 = 0.5. This would give x = 3.5 and z = 8, whereas we should have
z = 6 + 3.5 = 9.5.
The restriction we need to impose is that at most two of the wi can be
nonzero, and the two nonzero wi must be adjacent.
This is known as a SOS-2 constraint, that is, a special order set of type
2 constraint.
Mitchell Modeling Piecewise Linear Functions 17 / 18
Modeling the piecewise linear function
SOS-2 using binary variables
The SOS-2 restriction can be modeled using binary variables yi ,
i = 1, . . . , 4:
wi yi i = 1, . . . , 4P4
i=1yi 2
y1 + y3 1
y1 + y4 1
y2 + y4 1.
The summation constraint allows at most two of the yi to be equal to
one, and hence at most two components of wi can be positive.
The last three constraints prevent non-adjacent points being chosen.
For example, the constraint y1 + y4 1 forces y1 = 0 and/or y4 = 0;
in turn, the first constraint then forces either w1 = 0 and/or w4 = 0.
Mitchell Modeling Piecewise Linear Functions 18 / 18