312
312
313
313
function MOI. add_constraint (
314
314
model:: AbstractModel ,
315
- func:: MOI.AbstractFunction ,
316
- set:: MOI.AbstractSet ,
317
- )
315
+ func:: F ,
316
+ set:: S ,
317
+ ) where {F<: MOI.AbstractFunction ,S<: MOI.AbstractSet }
318
+ # We check supports_constraint here because it is a common practice for
319
+ # AbstractModels to declare that they do not support particular constraints,
320
+ # even though the underlying `.constraints` object does. See, for example,
321
+ # the various models in MOI.FileFormats.
322
+ if ! MOI. supports_constraint (model, F, S)
323
+ throw (MOI. UnsupportedConstraint {F,S} ())
324
+ end
318
325
return MOI. add_constraint (model. constraints, func, set)
319
326
end
320
327
@@ -328,10 +335,17 @@ end
328
335
329
336
function MOI. add_constraint (
330
337
model:: AbstractModel ,
331
- f:: MOI.VariableIndex ,
332
- s:: MOI.AbstractScalarSet ,
333
- )
334
- return MOI. add_constraint (model. variables, f, s)
338
+ func:: MOI.VariableIndex ,
339
+ set:: S ,
340
+ ) where {S<: MOI.AbstractScalarSet }
341
+ # We check supports_constraint here because it is a common practice for
342
+ # AbstractModels to declare that they do not support particular constraints,
343
+ # even though the underlying `.constraints` object does. See, for example,
344
+ # the various models in MOI.FileFormats.
345
+ if ! MOI. supports_constraint (model, MOI. VariableIndex, S)
346
+ throw (MOI. UnsupportedConstraint {MOI.VariableIndex,S} ())
347
+ end
348
+ return MOI. add_constraint (model. variables, func, set)
335
349
end
336
350
337
351
# MOI.NumberOfConstraints
0 commit comments