# \[JuMP\] Connecting JuMP to custom Solver Simplex

**URL:** <https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623>\
**Category:** Optimization (Mathematical)\
**Tags:** question, package, jump\
**Created:** [May 17, 2020, 5:54am UTC](https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623 "2020-05-17T05:54:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaulBritto](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raulbritto/32/15002_2.png) [@RaulBritto](https://discourse.julialang.org/u/RaulBritto)\
**Post date:** [May 17, 2020, 5:54am UTC](https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623/1 "2020-05-17T05:54:47Z")

</div>

Hello, I’m new in Julia Language and I’m currently coding the Simplex algorithm and I would like to use JuMP to write the optimization models to my solver. My ideia is write the models using JuMP and call my solver or JuMP pass the problem in Simplex’s standard form. I don’t know to do that and I don’t even know if it is possible to that using JuMP. Anyone could help me?

---

<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:** [May 17, 2020, 8:36am UTC](https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623/2 "2020-05-17T08:36:14Z")

</div>

Yes, that’s possible. See [Manual · MathOptInterface](http://www.juliaopt.org/MathOptInterface.jl/stable/apimanual/)

---

<div class="post-metadata">

**Author:** ![RaulBritto](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raulbritto/32/15002_2.png) [@RaulBritto](https://discourse.julialang.org/u/RaulBritto)\
**Post date:** [May 17, 2020, 12:09pm UTC](https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623/3 "2020-05-17T12:09:42Z")

</div>

I read the MOI’s documentation, but I couldn’t understand how to “translate” the model defined using JuMP to the standard form using MOI’s API. I’ve tried some functions and methods but I didn’t get any success.

![image](https://global.discourse-cdn.com/julialang/original/3X/8/4/849b9b30b36aeeada8cb0103ed0ef9906fdb617e.png)

I already have a model defined using JuMP and I would like to generate the standard form matrix for that.

---

<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:** [May 17, 2020, 12:42pm UTC](https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623/4 "2020-05-17T12:42:01Z")

</div>

@Wikunia has a blog post about connecting his solver to JuMP; maybe it will be useful for you: [Constraint Solver: How to use JuMP for your own solver?](https://opensourc.es/blog/constraint-solver-jump).

---

<div class="post-metadata">

**Author:** ![Wikunia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wikunia/32/2180_2.png) [@Wikunia](https://discourse.julialang.org/u/Wikunia)\
**Post date:** [May 17, 2020, 12:57pm UTC](https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623/5 "2020-05-17T12:57:49Z")

</div>

Yeah as @ericphanson mentioned I did something like that for my ConstraintSolver. Feel free to reach out if you have questions. For example if you’re in the slack we can chat 😉

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [May 17, 2020, 2:31pm UTC](https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623/6 "2020-05-17T14:31:53Z")

</div>

You don’t have to do the translation to the standard LP format, it is do for you automatically by bridges. You just have to specify which constraint type you support with `support_constraint`. In your case, if it’s the standard LP format, you only support nonnegative variables and linear equality constraint. I would suggest to look at [CSDP](https://github.com/JuliaOpt/CSDP.jl/blob/master/src/MOI_wrapper.jl) and [SDPA](https://github.com/JuliaOpt/SDPA.jl/blob/master/src/MOI_wrapper.jl) their format is the same with the added support for SDP variables (just ignore it)

---

<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:** [May 17, 2020, 4:15pm UTC](https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623/7 "2020-05-17T16:15:30Z")

</div>

The easiest thing to do is to copy Clp.jl.

In particular, it has code that extracts data for LPs in the standard form:

```julia
min c'x
s.t. rl <= Ax <= ru
     cl <= x <= cu

```

See here, for example:

> <https://github.com/jump-dev/Clp.jl/blob/dfb2c475788f86dafb7f7ce2849c1957ebc4a638/src/MOI_wrapper/MOI_wrapper.jl#L268-L280>

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [May 18, 2020, 11:22am UTC](https://discourse.julialang.org/t/jump-connecting-jump-to-custom-solver-simplex/39623/8 "2020-05-18T11:22:21Z")

</div>

It depends what is meant by standard form here. If the LP standard form is

```julia
min c'x
s.t. Ax = b
     x >= 0

```

Then what you need to do is

```julia
function MOI.supports_add_constrained_variables( # don't support free variables (they should all be nonnegatives)
    ::Optimizer, ::Type{MOI.Reals})
    return false
end
function MOI.supports_add_constrained_variables( # support nonnegative variables
    ::Optimizer, ::Type{MOI.Nonnegatives})
    return true
end
function MOI.add_constrained_variables(
    optimizer::Optimizer,
    set::MOI.Nonnegatives)
    # TODO load variables and return variables indices and constraint index
end
function MOI.supports( # support affine objective : c'x + constant
    ::Optimizer,
    ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}})
    return true
end
function MOI.set(
    optimizer::Optimizer,
    ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}},
    func::MOI.ScalarAffineFunction{Float64})
    # TODO load objective function
end
function MOI.supports_constraint( # support equalities A[i,:]'x = b[i]
    ::Optimizer, ::Type{MOI.ScalarAffineFunction{Float64}},
    ::Type{MOI.EqualTo{Float64}})
    return true
end
function MOI.add_constraint(
    ::Optimizer,
    func::MOI.ScalarAffineFunction{Float64},
    set::MOI.EqualTo{Float64})
    # TODO load constraint and return constraint index
end

```
