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.

パラメータ:

arg (Constraint)

戻り値:

A new ConstraintList containing both constraints.

戻り値の型:

ConstraintList

__eq__(self, arg: object, /) bool
パラメータ:

arg (object)

戻り値の型:

bool

__imul__(self, arg: float, /) Constraint
パラメータ:

arg (float)

戻り値の型:

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
パラメータ:

arg (float)

戻り値の型:

Constraint

__mul__(self, arg: float, /) Constraint
パラメータ:

arg (float)

戻り値の型:

Constraint

__ne__(self, arg: object, /) bool
パラメータ:

arg (object)

戻り値の型:

bool

__radd__(self, arg: int, /) Constraint
パラメータ:

arg (int)

戻り値の型:

Constraint

__repr__(self) str
戻り値の型:

str

__rmul__(self, arg: float, /) Constraint
パラメータ:

arg (float)

戻り値の型:

Constraint

__str__(self) str
戻り値の型:

str

__truediv__(self, arg: float, /) Constraint
パラメータ:

arg (float)

戻り値の型:

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.

戻り値:

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

戻り値の型:

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

property label

Constraint label used for identification.

戻り値の型:

str

property penalty

Penalty polynomial associated with this constraint.

戻り値:

Penalty expression used for this constraint.

戻り値の型:

Poly

property weight

Constraint weight.

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

戻り値の型:

float