Piecewise-Linear Functions via SOS Variables

Model a piecewise-linear function in a mixed-integer program by introducing a weight per breakpoint and forcing the weights to form a Special Ordered Set of Type 2 (SOS2). The SOS2 condition is encoded with binary segment indicators and disjunctive Big-M-style linking inequalities.

Step 1 of 157%

Tutorial

Piecewise-Linear Functions and the Lambda Representation

A piecewise-linear (PWL) function is specified by a sequence of breakpoints (x0,y0),(x1,y1),,(xn,yn)(x_0, y_0), (x_1, y_1), \ldots, (x_n, y_n) with x0<x1<<xnx_0 < x_1 < \cdots < x_n, connected by straight line segments. On the segment [xk,xk+1][x_k, x_{k+1}], the graph is the line through (xk,yk)(x_k, y_k) and (xk+1,yk+1)(x_{k+1}, y_{k+1}).

Any point (x,f(x))(x, f(x)) on the graph lies on exactly one segment and can be written as a convex combination of its two endpoints. If x[xk,xk+1]x \in [x_k, x_{k+1}], then for t=xxkxk+1xk[0,1]t = \dfrac{x - x_k}{x_{k+1} - x_k} \in [0,1],

x=(1t)xk+txk+1,f(x)=(1t)yk+tyk+1.x = (1-t)\, x_k + t\, x_{k+1}, \qquad f(x) = (1-t)\, y_k + t\, y_{k+1}.

To prepare for a MIP encoding, introduce nonnegative weights λ0,λ1,,λn\lambda_0, \lambda_1, \ldots, \lambda_n — one per breakpoint — and write

x=i=0nλixi,y=i=0nλiyi,i=0nλi=1,λi0.x = \sum_{i=0}^n \lambda_i\, x_i, \qquad y = \sum_{i=0}^n \lambda_i\, y_i, \qquad \sum_{i=0}^n \lambda_i = 1, \qquad \lambda_i \geq 0.

Setting λk=1t\lambda_k = 1-t, λk+1=t\lambda_{k+1} = t, and all other λi=0\lambda_i = 0 recovers the segment formula.

For example, with breakpoints (0,0),(2,3),(5,9),(8,3)(0,0), (2,3), (5,9), (8,3) and x=4x = 4: since 4[2,5]4 \in [2, 5], t=(42)/(52)=2/3t = (4-2)/(5-2) = 2/3, so λ1=1/3\lambda_1 = 1/3, λ2=2/3\lambda_2 = 2/3, and f(4)=(1/3)(3)+(2/3)(9)=1+6=7f(4) = (1/3)(3) + (2/3)(9) = 1 + 6 = 7.

navigate · Enter open · Esc close · ⌘K/Ctrl K toggle