@@ -193,29 +193,63 @@ def add_vars(
193
193
raise ValueError ("`pandas_obj` must be an index, series, or dataframe" )
194
194
195
195
196
+ # Two overloads are used here to specify that at least one of the left- and
197
+ # right-hand sides must be a series (the other can be a single expression).
198
+
199
+
200
+ @overload
196
201
def add_constrs (
197
202
model : gp .Model ,
198
- lhs : Union [ pd .Series , float ] ,
203
+ lhs : pd .Series ,
199
204
sense : Union [pd .Series , str ],
200
- rhs : Union [pd .Series , float ],
205
+ rhs : Union [pd .Series , gp . Var , gp . LinExpr , gp . QuadExpr , float ],
201
206
* ,
202
207
name : Optional [str ] = None ,
203
208
index_formatter : Union [str , Callable , Mapping [str , Callable ]] = "default" ,
204
209
) -> pd .Series :
205
- """Add a constraint to the model for each row in lhs & rhs.
210
+ ... # pragma: no cover
211
+
212
+
213
+ @overload
214
+ def add_constrs (
215
+ model : gp .Model ,
216
+ lhs : Union [pd .Series , gp .Var , gp .LinExpr , gp .QuadExpr , float ],
217
+ sense : Union [pd .Series , str ],
218
+ rhs : pd .Series ,
219
+ * ,
220
+ name : Optional [str ] = None ,
221
+ index_formatter : Union [str , Callable , Mapping [str , Callable ]] = "default" ,
222
+ ) -> pd .Series :
223
+ ... # pragma: no cover
224
+
225
+
226
+ def add_constrs (
227
+ model ,
228
+ lhs ,
229
+ sense ,
230
+ rhs ,
231
+ * ,
232
+ name = None ,
233
+ index_formatter = "default" ,
234
+ ) -> pd .Series :
235
+ """Add a constraint to the model for each row in lhs & rhs. At least one of
236
+ `lhs` and `rhs` must be a Series, while the other side may be a constant or a
237
+ single gurobipy expression. If both sides are Series, then their indexes
238
+ must match.
206
239
207
240
Parameters
208
241
----------
209
242
model : Model
210
243
A Gurobi model to which new constraints will be added
211
244
lhs : Series
212
- A series of expressions forming the left hand side of constraints
245
+ A series of expressions forming the left hand side of constraints, a
246
+ constant, or a single expression.
213
247
sense : Series or str
214
248
Constraint sense; can be a series if senses vary, or a single string
215
249
if all constraints have the same sense
216
250
rhs : Series or float
217
- A series of expressions forming the right hand side of constraints,
218
- or a common constant
251
+ A series of expressions forming the right hand side of constraints, a
252
+ constant, or a single expression.
219
253
name : str
220
254
Used as the returned series name, as well as the base name for added
221
255
Gurobi constraints. Constraint name suffixes come from the lhs/rhs
0 commit comments