LinearExpression¶
-
class
LinearExpression
(quadratic_program, coefficients)[source]¶ Bases:
qiskit.optimization.problems.quadratic_program_element.QuadraticProgramElement
Representation of a linear expression by its coefficients.
Creates a new linear expression.
The linear 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.
- Parameters
quadratic_program (
Any
) – The parent QuadraticProgram.coefficients (
Union
[ndarray
,spmatrix
,List
[float
],Dict
[Union
[int
,str
],float
]]) – The (sparse) representation of the coefficients.
Methods
Evaluate the linear expression for given variables.
Evaluate the gradient of the linear expression for given variables.
Returns the coefficients of the linear expression as array.
Returns the coefficients of the linear expression as dictionary, either using variable names or indices as keys.
Attributes
-
coefficients
¶ Returns the coefficients of the linear expression.
- Return type
dok_matrix
- Returns
The coefficients of the linear expression.
-
quadratic_program
¶ Returns the parent QuadraticProgram.
- Return type
Any
- Returns
The parent QuadraticProgram.