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. evaluate
Substitute variables in
xwith the givenvaluesand evaluatex^\top Q x + p^\top x + c. Ifdefaultis not specified, variables not included invaluesare 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.- 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: