# How to link a JuMP model and a general algorithm together?

**URL:** <https://discourse.julialang.org/t/how-to-link-a-jump-model-and-a-general-algorithm-together/118356>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, optimization\
**Created:** [August 19, 2024, 2:19am UTC](https://discourse.julialang.org/t/how-to-link-a-jump-model-and-a-general-algorithm-together/118356 "2024-08-19T02:19:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [August 19, 2024, 2:19am UTC](https://discourse.julialang.org/t/how-to-link-a-jump-model-and-a-general-algorithm-together/118356/1 "2024-08-19T02:19:36Z")

</div>

Suppose there is a general algorithm for some kind of optimization problem in a standard form, and then there is an instance of this kind of problem which is however not written in the standard form. Both of the algorithm and the instance are written with `JuMP`. Obviously, now there is a need for us to convert the naturally written instance into the standard form for solving. Then what is the next step that we should do?

---

<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:** [August 20, 2024, 1:14am UTC](https://discourse.julialang.org/t/how-to-link-a-jump-model-and-a-general-algorithm-together/118356/2 "2024-08-20T01:14:57Z")

</div>

This question is too general to provide an answer for.

What is the algorithm? What is the standard form? What sub solvers? etc.

In general, if your algorithm operates on a fixed input data that is representable using the MathOptInterface standard form (i.e., function -in- set), then the suggested approach is to implement an interface to MathOptInterface.jl. Look at the various existing packages for inspiration. The fact that you use JuMP internally in your algorithm is an implementation detail.

But if your algorithm operates as a JuMP extension on an existing JuMP model, then it depends. You’ll need to provide more information.

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [August 20, 2024, 1:59am UTC](https://discourse.julialang.org/t/how-to-link-a-jump-model-and-a-general-algorithm-together/118356/3 "2024-08-20T01:59:15Z")

</div>

Thank you @odow !

I know `MathOptInterface.jl` may help but I don’t get familiar with it for now. Maybe I should write an algorithm directly with `MathOptInterface.jl` instead of `JuMP.jl`. But now the algorithm is given by a function like for example

```julia
function myLP(A, b, c)
    # Here is a JuMP model for the LP: min c'x s.t. Ax ≤ b.
end

```

Now if I have an arbitrary LP problem written with `JuMP`, how should I extract from it the `A`, `b` and `c` automatically?

---

<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:** [August 20, 2024, 2:21am UTC](https://discourse.julialang.org/t/how-to-link-a-jump-model-and-a-general-algorithm-together/118356/4 "2024-08-20T02:21:35Z")

</div>

If your problem is an LP, then you can use: [Models · JuMP](https://jump.dev/JuMP.jl/stable/manual/models/#Get-the-matrix-representation)

See also [Connecting a simple first-order solver to solve standard form linear program to JuMP](https://discourse.julialang.org/t/connecting-a-simple-first-order-solver-to-solve-standard-form-linear-program-to-jump/95694)

and [GitHub - Shuvomoy/SimplePDHG.jl: Implements vanilla PDHG algorithm](https://github.com/Shuvomoy/SimplePDHG.jl)

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [August 20, 2024, 2:59am UTC](https://discourse.julialang.org/t/how-to-link-a-jump-model-and-a-general-algorithm-together/118356/5 "2024-08-20T02:59:51Z")

</div>

Thanks. I’ll try to understand the things. 🤝🤝
