Generic constraints

AbstractConstraint (Abstract class)

class disropt.constraints.constraints.AbstractConstraint[source]

Bases: object

Abstract class for expressing constraints

eval()[source]

Constraint

class disropt.constraints.constraints.Constraint(fn, sign='==')[source]

Bases: disropt.constraints.constraints.AbstractConstraint

Constraint build from a AbstractFunction object. Constraints are represented in the canonical forms \(f(x)=0\) and \(f(x)\leq 0\).

Parameters
  • fn (AbstractFunction) – constraint function

  • sign (bool) – type of constraint: “==”, “<=” or “>=”

fn

constraint function

Type

AbstractFunction

sign

type of constraint: “==”, “<=” or “>=”

Type

bool

input_shape

input space dimensions

Type

tuple

output_shape

output space dimensions

Type

tuple

eval(x)[source]

Evaluate the constraint function at a point x

Parameters

x (ndarray) – input point

Return type

bool

property function
get_parameters()[source]

Return the parameters of the function if it is affine or quadratic

Returns

A, b for affine constraints, P, q, r for quadratic

Return type

tuple

property is_affine

Return true if the function is affine.

Returns

true if the function is affine

Return type

bool

property is_equality
property is_inequality
property is_quadratic

Return true if the function is affine.

Returns

true if the function is affine

Return type

bool

projection(x)[source]

Compute the projection of a point onto the set defined by the constraint. The constraint should be convex.

Parameters

x (ndarray) – point to be projected

Returns

projected point

Return type

numpy.ndarray

ExtendedConstraint

class disropt.constraints.extended_constraint.ExtendedConstraint(fn, sign='==')[source]

Bases: disropt.constraints.constraints.Constraint

Constraint with extended variable

Parameters
  • constr (Constraint or list of Constraint) – original constraint(s)

  • n_var – number of additional variables. Defaults to 1

  • axis – axis along which the additional variables are appended. Defaults to -1 (the last valid one)

  • pos – position index of the old variable vector. Defaults to 0

Raises
  • TypeError – fn must be a Constraint object or a list of Constraint objects

  • TypeError – n_var must be a positive int

  • TypeError – axis must be int