Constraint

class Constraint

Constraint class representing equality or inequality conditions on polynomial expressions.

Methods

__init__

Construct a constraint from bounds and a penalty polynomial.

is_satisfied

Check whether the constraint is satisfied.

Attributes

conditional

Constraint condition as (left, op, right) tuple.

label

Constraint label used for identification.

penalty

Penalty polynomial associated with this constraint.

weight

Constraint weight.

__add__(self, arg: Constraint, /) ConstraintList

Combine two constraints into a ConstraintList.

Parameters:

arg (Constraint)

Returns:

A new ConstraintList containing both constraints.

Return type:

ConstraintList

__eq__(self, arg: object, /) bool
Parameters:

arg (object)

Return type:

bool

__imul__(self, arg: float, /) Constraint
Parameters:

arg (float)

Return type:

Constraint

__init__(
self,
left: Poly,
bounds: tuple[float | None, float | None],
penalty: Poly,
label: str = '',
threshold: float = 0.0,
) None
__init__(self, left: Poly, eq: float, penalty: Poly, label: str = '', threshold: float = 0.0) None
__init__(self, left: Poly, le: float, penalty: Poly, label: str = '', threshold: float = 0.0) None
__init__(self, left: Poly, ge: float, penalty: Poly, label: str = '', threshold: float = 0.0) None

Construct a constraint from bounds and a penalty polynomial.

Overload 1.

Args:
  • left (amplify.Poly): Left-hand side polynomial.

  • bounds (tuple[float | None, float | None]): Bounds as (lower, upper). At least one must be specified.

  • penalty (amplify.Poly): Penalty polynomial.

  • label (str): Constraint label. Defaults to ''.

  • threshold (float): Satisfaction threshold. Defaults to 0.0.

Overload 2.

Args:
  • left (amplify.Poly): Left-hand side polynomial.

  • eq (float): Right-hand side value for equality.

  • penalty (amplify.Poly): Penalty polynomial.

  • label (str): Constraint label. Defaults to ''.

  • threshold (float): Satisfaction threshold. Defaults to 0.0.

Overload 3.

Args:
  • left (amplify.Poly): Left-hand side polynomial.

  • le (float): Upper bound value.

  • penalty (amplify.Poly): Penalty polynomial.

  • label (str): Constraint label. Defaults to ''.

  • threshold (float): Satisfaction threshold. Defaults to 0.0.

Overload 4.

Args:
  • left (amplify.Poly): Left-hand side polynomial.

  • ge (float): Lower bound value.

  • penalty (amplify.Poly): Penalty polynomial.

  • label (str): Constraint label. Defaults to ''.

  • threshold (float): Satisfaction threshold. Defaults to 0.0.

__itruediv__(self, arg: float, /) Constraint
Parameters:

arg (float)

Return type:

Constraint

__mul__(self, arg: float, /) Constraint
Parameters:

arg (float)

Return type:

Constraint

__ne__(self, arg: object, /) bool
Parameters:

arg (object)

Return type:

bool

__radd__(self, arg: int, /) Constraint
Parameters:

arg (int)

Return type:

Constraint

__repr__(self) str
Return type:

str

__rmul__(self, arg: float, /) Constraint
Parameters:

arg (float)

Return type:

Constraint

__str__(self) str
Return type:

str

__truediv__(self, arg: float, /) Constraint
Parameters:

arg (float)

Return type:

Constraint

is_satisfied(self, values: Values) bool
is_satisfied(
self,
mapping: Mapping[Poly, float | int] | Mapping[Variable, float | int],
) bool

Check whether the constraint is satisfied.

Overload 1.

Args:
  • values (amplify.Values): Values for variables, typically result.best.values.

Returns:

bool: True if the condition is satisfied.

Overload 2.

Args:
  • mapping (collections.abc.Mapping[amplify.Poly, float | int] | collections.abc.Mapping[amplify.Variable, float | int]): Mapping from variable to numeric value.

Returns:

bool: True if the condition is satisfied.

property conditional

Constraint condition as (left, op, right) tuple.

Returns:

Left polynomial, operator literal, and right-hand side value(s).

Return type:

tuple[Poly, Literal[‘EQ’, ‘GE’, ‘GT’, ‘LE’, ‘LT’, ‘BW’], float | tuple[float, float]]

property label

Constraint label used for identification.

Return type:

str

property penalty

Penalty polynomial associated with this constraint.

Returns:

Penalty expression used for this constraint.

Return type:

Poly

property weight

Constraint weight.

Larger values enforce this constraint more strongly when penalty methods are used.

Return type:

float