|
1 | 1 | # MatrixOptInterface.jl |
2 | | -An interface for matrix form optimization problems |
| 2 | + |
| 3 | +**This package is this in early development, feedback is welcome!** |
| 4 | + |
| 5 | +An interface for optimization problems in matrix forms. |
| 6 | +Several matrix forms are represented in subtypes of |
| 7 | +[`MathOptInterface (MOI)`](https://github.com/jump-dev/MathOptInterface.jl) |
| 8 | +models. |
| 9 | +As they implement the MOI API, they can be copied directly to an MOI or JuMP |
| 10 | +model. |
| 11 | + |
| 12 | +Here is a simple example copying a linear program represented in its standard |
| 13 | +form into JuMP: |
| 14 | +```julia |
| 15 | +import MatrixOptInterface |
| 16 | +const MatOI = MatrixOptInterface |
| 17 | +lp = MatOI.LPStandardForm{Float64, Matrix{Float64}}(MOI.MAX_SENSE, [1.0, 0.0], [1.0 1.0], [1.0]) |
| 18 | + |
| 19 | +using JuMP |
| 20 | +model = Model() |
| 21 | +MOI.copy_to(model, lp) |
| 22 | +``` |
| 23 | + |
| 24 | +Giving some arbitrary names to the variables for pretty printing: |
| 25 | +```julia |
| 26 | +set_name.(all_variables(model), "x" .* string.(1:2)) |
| 27 | +print(model) |
| 28 | +``` |
| 29 | +we get the following output: |
| 30 | +``` |
| 31 | +Max x1 |
| 32 | +Subject to |
| 33 | + x1 + x2 = 1.0 |
| 34 | + [x1, x2] ∈ MathOptInterface.Nonnegatives(2) |
| 35 | +``` |
| 36 | + |
| 37 | +The LP standard form is the the only one implemented in this package. |
| 38 | +The 4 different available forms of linear programs are given below. |
| 39 | +In each form, `sense` is a `MOI.OptimizationSense` so its values |
| 40 | +are either `MOI.FEASIBILITY_SENSE`, `MOI.MAX_SENSE` or `MOI.MIN_SENSE`. |
| 41 | + |
| 42 | +An LP standard form with `LPStandardForm(sense, c, A, b)`: |
| 43 | +``` |
| 44 | +sense ⟨c, x⟩ |
| 45 | +s.t. |
| 46 | +Ax == b |
| 47 | + x >= 0 |
| 48 | +``` |
| 49 | + |
| 50 | +An LP geometric form with `LPGeometricForm(sense, c, A, b)`: |
| 51 | +``` |
| 52 | +sense ⟨c, x⟩ |
| 53 | +s.t. |
| 54 | +Ax <= b |
| 55 | +``` |
| 56 | + |
| 57 | +A generic LP form with `LPForm(sense, c, A, c_lb, c_ub, v_lb, v_ub)`: |
| 58 | +``` |
| 59 | +sense ⟨c, x⟩ |
| 60 | +s.t. |
| 61 | +c_lb <= Ax <= c_ub |
| 62 | +v_lb <= x <= v_ub |
| 63 | +``` |
| 64 | + |
| 65 | +An LP Solver form with `LPSolverForm(sense, c, A, b, senses, v_lb, v_ub)`: |
| 66 | +``` |
| 67 | +sense ⟨c, x⟩ |
| 68 | +s.t. |
| 69 | +Ax senses b |
| 70 | +v_lb <= x <= v_ub |
| 71 | +``` |
| 72 | +where `senses` is a vector whose `i`th entry is either |
| 73 | +* `MatOI.EQUAL_TO` if `(Ax)_i = b_i`, |
| 74 | +* `MatOI.LESS_THAN` if `(Ax)_i <= b_i`, |
| 75 | +* `MatOI.GREATER_THAN` if `(Ax)_i >= b_i`. |
| 76 | + |
| 77 | +## Transition from linprog |
| 78 | + |
| 79 | +If you are used to [`MathProgBase`](https://github.com/JuliaOpt/MathProgBase.jl)'s or MATLAB's `linprog` function, this package provides an easy transition. |
| 80 | +The package does not provide a one-shot function that takes the form as input are returns the solution and status as |
| 81 | +in general, solvers may have multiple solutions to report and the status cannot be summarized in a single value. |
| 82 | +`MathOptInterface` embraces this complexity and allows to retrieve multiple solutions, |
| 83 | +has 4 different solver-independent statuses (`MOI.TerminationStatus`, `MOI.PrimalStatus`, `MOI.DualStatus` and `MOI.RawStatusString`) and also |
| 84 | +allows solvers to provide solver independent statuses. |
| 85 | +For these reasons, there is no `linprog` functions covering all use cases but using this packages one covering your use cases can be implemented in just a few lines: |
| 86 | +1) Create the appropriate structure from the matrix data, e.g. `LPForm`, `LPSolverForm`, ... |
| 87 | +2) Copy it to a JuMP model or MOI optimizer. |
| 88 | +3) Call `JuMP.optimize!` or `MOI.optimize!`. |
| 89 | +4) Retrieve and return solutions and statuses. |
0 commit comments