qp.resource.Expression

class Expression(data, vars=None, _skip_copy=False, _skip_normalization=False)[source]

Bases: object

Internal class for representing symbolic expressions of resources. Specifically, each expression is a polynomial in the variables with real (numeric) coefficients, where the variables represent symbolic parameters of the resources. The expressions are represented as a dictionary mapping tuples of variable names to their coefficients.

Warning

This class is intended to be immutable. Do not modify the internal state of an expression after it is created, as this may lead to incorrect behaviour.

vars

The set of variables that appear in the expression.

vars

The set of variables that appear in the expression.

subs([substitutions])

Substitutes the given values for the variables in the expression.

subs(substitutions=None, **kwargs)[source]

Substitutes the given values for the variables in the expression.

Parameters:

substitutions (dict[str, Real] | None) – A dictionary mapping variable names to their values. If None, an empty dictionary is used. Additional keyword arguments can also be provided as substitutions.

Returns:

A new expression with the variables substituted, or a number if the result is a constant.

Return type:

Expression | Real