BinaryMatrix

class BinaryMatrix

Bases: Matrix

A matrix form of binary variables. Deprecated alias of Matrix.

Amplify v1 gives the variable its type when the generator makes it, so the matrix no longer carries the type. This class still works, and it emits a DeprecationWarning.

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.

Parameters:

arg (Constraint | ConstraintList) – Constraints to include.

Returns:

Model containing this objective and the given constraints.

Return type:

Model

__eq__(self, arg: object, /) bool
Parameters:

arg (object)

Return type:

bool

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

arg (object)

Return type:

bool

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

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

Parameters:

arg (Constraint | ConstraintList) – Constraints to include.

Returns:

Model containing this objective and the given constraints.

Return type:

Model

__repr__(self) str

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

Return type:

str

__str__(self) str

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

Return type:

str

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

Evaluate the matrix objective using the provided variable assignments.

Substitute variables in x with the given values and evaluate x^\top Q x + p^\top x + c. If default is not specified, a variable that values does not give takes the default value of its type: 0 for a binary variable, -1 for an Ising variable, and, for an integer or a real variable, 0 if the bounds hold 0, else the upper bound, or the lower bound when the variable has no upper bound.

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.

Returns:

Polynomial converted from this matrix form.

Return type:

Poly

__deprecated__ = 'BinaryMatrix is deprecated since amplify v1.0.0 and will no longer support in the near future.\nUse Matrix instead. Please see the migration guide for details: https://amplify.fixstars.com/docs/amplify/v1/migration.html'
property constant

Constant term c.

Return type:

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.

Return type:

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.

Return type:

ndarray

property variable_array

Variable array x used in the matrix representation.

Use this array when constructing constraints for a matrix objective.

Returns:

Variable array used in this representation.

Return type:

PolyArray[Dim]