Piecewise linear (PWL) constraints in LP file format

CPLEX conforms to these rules about piecewise linear (PWL) constraints in LP file format.

For a definition of a piecewise-linear (PWL) constraint, see the topic What is a piecewise linear function? in the CPLEX User's Manual.

To specify piecewise-linear constraints, use a PWL section. A PWL section must be the last section before the END section. By convention, a new PWL constraint starts a new line in the formatted file. Piecewise-linear constraints begin with an optional name followed by a colon (as with objective function names, or other constraint names). The rest of the piecewise-linear constraint is specified by a 'y' variable followed by an equal sign ('='), an 'x' variable, preslope, list of breakpoints, and a postslope. Only the name is optional; all other syntactic elements are required. In particular, CPLEX rejects a PWL declaration with no breakpoint and issues the error message CPXERR_ILL_DEFINED_PWL.

For example:

pwl1: y = x 0.5 (0, 0) (1, 1) (2, 4) 2.0  
In that example, the variable is x; the preslope is 0.5; the breakpoints are (0, 0) (1, 1) (2, 4); the postslope is 2.0. The name of this piecewise linear constraint is pwl1.

A breakpoint, such as (1, 1) or (2, 4), is not an acceptable name of a variable nor of a piecewise linear constraint. The name of a piecewise linear constraint must adhere to the same guidelines as variable names. (See the rule about Variable names in LP file format.)

Tip: You must specify breakpoints in the order that you want CPLEX to extract them.

Consider, for example, these breakpoints:
 
(0,0) (1,0) (1,1) (2,1)
(0,0) (1,1) (1,0) (2,1) 
Both sets cite the same four breakpoints, but notice that the order is different. The first set specifies these two horizontal line segments:
 
                          _
(0,0) (1,0) (1,1) (2,1)  _
The second set specifies these two parallel line segments sloping at 45 degrees:
 
(0,0) (1,1) (1,0) (2,1) //

Sample LP file format

Cplex produces the following data in LP file format from the Python example transport.py of a model with a piecewise linear objective function.

 
\ENCODING=ISO-8859-1
\Problem name: transport.py

Minimize
 obj: y1 + y2 + y3 + y4 + y5 + y6 + y7 + y8 + y9 + y10 + y11 + y12
Subject To
 c1: x1 + x2 + x3 + x4  = 1000
 c2: x5 + x6 + x7 + x8  = 850
 c3: x9 + x10 + x11 + x12  = 1250
 c4: x1 + x5 + x9  = 900
 c5: x2 + x6 + x10  = 1200
 c6: x3 + x7 + x11  = 600
 c7: x4 + x8 + x12  = 400
Pwl
 p1:  y1 = x1 120 (200, 24000) (400, 40000) 50
 p2:  y2 = x2 120 (200, 24000) (400, 40000) 50
 p3:  y3 = x3 120 (200, 24000) (400, 40000) 50
 p4:  y4 = x4 120 (200, 24000) (400, 40000) 50
 p5:  y5 = x5 120 (200, 24000) (400, 40000) 50
 p6:  y6 = x6 120 (200, 24000) (400, 40000) 50
 p7:  y7 = x7 120 (200, 24000) (400, 40000) 50
 p8:  y8 = x8 120 (200, 24000) (400, 40000) 50
 p9:  y9 = x9 120 (200, 24000) (400, 40000) 50
 p10: y10 = x10 120 (200, 24000) (400, 40000) 50
 p11: y11 = x11 120 (200, 24000) (400, 40000) 50
 p12: y12 = x12 120 (200, 24000) (400, 40000) 50
End