Matrix

class Matrix

This class represents a quadratic objective in coefficient-matrix form, expressed as \(x^\top Q x + p^\top x + c\).

Methods

__init__

evaluate

Evaluate the matrix objective using the provided variable assignments.

to_poly

Convert this matrix form to Poly.

Attributes

constant

Constant term c.

linear

Linear coefficient array p.

quadratic

Quadratic coefficient array Q.

variable_array

Variable array x used in the matrix representation.

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

Create a Model whose objective is this matrix form, with the given constraints.

パラメータ:

arg (Constraint | ConstraintList) -- Constraints to include.

戻り値:

Model containing this objective and the given constraints.

戻り値の型:

Model

__eq__(self, arg: object, /) bool

__eq__

パラメータ:

arg (object)

戻り値の型:

bool

__init__(*args, **kwargs)
__ne__(self, arg: object, /) bool

__ne__

パラメータ:

arg (object)

戻り値の型:

bool

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

Create a Model whose objective is this matrix form, with the given constraints.

パラメータ:

arg (Constraint | ConstraintList) -- Constraints to include.

戻り値:

Model containing this objective and the given constraints.

戻り値の型:

Model

__repr__(self) str

Return a developer-friendly string representation of the matrix form.

戻り値の型:

str

__str__(self) str

Return a human-readable string representation of the matrix form.

戻り値の型:

str

evaluate(self, values: Values) float
evaluate(self, values: Values, default: float) float

Evaluate the matrix objective using the provided variable assignments. evaluate

Substitute variables in x with the given values and evaluate x^\top Q x + p^\top x + c. If default is not specified, variables not included in values are substituted with a reasonable default value.

Overload 1.

Args:
  • values (amplify.Values): Variable values obtained from optimization results, e.g. result.best.values.

Returns:

float: Evaluated objective value.

Overload 2.

Args:
  • values (amplify.Values): Variable values obtained from optimization results, e.g. result.best.values.

  • default (float): Default value used for variables not included in values.

Returns:

float: Evaluated objective value.

to_poly(self) Poly

Convert this matrix form to Poly.

戻り値:

Polynomial converted from this matrix form.

戻り値の型:

Poly

property constant

Constant term c.

戻り値の型:

float

property linear

Linear coefficient array p.

For a variable array x with n dimensions, the linear coefficient array p also has n dimensions. When x is one-dimensional, p is a 1D vector.

戻り値の型:

ndarray

property quadratic

Quadratic coefficient array Q.

For a variable array x with n dimensions, the quadratic coefficient array Q has 2n dimensions. When x is one-dimensional, Q is a 2D matrix.

戻り値の型:

ndarray

property variable_array

Variable array x used in the matrix representation.

Use this array when constructing constraints for a matrix objective.

戻り値:

Variable array used in this representation.

戻り値の型:

PolyArray[Dim]