Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ makedocs(
"Tutorials" => [
"tutorials/example.md",
"tutorials/implementing.md",
"tutorials/mathprogbase.md",
],
"Manual" => [
"manual/standard_form.md",
Expand Down
97 changes: 97 additions & 0 deletions docs/src/tutorials/mathprogbase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Transitioning from MathProgBase

MathOptInterface is a replacement for [MathProgBase.jl](https://github.com/JuliaOpt/MathProgBase.jl).
However, it is not a direct replacement.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't https://github.com/jump-dev/MatrixOptInterface.jl providing a closer interface to what MPB looked like?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the modeling side, yes. But it still needs some development to integrate properly, so I held off mentioning it.


## Transitioning a solver interface

Writing a solver interface in MathOptInterface is more work than the equivalent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say this. It may potentially be much closer to the solver. MPB was tailored to 3 specific format. If you didn't fit then it was way more work. CSDP MPB wrapper was so complicated I had to create SemidefiniteModels.jl. Now it's quite simple.

Copy link
Member

@blegat blegat Aug 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For conic solver, it will be simpler than with MPB with MatrixOfConstraints.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a PR with the suggested wording. I didn't think it was controversial that it was more complicated! We now have lots of constraint types and attributes and copy-to and caching and layers. It might be simpler for you, but it certainly isn't for most people.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends what you mean by simpler I guess :)

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](https://github.com/jump-dev/JuMP.jl)
as a modeling interface 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
```