# Checking membership in a MathOptInterface Set

**URL:** <https://discourse.julialang.org/t/checking-membership-in-a-mathoptinterface-set/47642>\
**Category:** Optimization (Mathematical)\
**Tags:** package, jump, optimization\
**Created:** [October 2, 2020, 2:12pm UTC](https://discourse.julialang.org/t/checking-membership-in-a-mathoptinterface-set/47642 "2020-10-02T14:12:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![1ozturkbe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1ozturkbe/32/16461_2.png) [@1ozturkbe](https://discourse.julialang.org/u/1ozturkbe)\
**Post date:** [October 2, 2020, 2:12pm UTC](https://discourse.julialang.org/t/checking-membership-in-a-mathoptinterface-set/47642/1 "2020-10-02T14:12:26Z")

</div>

Hello folks,

I hope this is an easy question, but unfortunately some of the internals of MathOptInterface and JuMP are opaque. `constraint_object(constraint::ConstraintRef)` operation in JuMP returns a ScalarConstraint, which has `.func` and `.set` attributes. I know how to evaluate the `.func`, but I am still confused about how to confirm membership in the set (i.e. feasibility to the constraint). Here is a MWE.

```julia
using MathOptInterface
val = 18.
set = MathOptInterface.GreaterThan{Float64}(-2.)
# How do I confirm membership in the set, returning Bool, or distance from constraint boundary?

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![1ozturkbe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1ozturkbe/32/16461_2.png) [@1ozturkbe](https://discourse.julialang.org/u/1ozturkbe)\
**Post date:** [October 2, 2020, 2:18pm UTC](https://discourse.julialang.org/t/checking-membership-in-a-mathoptinterface-set/47642/2 "2020-10-02T14:18:45Z")

</div>

I guess another way to put it is, how does one convert a `ScalarConstraint` to a JuMP expression that can be evaluated?

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [October 2, 2020, 5:57pm UTC](https://discourse.julialang.org/t/checking-membership-in-a-mathoptinterface-set/47642/3 "2020-10-02T17:57:48Z")

</div>

Not sure if this answers your questions, but there is a package [MathOptSetDistances.jl](https://github.com/matbesancon/MathOptSetDistances.jl) that is able to check set membership for several sets in MOI, a functionality that is not provided by MOI itself, I believe.

---

<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:** [October 3, 2020, 10:26pm UTC](https://discourse.julialang.org/t/checking-membership-in-a-mathoptinterface-set/47642/4 "2020-10-03T22:26:25Z")

</div>

See here for the full saga: [https://github.com/jump-dev/MathOptInterface.jl/pull/1023](https://github.com/jump-dev/MathOptInterface.jl/pull/1023)

---

<div class="post-metadata">

**Author:** ![1ozturkbe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1ozturkbe/32/16461_2.png) [@1ozturkbe](https://discourse.julialang.org/u/1ozturkbe)\
**Post date:** [October 5, 2020, 3:13pm UTC](https://discourse.julialang.org/t/checking-membership-in-a-mathoptinterface-set/47642/5 "2020-10-05T15:13:09Z")

</div>

Wow, thanks @odow for the blow-by-blow. I see how difficult it is to define a notion of set distance and not step on anyones’ toes 😛

---

<div class="post-metadata">

**Author:** ![1ozturkbe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1ozturkbe/32/16461_2.png) [@1ozturkbe](https://discourse.julialang.org/u/1ozturkbe)\
**Post date:** [October 5, 2020, 3:13pm UTC](https://discourse.julialang.org/t/checking-membership-in-a-mathoptinterface-set/47642/6 "2020-10-05T15:13:59Z")

</div>

Thanks @leethargo for the reference. Will check it out and get back here!
