QuadraticExpression¶
- class QuadraticExpression(quadratic_program, coefficients)[source]¶
Representation of a quadratic expression by its coefficients.
Creates a new quadratic expression.
The quadratic expression can be defined via an array, a list, a sparse matrix, or a dictionary that uses variable names or indices as keys and stores the values internally as a dok_matrix. We stores values in a compressed way, i.e., values at symmetric positions are summed up in the upper triangle. For example, {(0, 1): 1, (1, 0): 2} -> {(0, 1): 3}.
- Parameters
quadratic_program (
Any
) – The parent QuadraticProgram.coefficients (
Union
[ndarray
,spmatrix
,List
[List
[float
]],Dict
[Tuple
[Union
[int
,str
],Union
[int
,str
]],float
]]) – The (sparse) representation of the coefficients.
Attributes
Returns the coefficients of the quadratic expression.
Returns the parent QuadraticProgram.
Methods
Returns the coefficient where i, j can be a variable names or indices.
Evaluate the quadratic expression for given variables: x * Q * x.
QuadraticExpression.to_array
([symmetric])Returns the coefficients of the quadratic expression as array.
QuadraticExpression.to_dict
([symmetric, …])Returns the coefficients of the quadratic expression as dictionary, either using tuples of variable names or indices as keys.