linopy.model.Model.add_expressions#
- Model.add_expressions(data, name=None, mask=None)#
Assign a new, possibly multi-dimensional array of expressions to the model.
- Parameters:
data (
Variable,LinearExpression,QuadraticExpression, orSequenceof(constant,variable) tuples) – The expression(s) to add. This can be a Variable or LinearExpression, or a sequence of (constant, variable) tuples which will be summed up.coords (
list/xarray.Coordinates, optional) – The coords of the expression array. The default is None.name (
str, optional) – Reference name of the added expressions. The default None results in a name like “expr1”, “expr2” etc.mask (
array_like, optional) – Boolean mask with False values for expressions which are skipped. The shape of the mask has to match the shape the added expressions. Default is None.
- Raises:
ValueError – If neither lower bound and upper bound have coordinates, nor coords are directly given.
- Returns:
linopy.LinearExpression | linopy.QuadraticExpression– Expression which was added to the model.
Examples
>>> from linopy import Model >>> import pandas as pd >>> m = Model() >>> time = pd.RangeIndex(10, name="Time") >>> x = m.add_variables(lower=0, coords=[time], name="x") >>> expr = m.add_expressions(x + 1, name="expr")