Model

class Model

Combinatorial optimization model containing objective and constraints.

Methods

__init__

Construct a model.

copy

Return a copy of the model.

get_variables

Return the variables appearing in the model.

to_intermediate_model

Convert the model to an intermediate model according to degree and encoding settings.

to_unconstrained_poly

Convert model constraints into penalty form and return an unconstrained objective polynomial.

Attributes

constraints

Constraints held by the model.

objective

Objective function held by the model.

variables

List of variables in the model.

__add__(self, arg: Poly | Constraint | ConstraintList, /) Model

Give a new model that holds the right side in addition.

A polynomial goes to the objective function, and a constraint or a constraint list goes to the constraints.

パラメータ:

arg (Poly | Constraint | ConstraintList)

戻り値の型:

Model

__eq__(self, arg: object, /) bool

Tell whether the two models have the same objective function and the same constraints.

パラメータ:

arg (object)

戻り値の型:

bool

__iadd__(self, arg: Poly | Constraint | ConstraintList, /) Model

Add the right side to the model.

A polynomial goes to the objective function, and a constraint or a constraint list goes to the constraints.

パラメータ:

arg (Poly | Constraint | ConstraintList)

戻り値の型:

Model

__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.

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.

__isub__(self, arg: Poly, /) Model

Subtract the polynomial from the objective function of the model.

パラメータ:

arg (Poly)

戻り値の型:

Model

__ne__(self, arg: object, /) bool

Tell whether the two models differ. This is the negation of ==.

パラメータ:

arg (object)

戻り値の型:

bool

__radd__(self, arg: Poly | Constraint | ConstraintList, /) Model

Give a new model that holds the right side in addition.

A polynomial goes to the objective function, and a constraint or a constraint list goes to the constraints.

パラメータ:

arg (Poly | Constraint | ConstraintList)

戻り値の型:

Model

__repr__(self) str

Return a developer-friendly string representation of the model.

戻り値の型:

str

__str__(self) str

Return a human-readable string representation of the model.

戻り値の型:

str

__sub__(self, arg: Poly, /) Model

Give a new model whose objective function is this one minus the polynomial.

パラメータ:

arg (Poly)

戻り値の型:

Model

copy(self) Model

Return a copy of the model.

戻り値:

Copy of the model.

戻り値の型:

Model

get_variables(self, with_penalty: bool = False) list[Variable]

Return the variables appearing in the model.

When with_penalty is True, this may trigger penalty construction for constraints and include auxiliary variables introduced by the penalty formulation.

パラメータ:

with_penalty (bool) -- Whether to include auxiliary variables introduced by penalty formulation. Defaults to False.

戻り値:

Variables that appear in the model.

One polynomial for each variable, in the order of the variable ID.

戻り値の型:

list[Variable]

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,
) tuple[Model, IntermediateMapping]

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.

パラメータ:
  • 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 to 1.0.

戻り値:

Converted model and mapping information.

The model that holds only the accepted degrees, and the map that gives the intermediate expression of each input variable.

戻り値の型:

tuple[Model, IntermediateMapping]

to_unconstrained_poly(self) Poly

Convert model constraints into penalty form and return an unconstrained objective polynomial.

戻り値:

Unconstrained objective polynomial.

The objective function with the penalty function of every constraint added to it.

戻り値の型:

Poly

property constraints

Constraints held by the model.

戻り値の型:

ConstraintList

property objective

Objective function held by the model.

A model always holds the objective function as a Poly. If you give a Matrix, the model converts it, and a later write to that matrix does not reach the model.

戻り値の型:

Poly

property variables

List of variables in the model.

Equivalent to get_variables() with with_penalty=False.

戻り値の型:

list[Variable]