Constraint¶
- class Constraint¶
Constraint class representing equality or inequality conditions on polynomial expressions.
Methods
Construct a constraint from bounds and a penalty polynomial.
Check whether the constraint is satisfied.
Attributes
Constraint condition as
(left, op, right)tuple.Constraint label used for identification.
Penalty polynomial associated with this constraint.
Constraint weight.
- __add__(self, arg: Constraint, /) ConstraintList¶
Combine two constraints into a
ConstraintList.- Parameters:
arg (Constraint)
- Returns:
A new
ConstraintListcontaining both constraints.- Return type:
- __imul__(self, arg: float, /) Constraint¶
__imul__
- Parameters:
arg (float)
- Return type:
- __init__(
- self,
- left: Poly,
- bounds: tuple[float | None, float | None],
- penalty: Poly,
- label: str = '',
- threshold: float = 0.0,
- __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. __init__ __init__ __init__
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¶
__itruediv__
- Parameters:
arg (float)
- Return type:
- __mul__(self, arg: float, /) Constraint¶
__mul__
- Parameters:
arg (float)
- Return type:
- __radd__(self, arg: int, /) Constraint¶
__radd__
- Parameters:
arg (int)
- Return type:
- __rmul__(self, arg: float, /) Constraint¶
__rmul__
- Parameters:
arg (float)
- Return type:
- __truediv__(self, arg: float, /) Constraint¶
__truediv__
- Parameters:
arg (float)
- Return type:
- is_satisfied(self, values: Values) bool¶
- is_satisfied( ) bool
Check whether the constraint is satisfied. is_satisfied
Overload 1.
- Args:
values (amplify.Values): Values for variables, typically
result.best.values.
- Returns:
bool:
Trueif 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:
Trueif the condition is satisfied.
- property conditional¶
Constraint condition as
(left, op, right)tuple.
- property penalty¶
Penalty polynomial associated with this constraint.
- Returns:
Penalty expression used for this constraint.
- Return type: