# How to check if a solver supports SOS2 constraints

**URL:** <https://discourse.julialang.org/t/how-to-check-if-a-solver-supports-sos2-constraints/34186>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [February 4, 2020, 8:40pm UTC](https://discourse.julialang.org/t/how-to-check-if-a-solver-supports-sos2-constraints/34186 "2020-02-04T20:40:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [February 4, 2020, 8:40pm UTC](https://discourse.julialang.org/t/how-to-check-if-a-solver-supports-sos2-constraints/34186/1 "2020-02-04T20:40:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 4, 2020, 9:12pm UTC](https://discourse.julialang.org/t/how-to-check-if-a-solver-supports-sos2-constraints/34186/2 "2020-02-04T21:12:49Z")

</div>

You’re looking for something like:

```nohighlight
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.

---

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [February 5, 2020, 8:43am UTC](https://discourse.julialang.org/t/how-to-check-if-a-solver-supports-sos2-constraints/34186/3 "2020-02-05T08:43:34Z")

</div>

Would it be possible to not need to know the specific solver?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 5, 2020, 2:22pm UTC](https://discourse.julialang.org/t/how-to-check-if-a-solver-supports-sos2-constraints/34186/4 "2020-02-05T14:22:59Z")

</div>

Hmm. I dug into my earlier suggestion, which was:

```nohighlight
MOI.supports_constraint(
    backend(model), MOI.VectorOfVariables, MOI.SOS2{Float64}
)

```

and it seems to work:

```nohighlight
using JuMP, SCS
model = Model(with_optimizer(SCS.Optimizer))
MOI.supports_constraint(
    backend(model), MOI.VectorOfVariables, MOI.SOS2{Float64}
) # false

```
