Model.add_constraints(lhs, sign=None, rhs=None, name=None, coords=None, mask=None)#

Assign a new, possibly multi-dimensional array of constraints to the model.

Constraints are added by defining a left hand side (lhs), the sign and the right hand side (rhs). The lhs has to be a linopy.LinearExpression and the rhs a constant (array of constants). The function return the an array with the constraint labels (integers).

  • lhs (linopy.LinearExpression/linopy.Constraint/callable) – Left hand side of the constraint(s) or optionally full constraint. In case a linear expression is passed, sign and rhs must not be None. If a function is passed, it is called for every combination of coordinates given in coords. It’s first argument has to be the model, followed by scalar argument for each coordinate given in coordinates.

  • sign (str/array_like) – Relation between the lhs and rhs, valid values are {‘=’, ‘>=’, ‘<=’}.

  • rhs (int/float/array_like) – Right hand side of the constraint(s).

  • name (str, optional) – Reference name of the added constraints. The default None results results a name like “con1”, “con2” etc.

  • coords (list/xarray.Coordinates, optional) – The coords of the constraint array. This is only used when lhs is a function. The default is None.

  • mask (array_like, optional) – Boolean mask with False values for constraints which are skipped. The shape of the mask has to match the shape the added constraints. Default is None.


labels (linopy.model.Constraint) – Array containing the labels of the added constraints.