Initializing help system before first use

xpress.pwl

xpress.pwl


Purpose

Returns a piecewise linear function over a variable.


Synopsis
xpress.pwl(dict)
Argument
dict 
Python dictionary containing, as keys, two-elements tuples, and, as values, linear expressions in a variable. If the piecewise linear function has only constant values (i.e. it is a piecewise constant function), the independent variable can be specified with the key-value pair None: x.
Example
The following example shows various usages of xpress.pwl to model nonlinear functions as piecewise-linear functions :

x = xp.var()  # Nonnegative variable
y = xp.var(lb=-xp.infinity)  # dependent variable, unrestricted
t = xp.var()
w = xp.var()

p = xp.problem(x, y)

# Sets a piecewise linear objective: a ramp function
p.setObjective (xp.pwl({(-xp.infinity, -1):  -2,
                        (-1, 1):            2*x,
                        (1, xp.infinity)]:    2}))

p.addConstraint (t == xp.pwl({(1,2): 4*x, (2,4): 2, (4,5): -1}))

# Piecewise CONSTANT function: add a key-value pair None: x to specify
# independent variable
p.addConstraint (t == xp.pwl({(1,2): 4, (2,4): 2, (4,5): -1, None: x}))

p.addConstraint (xp.pwl({(-1,0): x, (0,1): 2*x, (1,10): 2}) <=
                 xp.pwl({(0,10): 2*z, (10,20): z+2, (20,xp.infinity): 4}))
Further information
1. A piecewise linear function must use only one variable in all of the dictionary's values;
2. All values in the dictionary must be either constants or linear functions;
3. The intervals, specified as two-element tuples in the dictionary's keys, must be pairwise disjoint, i.e., they must not overlap.
4. Discontinuities in the function are allowed, i.e., one can declare a function as follows: xp.pwl({(1, 2): 2*x + 4, (2,3): x - 1}), which is obviously discontinuous at 2. The value of the function if the optimal solution has x=2 will be then either 8 or 1.
Related topics

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.