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.

  • 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.

Return type:

(int, list)


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.

  • 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.


Generates a Gray code of nbits as list of lists


Checks if a list of points is constant


Checks if a list of points is nondecreasing


Checks if a list of points is nonincreasing


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


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