linopy.model.Model.add_variables#
- Model.add_variables(lower=-inf, upper=inf, coords=None, name=None, mask=None, binary=False, integer=False, **kwargs)#
Assign a new, possibly multi-dimensional array of variables to the model.
Variables may be added with lower and/or upper bounds. Unless a coords argument is provided, the shape of the lower and upper bounds define the number of variables which will be added to the model under the name name.
- Parameters:
lower (
float/array_like
, optional) – Lower bound of the variable(s). Ignored if binary is True. The default is -inf.upper (
TYPE
, optional) – Upper bound of the variable(s). Ignored if binary is True. The default is inf.coords (
list/xarray.Coordinates
, optional) – The coords of the variable array. These are directly passed to the DataArray creation of lower and upper. For every single combination of coordinates a optimization variable is added to the model. The default is None.name (
str
, optional) – Reference name of the added variables. The default None results in a name like “var1”, “var2” etc.mask (
array_like
, optional) – Boolean mask with False values for variables which are skipped. The shape of the mask has to match the shape the added variables. Default is None.binary (
bool
) – Whether the new variable is a binary variable which are used for Mixed-Integer problems.integer (
bool
) – Whether the new variable is a integer variable which are used for Mixed-Integer problems.**kwargs – Additional keyword arguments are passed to the DataArray creation.
- Raises:
ValueError – If neither lower bound and upper bound have coordinates, nor coords are directly given.
- Returns:
linopy.Variable
– Variable which was added to the model.
Examples
>>> from linopy import Model >>> import pandas as pd >>> m = Model() >>> time = pd.RangeIndex(10, name="Time") >>> m.add_variables(lower=0, coords=[time], name="x") Variable (Time: 10) ------------------- [0]: x[0] ∈ [0, inf] [1]: x[1] ∈ [0, inf] [2]: x[2] ∈ [0, inf] [3]: x[3] ∈ [0, inf] [4]: x[4] ∈ [0, inf] [5]: x[5] ∈ [0, inf] [6]: x[6] ∈ [0, inf] [7]: x[7] ∈ [0, inf] [8]: x[8] ∈ [0, inf] [9]: x[9] ∈ [0, inf]