# Utilities for Piecewise Functions¶

exception pyomo.core.kernel.piecewise_library.util.PiecewiseValidationError[source]

Bases: exceptions.Exception

An exception raised when validation of piecewise linear functions fail.

pyomo.core.kernel.piecewise_library.util.characterize_function(breakpoints, values)[source]

Characterizes a piecewise linear function described by a list of breakpoints and function values.

Parameters: breakpoints (list) – The list of breakpoints of the piecewise linear function. It is assumed that the list of breakpoints is in non-decreasing order. values (list) – The values of the piecewise linear function corresponding to the breakpoints. a function characterization code and the list of slopes. (int, list)

Note

The function characterization codes are

• 1: affine
• 2: convex
• 3: concave
• 4: step
• 5: other

If the function has step points, some of the slopes may be None.

pyomo.core.kernel.piecewise_library.util.generate_delaunay(variables, num=10, **kwds)[source]

Generate a Delaunay triangulation of the D-dimensional bounded variable domain given a list of D variables.

Requires numpy and scipy.

Parameters: variables – A list of variables, each having a finite upper and lower bound. num (int) – The number of grid points to generate for each variable (default=10). **kwds – All additional keywords are passed to the scipy.spatial.Delaunay constructor. A scipy.spatial.Delaunay object.
pyomo.core.kernel.piecewise_library.util.generate_gray_code(nbits)[source]

Generates a Gray code of nbits as list of lists

pyomo.core.kernel.piecewise_library.util.is_constant(vals)[source]

Checks if a list of points is constant

pyomo.core.kernel.piecewise_library.util.is_nondecreasing(vals)[source]

Checks if a list of points is nondecreasing

pyomo.core.kernel.piecewise_library.util.is_nonincreasing(vals)[source]

Checks if a list of points is nonincreasing

pyomo.core.kernel.piecewise_library.util.is_positive_power_of_two(x)[source]

Checks if a number is a nonzero and positive power of 2

pyomo.core.kernel.piecewise_library.util.log2floor(n)[source]

Computes the exact value of floor(log2(n)) without using floating point calculations. Input argument must be a positive integer.