LinearExpression

class LinearExpression(quadratic_program, coefficients)[source]

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

LinearExpression.coefficients

Returns the coefficients of the linear expression.

LinearExpression.quadratic_program

Returns the parent QuadraticProgram.

Methods

LinearExpression.__getitem__(i)

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

LinearExpression.evaluate(x)

Evaluate the linear expression for given variables.

LinearExpression.to_array()

Returns the coefficients of the linear expression as array.

LinearExpression.to_dict([use_name])

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