# How can i use sets created using LasySets.jl with Convex.jl variables?

**URL:** https://discourse.julialang.org/t/how-can-i-use-sets-created-using-lasysets-jl-with-convex-jl-variables/52572
**Category:** Specific Domains
**Created:** [December 29, 2020, 1:00pm UTC](https://discourse.julialang.org/t/how-can-i-use-sets-created-using-lasysets-jl-with-convex-jl-variables/52572 "2020-12-29T13:00:18Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![adropintheriver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adropintheriver/32/20634_2.png) [@adropintheriver](https://discourse.julialang.org/u/adropintheriver)
#### Post date: [December 29, 2020, 1:00pm UTC](https://discourse.julialang.org/t/how-can-i-use-sets-created-using-lasysets-jl-with-convex-jl-variables/52572/1 "2020-12-29T13:00:18Z")

</div>

Is there a way i can create LazySets Polyhedron and use it as a variable in my optimization program that uses Convex.jl, use them in constraints i want to add to the problem?.

---

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [December 29, 2020, 1:17pm UTC](https://discourse.julialang.org/t/how-can-i-use-sets-created-using-lasysets-jl-with-convex-jl-variables/52572/2 "2020-12-29T13:17:34Z")

</div>

I don’t think there’s any interoperability already set up for those two packages. I think you can use Polyhedra.jl to create a constraint for JuMP.jl, however: [http://juliapolyhedra.github.io/Polyhedra.jl/stable/optimization/#Polyhedra.linear\_objective\_solver](http://juliapolyhedra.github.io/Polyhedra.jl/stable/optimization/#Polyhedra.linear_objective_solver).

---

<div class="post-metadata">

### Author: ![adropintheriver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adropintheriver/32/20634_2.png) [@adropintheriver](https://discourse.julialang.org/u/adropintheriver)
#### Post date: [December 29, 2020, 1:21pm UTC](https://discourse.julialang.org/t/how-can-i-use-sets-created-using-lasysets-jl-with-convex-jl-variables/52572/3 "2020-12-29T13:21:28Z")

</div>

Thanks.

---

<div class="post-metadata">

### Author: ![mforets](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mforets/32/298_2.png) [@mforets](https://discourse.julialang.org/u/mforets)
#### Post date: [December 29, 2020, 1:49pm UTC](https://discourse.julialang.org/t/how-can-i-use-sets-created-using-lasysets-jl-with-convex-jl-variables/52572/4 "2020-12-29T13:49:41Z")

</div>

Hi @adropintheriver,

Integration of LazySets.jl types with JuMP is implemented in the package [InvariantSets.jl](https://github.com/ueliwechsler/InvariantSets.jl#integration-with-jumpjl) (thanks to @uweschler). We should probably refactor that conversion code to LazySets.jl and make it available when users load JuMP.

With respecto to Convex.jl I’m not aware of such conversions but I guess it shouldn’t be too hard  
(PRs welcome).

---

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [December 29, 2020, 1:54pm UTC](https://discourse.julialang.org/t/how-can-i-use-sets-created-using-lasysets-jl-with-convex-jl-variables/52572/5 "2020-12-29T13:54:01Z")

</div>

Nice! If InvariantSets.jl worked on the MathOptInterface (MOI) level instead of the JuMP level, then support for Convex should be even easier (since both Convex and JuMP are MOI frontends). MOI can be a bit harder to work with than JuMP though so maybe it’s not worth it.

---

<div class="post-metadata">

### Author: ![mforets](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mforets/32/298_2.png) [@mforets](https://discourse.julialang.org/u/mforets)
#### Post date: [December 29, 2020, 10:42pm UTC](https://discourse.julialang.org/t/how-can-i-use-sets-created-using-lasysets-jl-with-convex-jl-variables/52572/6 "2020-12-29T22:42:19Z")

</div>

Do you have a use case or MWE of the kind of problem you want to address?

Note that constraints can be added easily in this way:

```julia
using LazySets, Convex, SCS

function Convex.add_constraint!(x::Convex.AbstractVariable, X::LazySet)
    A, b = tosimplehrep(X)
    add_constraint!(x, A*x ≤ b)
end

```

Example use:

```julia
function supfunc(d::AbstractVector, X::LazySet; solver=SCS.Optimizer(verbose=false))
    x = Variable(length(d))
    add_constraint!(x, X) # x ∈ X
    xᵀd = dot(x, d)
    solve!(maximize(xᵀd), solver)
    return evaluate(xᵀd)
end

X = rand(VPolygon)
d = ones(2)

supfunc(d, X) ≈ ρ(d, X) # ρ is defined on LazySets for each set / lazy operation
true

```

---

<div class="post-metadata">

### Author: ![adropintheriver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adropintheriver/32/20634_2.png) [@adropintheriver](https://discourse.julialang.org/u/adropintheriver)
#### Post date: [January 2, 2021, 1:49am UTC](https://discourse.julialang.org/t/how-can-i-use-sets-created-using-lasysets-jl-with-convex-jl-variables/52572/8 "2021-01-02T01:49:27Z")

</div>

hi @mforets, yes, i have tried to describe the use-case here [3D bin packaging using Convex.jl](https://discourse.julialang.org/t/3d-bin-packaging-using-convex-jl/52571)
