Constraint¶
- class Constraint¶
Bases:
object
A class for a user-defined constraint.
Methods
Initialize constraint.
Return whether a given input (solution of the optimization) meets the constraint.
Convert the constraint to the Amplify SDK's constraint.
Unify duplicate variables used in the constraint and across different constraints.
Attributes
A l.h.s.
An equality or inequality operator symbol of a constraint.
The Amplify SDK's penalty_formulation parameter.
A r.h.s.
A constraint weight.
- __init__(left: Poly | VariableListBase, op: str, right: float | tuple) None ¶
Initialize constraint.
- Parameters:
left (Poly | VariableListBase) – A polynomial of variables. If a ‘variable list’ is directly given, its sum is considered as the l.h.s. polynomial.
op (str) – An equality or inequality operator of the constraint.
- __str__() str ¶
Return a human-readable constraint expression.
- Returns:
A constraint expression.
- Return type:
- is_satisfied(solution_dict: FlatSolutionDict) bool ¶
Return whether a given input (solution of the optimization) meets the constraint.
- Parameters:
solution_dict (FlatSolutionDict) – A solution.
- Raises:
ValueError – If a variable used in the constraint is not found in the solution_dict .
ValueError – If an operator is invalid.
- Returns:
True if the constraint is met.
- Return type:
- to_amplify_constraint() Constraint ¶
Convert the constraint to the Amplify SDK’s constraint.
- Raises:
ValueError – If an operator is invalid.
- Returns:
A converted constraint.
- Return type:
amplify.Constraint
- unify_variables(var_dict_universe: dict[str, Any]) None ¶
Unify duplicate variables used in the constraint and across different constraints. Intended for multi-objective optimizations where the same variable is used in different black-box objective functions. Calling this for single-objective optimization has no effect.
- __dict__ = mappingproxy({'__module__': 'amplify_bbopt.constraint', '__doc__': 'A class for a user-defined constraint.', '__init__': <function Constraint.__init__>, 'unify_variables': <function Constraint.unify_variables>, 'left': <property object>, 'op': <property object>, 'right': <property object>, 'weight': <property object>, 'penalty_formulation': <property object>, 'to_amplify_constraint': <function Constraint.to_amplify_constraint>, 'is_satisfied': <function Constraint.is_satisfied>, '__str__': <function Constraint.__str__>, '__repr__': <function Constraint.__repr__>, '__dict__': <attribute '__dict__' of 'Constraint' objects>, '__weakref__': <attribute '__weakref__' of 'Constraint' objects>, '__annotations__': {}})¶
- __weakref__¶
list of weak references to the object (if defined)
- property penalty_formulation: str¶
The Amplify SDK’s penalty_formulation parameter.
- Set this to “Relaxation” when you:
impose an inequality constraint with real variables (when coefficients in the constraint formulation is likely to yield real numbers), AND
the specified solver (e.g Amplify Annealing Engine) is a QUBO solver that does not support real variables, until the Amplify SDK used internally in Amplify-BBOpt supports the real-to-binary variable conversion. See: https://amplify.fixstars.com/ja/docs/amplify/v1/penalty.html#ineq-penalty