I have a piece of code that adds SOS2 constraints to a model.
If the solver supports it, I would like to use its interface, if not I would assemble the constraints myself.
Is there a way to check if an optimizer supports MathOptInterface.SOS2
constraints?
Just wrapping JuMP.@constraint
in a try catch
seems not like the proper way.
You’re looking for something like:
model = Model(with_optimizer(CPLEX.Optimizer))
MOI.supports_constraint(
CPLEX.Optimizer(), MOI.VectorOfVariables, MOI.SOS2{Float64}
)
(Replace CPLEX with the solver of your choice.)
Edit(odow): my first solution wasn’t strictly correct in all cases.
Would it be possible to not need to know the specific solver?
Hmm. I dug into my earlier suggestion, which was:
MOI.supports_constraint(
backend(model), MOI.VectorOfVariables, MOI.SOS2{Float64}
)
and it seems to work:
using JuMP, SCS
model = Model(with_optimizer(SCS.Optimizer))
MOI.supports_constraint(
backend(model), MOI.VectorOfVariables, MOI.SOS2{Float64}
) # false