Model¶
- class Model¶
Combinatorial optimization model containing objective and constraints.
Methods
Construct a model.
Return a copy of the model.
Return the variables appearing in the model.
Convert the model to an intermediate model according to degree and encoding settings.
Convert model constraints into penalty form and return an unconstrained objective polynomial.
Attributes
Constraints held by the model.
Objective function held by the model.
List of variables in the model.
- __add__(self, arg: Poly | Constraint | ConstraintList, /) Model¶
__add__
- Parameters:
arg (Poly | Constraint | ConstraintList)
- Return type:
- __iadd__(self, arg: Poly | Constraint | ConstraintList, /) Model¶
__iadd__
- Parameters:
arg (Poly | Constraint | ConstraintList)
- Return type:
- __init__(self) None¶
- __init__(self, objective: Poly | Matrix) None
- __init__(self, constraint: Constraint | ConstraintList) None
- __init__(self, objective: Poly | Matrix, constraint: Constraint | ConstraintList) None
Construct a model. If no arguments are given, create an empty model with zero objective and no constraints. If a polynomial is given, construct a model with the polynomial as the objective. If constraints are given, Construct a model with the constraints. __init__
Overload 2.
- Args:
objective (amplify.Poly | amplify.Matrix): Objective function.
Overload 3.
- Args:
constraint (amplify.Constraint | amplify.ConstraintList): Constraints to include.
Overload 4.
- Args:
objective (amplify.Poly | amplify.Matrix): Objective function.
constraint (amplify.Constraint | amplify.ConstraintList): Constraints to include.
- __radd__(self, arg: Poly | Constraint | ConstraintList, /) Model¶
__radd__
- Parameters:
arg (Poly | Constraint | ConstraintList)
- Return type:
- get_variables(self, with_penalty: bool = False) list[Variable]¶
Return the variables appearing in the model.
When
with_penaltyisTrue, this may trigger penalty construction for constraints and include auxiliary variables introduced by the penalty formulation.
- to_intermediate_model(
- self,
- acceptable_degrees: AcceptableDegrees,
- integer_encoding_method: Literal['Unary', 'Linear', 'Binary', 'Default'] | IntegerEncodingMethod = IntegerEncodingMethod.Default,
- real_encoding_method: Literal['Random4', 'Random8', 'Random16', 'Random32'] | RealEncodingMethod = RealEncodingMethod.Random16,
- quadratization_method: Literal['IshikawaKZFD', 'Substitute'] | QuadratizationMethod = QuadratizationMethod.Substitute,
- substitution_multiplier: float = 1.0,
Convert the model to an intermediate model according to degree and encoding settings.
Performs variable conversion (integer/real to binary as needed), optional degree reduction, and variable remapping based on the required degrees.
- Parameters:
acceptable_degrees (AcceptableDegrees) – Acceptable degree settings.
integer_encoding_method (Literal['Unary', 'Linear', 'Binary', 'Default'] | amplify.IntegerEncodingMethod) – Integer variable conversion method. Defaults to
IntegerEncodingMethod.Default.real_encoding_method (Literal['Random4', 'Random8', 'Random16', 'Random32'] | amplify.RealEncodingMethod) – Real variable conversion method. Defaults to
RealEncodingMethod.Random16.quadratization_method (Literal['IshikawaKZFD', 'Substitute'] | amplify.QuadratizationMethod) – Quadratization method. Defaults to
QuadratizationMethod.Substitute.substitution_multiplier (float) – Multiplier for substitution penalty scaling (used only with
QuadratizationMethod.Substitute). Defaults to1.0.
- Returns:
Converted model and mapping information.
- Return type:
- to_unconstrained_poly(self) Poly¶
Convert model constraints into penalty form and return an unconstrained objective polynomial.
- Returns:
Unconstrained objective polynomial.
- Return type:
- property constraints¶
Constraints held by the model.
- Return type:
- property variables¶
List of variables in the model.
Equivalent to
get_variables()withwith_penalty=False.