# Existing package to convert LP to standard form?

**URL:** <https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398>\
**Category:** Optimization (Mathematical)\
**Created:** [January 8, 2019, 9:36pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398 "2019-01-08T21:36:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [January 8, 2019, 9:36pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/1 "2019-01-08T21:36:35Z")

</div>

I’m working towards implementing a new type of solver for MILPs based on ADMM. This solver requires that the problem be specified as an LP in standard form (+ MI constraints). Before I go re-inventing the wheel, are there any existing packages that perform this conversion (raw LP spec to standard form)? I haven’t found anything so far since most solvers are wrappers around C libraries and that conversion to standard form happens at the C-library level. However, I’d like to write the solver itself in Julia. I didn’t see anything like this in MathProgBase or MathOptInterface, but I might have missed something. Thanks for any tips!

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [January 8, 2019, 11:27pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/2 "2019-01-08T23:27:18Z")

</div>

[`NLPModels.jl`](https://github.com/JuliaSmoothOptimizers/NLPModels.jl) will let you specify continuous optimization problems and convert them by adding slack variables. Currently, inequality constraints of the form \ell \leq c(x) \leq u are transformed to c(x) - s = 0 and \ell \leq s \leq u, where s are the slack variables. That should be ok for most solvers, but it wouldn’t be hard to actually perform the conversion to standard form. For example, you could read an LP in MPS format using [`QPSReader.jl`](https://github.com/JuliaSmoothOptimizers/QPSReader.jl), turn the result into a [`QuadraticModel`](https://github.com/JuliaSmoothOptimizers/QuadraticModels.jl) (a subtype of NLPModel), and then add slack variables to the result. The metadata contained in an NLPModel lets you specify which variables have integrality constraints on them, though we haven’t really exercised that facility much. So feedback there would be very welcome.

---

<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:** [January 9, 2019, 7:35am UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/3 "2019-01-09T07:35:32Z")

</div>

I think this should be relatively easy to do on the basis of [MathOptInterface](https://github.com/JuliaOpt/MathOptInterface.jl/), which also give [JuMP](https://github.com/JuliaOpt/JuMP.jl) support to your solver.

There’s also the [LinQuadOptInterface](https://github.com/JuliaOpt/LinQuadOptInterface.jl) intermediate layer that is more high-level used by several MIP solver wrappers.

But I did not find exactly the function to extract the LP data in matrix/vector form.

---

<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:** [January 9, 2019, 7:51am UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/4 "2019-01-09T07:51:43Z")

</div>

With [MathOptInterface](https://github.com/JuliaOpt/MathOptInterface.jl), a solver should only support the type of constraints for which he actually exploits the structure and not support any constraint types that are transformed internally into equivalent ones.  
The transformations are all done automatically using [bridges](http://www.juliaopt.org/MathOptInterface.jl/stable/apimanual/#Constraint-bridges-1).  
If your optimizer only support `MOI.SingleVariable`-in-`MOI.GreaterThan{Float64}` and `MOI.ScalarAffineFunction{Float64}`-in-`MOI.EqualTo{Float64}` (standard LP form), then the user will be able to use any LP form with JuMP.  
Slack variables, and so on will be automatically created by the bridges (note that a few bridges are currently missing but they are planning to be done in the coming days, see [VectorizeBridge and ScalarizeBridge · Issue #614 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/JuliaOpt/MathOptInterface.jl/issues/614), [Slack and Unslack bridge · Issue #528 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/JuliaOpt/MathOptInterface.jl/issues/528) and [nonpositives to nonnegatives bridge · Issue #516 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/JuliaOpt/MathOptInterface.jl/issues/516)).

---

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [January 9, 2019, 4:17pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/5 "2019-01-09T16:17:30Z")

</div>

Thank you for the tip. I didn’t really know about NLPModels.jl. I will come back to this solution if the JuMP/MathOptInterface solutions don’t work out.

---

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [January 9, 2019, 4:21pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/6 "2019-01-09T16:21:21Z")

</div>

Wow! I had hoped that this type of thing was supported in MathOptInterface, just didn’t quite know where to find it. Bridges look amazing. I’ll start testing with those that are already available. Looking forward to the rest of them coming as you’ve mentioned for slack variables since the method I’m looking at only supports equality constraints.

---

<div class="post-metadata">

**Author:** ![nlaws](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nlaws/32/22205_2.png) [@nlaws](https://discourse.julialang.org/u/nlaws)\
**Post date:** [April 7, 2021, 2:49pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/7 "2021-04-07T14:49:26Z")

</div>

I am also looking to convert a General LP to Standard LP - @ianfiske do you have any code or insights that you can share from what you found? (My use case requires manipulating the coefficient matrix of the equality constraints in the Standard form, i.e. `A` in `Ax=b`.)

---

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [April 7, 2021, 7:51pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/8 "2021-04-07T19:51:36Z")

</div>

Will [JuMP.set\_normalized\_coefficient](https://jump.dev/JuMP.jl/stable/reference/constraints/#JuMP.set_normalized_coefficient) work for you?

More here: [https://jump.dev/JuMP.jl/stable/constraints/#Modifying-a-variable-coefficient](https://jump.dev/JuMP.jl/stable/constraints/#Modifying-a-variable-coefficient)

---

<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:** [April 7, 2021, 8:10pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/9 "2021-04-07T20:10:45Z")

</div>

There’s also this code in JuMP to get the standard form:  
[https://github.com/jump-dev/JuMP.jl/blob/b6d9ddfc1f190986834eaef1c729098fb16ddf32/src/lp\_sensitivity2.jl#L301-L410](https://github.com/jump-dev/JuMP.jl/blob/b6d9ddfc1f190986834eaef1c729098fb16ddf32/src/lp_sensitivity2.jl#L301-L410)  
although it’s not public, so it may change in any future release.

---

<div class="post-metadata">

**Author:** ![nlaws](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nlaws/32/22205_2.png) [@nlaws](https://discourse.julialang.org/u/nlaws)\
**Post date:** [April 7, 2021, 10:24pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/10 "2021-04-07T22:24:43Z")

</div>

Thanks! That is what I need to manipulate `A` once it is defined in the `Model`.

---

<div class="post-metadata">

**Author:** ![nlaws](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nlaws/32/22205_2.png) [@nlaws](https://discourse.julialang.org/u/nlaws)\
**Post date:** [April 7, 2021, 10:27pm UTC](https://discourse.julialang.org/t/existing-package-to-convert-lp-to-standard-form/19398/11 "2021-04-07T22:27:12Z")

</div>

Thank you! This is the solution that I was looking for.
