312312
313313function MOI. add_constraint (
314314 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
318325 return MOI. add_constraint (model. constraints, func, set)
319326end
320327
@@ -328,10 +335,17 @@ end
328335
329336function MOI. add_constraint (
330337 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)
335349end
336350
337351# MOI.NumberOfConstraints
0 commit comments