English
Languages
English
Shortcuts



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.

Attributes

bounds

Returns the lower bound and the upper bound of the linear expression

coefficients

Returns the coefficients of the linear expression.

Methods

__getitem__(i)

Returns the i-th coefficient where i can be a variable name or index.

evaluate(x)

Evaluate the linear expression for given variables.

evaluate_gradient(x)

Evaluate the gradient of the linear expression for given variables.

to_array()

Returns the coefficients of the linear expression as array.

to_dict([use_name])

Returns the coefficients of the linear expression as dictionary, either using variable names or indices as keys.