LinearExpression#

class LinearExpression(quadratic_program, coefficients)[ソース]#

ベースクラス: 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)[ソース]#

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)[ソース]#

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()[ソース]#

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)[ソース]#

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]