friendlysam.opt.piecewise_affine_constraints

friendlysam.opt.piecewise_affine_constraints(variables, include_lb=True)

Constrains for a piecewise affine expression.

For some variables x_0, x_1, \ldots, x_n, this function creates

  • A SOS2 constraint for the variables.
  • A constraint that \sum_{i=0}^n x_i = 1.
  • For each variable x_i, a constraint that x_i \geq 0.

It is used by piecewise_affine().

Parameters:
  • (sequence of (variables) – class:Variable instances)
  • include_lb (boolean, optional) – If True (the default), lower bound constraints x[i] >= 0 are created for the variables. Set to False if your variables already have lower bounds >= 0 and you want to avoid a few redundant constraints.
Returns:

A set of SOS2 and Constraint instances.

Return type:

set