> Discrete Optimization > Transport: Piecewise Linear Optimization > Piecewise Linearity in ILOG CPLEX > Syntax of Piecewise Linear Functions

To define a piecewise linear function in Concert Technology, you need these components:

In other words, for a piecewise linear function of n breakpoints, you need to know n+1 slopes.

Typically, the breakpoints of a piecewise linear function are specified as an array of numeric values. For example, the breakpoints of the function f(x) as it appears in Figure 16.1 are specified in this way:

IloNumArray (env, 3, 4., 5., 7)

The slopes of its segments are indicated as an array of numeric values as well. For example, the slopes of f(x) are specified in this way:

IloNumArray (env, 4, -0.5, 1., -1., 2.)

The geometric coordinates of at least one point of the function, (x, f(x)) must also be specified; for example, (4, 2). Then in Concert Technology, those elements are brought together in an instance of the class IloPiecewiseLinear in this way:

IloPiecewiseLinear(x, 
                   IloNumArray(env, 3, 4., 5., 7.), 
                   IloNumArray(env, 4, -0.5, 1., -1., 2.), 
                   4, 2)

Another way to specify a piecewise linear function is to give the slope of the first segment, two arrays for the coordinates of the breakpoints, and the slope of the last segment. In this approach, the example f(x) from Figure 16.1 looks like this:

IloPiecewiseLinear(x, -0.5, IloNumArray(env, 3, 4., 5., 7.),
                            IloNumArray(env, 3, 2., 3., 1.), 2);