Matrix¶
- class Matrix¶
This class represents a quadratic objective in coefficient-matrix form, expressed as \(x^\top Q x + p^\top x + c\).
Methods
Evaluate the matrix objective using the provided variable assignments.
Convert this matrix form to
Poly.Attributes
Constant term
c.Linear coefficient array
p.Quadratic coefficient array
Q.Variable array
xused in the matrix representation.- __add__(self, arg: Constraint | ConstraintList, /) Model¶
Create a
Modelwhose 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:
- __init__(*args, **kwargs)¶
- __radd__(self, arg: Constraint | ConstraintList, /) Model¶
Create a
Modelwhose 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:
- __repr__(self) str¶
Return a developer-friendly string representation of the matrix form.
- Return type:
- evaluate(self, values: Values) float¶
- evaluate(self, values: Values, default: float) float
Evaluate the matrix objective using the provided variable assignments.
Substitute variables in
xwith the givenvaluesand evaluatex^\top Q x + p^\top x + c. Ifdefaultis not specified, a variable thatvaluesdoes not give takes the default value of its type:0for a binary variable,-1for an Ising variable, and, for an integer or a real variable,0if the bounds hold0, 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:
- property linear¶
Linear coefficient array
p.For a variable array
xwithndimensions, the linear coefficient arraypalso hasndimensions. Whenxis one-dimensional,pis a 1D vector.- Return type:
- property quadratic¶
Quadratic coefficient array
Q.For a variable array
xwithndimensions, the quadratic coefficient arrayQhas2ndimensions. Whenxis one-dimensional,Qis a 2D matrix.- Return type: