From adab90b7b70dba6547d35e3e552c9b6eb364e0d2 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 3 Aug 2021 15:43:53 +1200 Subject: [PATCH 1/2] [docs] Add tutorial on transitioning from MPB --- docs/make.jl | 1 + docs/src/tutorials/mathprogbase.md | 96 ++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 docs/src/tutorials/mathprogbase.md diff --git a/docs/make.jl b/docs/make.jl index c8b5ac8c26..3d8d953291 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -27,6 +27,7 @@ makedocs( "Tutorials" => [ "tutorials/example.md", "tutorials/implementing.md", + "tutorials/mathprogbase.md", ], "Manual" => [ "manual/standard_form.md", diff --git a/docs/src/tutorials/mathprogbase.md b/docs/src/tutorials/mathprogbase.md new file mode 100644 index 0000000000..f283f6de9d --- /dev/null +++ b/docs/src/tutorials/mathprogbase.md @@ -0,0 +1,96 @@ +# Transitioning from MathProgBase + +MathOptInterface is a replacement for [MathProgBase.jl](https://github.com/JuliaOpt/MathProgBase.jl). +However, it is not a direct replacement. + +## Transitioning a solver interface + +Writing a solver interface in MathOptInterface is more work than the equivalent +interface in MathProgBase. + +For more information, read [Implementing a solver interface](@ref). + +## Transitioning the high-level functions + +MathOptInterface doesn't provide replacements for the high-level interfaces in +MathProgBase. We recommend you use JuMP instead. + +!!! tip + If you haven't used JuMP before, start with the tutorial + [Getting started with JuMP](https://jump.dev/JuMP.jl/stable/tutorials/Getting%20started/getting_started_with_JuMP/) + +### linprog + +Here is one way of transitioning from `linprog`: + +```julia +using JuMP + +function linprog(c, A, sense, b, l, u, solver) + N = length(c) + model = Model(solver) + @variable(model, l[i] <= x[i=1:N] <= u[i]) + @objective(model, Min, c' * x) + eq_rows, ge_rows, le_rows = sense .== '=', sense .== '>', sense .== '<' + @constraint(model, A[eq_rows, :] * x .== b[eq_rows]) + @constraint(model, A[ge_rows, :] * x .>= b[ge_rows]) + @constraint(model, A[le_rows, :] * x .<= b[le_rows]) + optimize!(model) + return ( + status = termination_status(model), + objval = objective_value(model), + sol = value.(x) + ) +end +``` + +### mixintprog + +Here is one way of transitioning from `mixintprog`: + +```julia +using JuMP + +function mixintprog(c, A, rowlb, rowub, vartypes, lb, ub, solver) + N = length(c) + model = Model(solver) + @variable(model, lb[i] <= x[i=1:N] <= ub[i]) + for i in 1:N + if vartypes[i] == :Bin + set_binary(x[i]) + elseif vartypes[i] == :Int + set_integer(x[i]) + end + end + @objective(model, Min, c' * x) + @constraint(model, rowlb .<= A * x .<= rowub) + optimize!(model) + return ( + status = termination_status(model), + objval = objective_value(model), + sol = value.(x) + ) +end +``` + +### quadprog + +Here is one way of transitioning from `quadprog`: + +```julia +using JuMP + +function quadprog(c, Q, A, rowlb, rowub, lb, ub, solver) + N = length(c) + model = Model(solver) + @variable(model, lb[i] <= x[i=1:N] <= ub[i]) + @objective(model, Min, c' * x + 0.5 * x' * Q * x) + @constraint(model, rowlb .<= A * x .<= rowub) + optimize!(model) + return ( + status = termination_status(model), + objval = objective_value(model), + sol = value.(x) + ) +end +``` From eb47568e13d2dba20c6b76856eef2df043e0d87a Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 4 Aug 2021 10:06:12 +1200 Subject: [PATCH 2/2] Update mathprogbase.md --- docs/src/tutorials/mathprogbase.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/tutorials/mathprogbase.md b/docs/src/tutorials/mathprogbase.md index f283f6de9d..f268748bb7 100644 --- a/docs/src/tutorials/mathprogbase.md +++ b/docs/src/tutorials/mathprogbase.md @@ -13,7 +13,8 @@ For more information, read [Implementing a solver interface](@ref). ## Transitioning the high-level functions MathOptInterface doesn't provide replacements for the high-level interfaces in -MathProgBase. We recommend you use JuMP instead. +MathProgBase. We recommend you use [JuMP](https://github.com/jump-dev/JuMP.jl) +as a modeling interface instead. !!! tip If you haven't used JuMP before, start with the tutorial