LinearExpression#

class LinearExpression(quadratic_program, coefficients)[source]#

Bases: 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.

প্যারামিটার:
  • quadratic_program (Any) -- The parent QuadraticProgram.

  • coefficients (ndarray | spmatrix | List[float] | Dict[int | str, float]) -- The (sparse) representation of the coefficients.

Attributes

bounds#

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

রিটার্নস:

The lower bound and the upper bound of the linear expression

রেইজেস:

QiskitOptimizationError -- if the linear expression contains any unbounded variable

coefficients#

Returns the coefficients of the linear expression.

রিটার্নস:

The coefficients of the linear expression.

quadratic_program#

Returns the parent QuadraticProgram.

রিটার্নস:

The parent QuadraticProgram.

Methods

evaluate(x)[source]#

Evaluate the linear expression for given variables.

প্যারামিটার:

x (ndarray | List | Dict[int | str, float]) -- The values of the variables to be evaluated.

রিটার্নস:

The value of the linear expression given the variable values.

রিটার্ন টাইপ:

float

evaluate_gradient(x)[source]#

Evaluate the gradient of the linear expression for given variables.

প্যারামিটার:

x (ndarray | List | Dict[int | str, float]) -- The values of the variables to be evaluated.

রিটার্নস:

The value of the gradient of the linear expression given the variable values.

রিটার্ন টাইপ:

ndarray

to_array()[source]#

Returns the coefficients of the linear expression as array.

রিটার্নস:

An array with the coefficients corresponding to the linear expression.

রিটার্ন টাইপ:

ndarray

to_dict(use_name=False)[source]#

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

প্যারামিটার:

use_name (bool) -- Determines whether to use index or names to refer to variables.

রিটার্নস:

An dictionary with the coefficients corresponding to the linear expression.

রিটার্ন টাইপ:

Dict[int | str, float]