|
3 | 3 | [](https://github.com/samuelsonric/MathOptChordalDecomposition.jl/actions/workflows/ci.yml) |
4 | 4 | [](https://codecov.io/gh/samuelsonric/MathOptChordalDecomposition.jl) |
5 | 5 |
|
6 | | -MathOptChordalDecomposition.jl is a [MathOptInterface.jl](https://github.com/jump-dev/MathOptInterface.jl) layer that implements chordal decomposition of |
7 | | -sparse semidefinite constraints. |
| 6 | +MathOptChordalDecomposition.jl is a [MathOptInterface.jl](https://github.com/jump-dev/MathOptInterface.jl) |
| 7 | +layer that implements chordal decomposition of sparse semidefinite constraints. |
8 | 8 |
|
9 | | -## Basic Usage |
| 9 | +## Getting help |
10 | 10 |
|
11 | | -The `sdplib` directory contains four semidefinite programming problems from the [SDPLIB library](https://github.com/vsdp/SDPLIB). The function `construct_model`, defined below, reads one of the problems and constructs a [JuMP.jl](https://github.com/jump-dev/JuMP.jl) model. |
| 11 | +If you need help, please ask a question on the [JuMP community forum](https://jump.dev/forum). |
12 | 12 |
|
13 | | -```julia-repl |
14 | | -julia> using FileIO, LinearAlgebra, JuMP |
| 13 | +If you have a reproducible example of a bug, please [open a GitHub issue](https://github.com/samuelsonric/MathOptChordalDecomposition.jl/issues/new). |
15 | 14 |
|
16 | | -julia> import MosekTools, Mosek |
| 15 | +## License |
17 | 16 |
|
18 | | -julia> import MathOptChordalDecomposition as MOCD |
| 17 | +`MathOptChordalDecomposition.jl` is licensed under the |
| 18 | +[MIT License](https://github.com/samuelsonric/MathOptChordalDecomposition.jl/blob/master/LICENSE). |
19 | 19 |
|
20 | | -julia> function construct_model(f, name::String) |
21 | | - # load data |
22 | | - data = load("./sdplib/$name.jld2"); |
23 | | - F = data["F"] |
24 | | - c = data["c"] |
25 | | - m = data["m"] |
26 | | - n = data["n"] |
27 | | - |
28 | | - # construct model |
29 | | - model = JuMP.Model(f) |
30 | | - set_silent(model) |
31 | | - @variable(model, x[1:m]) |
32 | | - @objective(model, Min, c' * x) |
33 | | - @constraint(model, con, Symmetric(-Matrix(F[1]) + sum(Matrix(F[k + 1]) .* x[k] for k in 1:m)) in JuMP.PSDCone()) |
34 | | - return model, con |
35 | | - end |
36 | | -construct_model (generic function with 1 method) |
37 | | -``` |
| 20 | +## Installation |
38 | 21 |
|
39 | | -Solve the problem using the [Mosek.jl](https://github.com/MOSEK/Mosek.jl) optimizer. |
| 22 | +Install MathOptChordalDecomposition as follows: |
| 23 | +```julia |
| 24 | +import Pkg |
| 25 | +Pkg.add("MathOptChordalDecomposition") |
| 26 | +``` |
40 | 27 |
|
41 | | -```julia-repl |
42 | | -julia> model, con = construct_model(Mosek.Optimizer, "mcp124-1"); |
| 28 | +## Use with JuMP |
43 | 29 |
|
44 | | -julia> @time JuMP.optimize!(model) |
45 | | - 6.005076 seconds (2.53 k allocations: 515.859 KiB) |
| 30 | +To use MathOptChordalDecomposition with JuMP, use `MathOptChordalDecomposition.Optimizer`: |
46 | 31 |
|
47 | | -julia> objective_value(model) |
48 | | -141.9904770422396 |
| 32 | +```julia |
| 33 | +using JuMP, MathOptChordalDecomposition, SCS |
| 34 | +model = Model(() -> MathOptChordalDecomposition.Optimizer(SCS.Optimizer)) |
49 | 35 | ``` |
| 36 | +Change `SCS` for any other conic solver that supports semidefinite constraints. |
| 37 | + |
| 38 | +## Basic Usage |
50 | 39 |
|
51 | | -Solve the problem using [Mosek.jl](https://github.com/MOSEK/Mosek.jl) and MathOptChordalDecomposition.jl. |
| 40 | +The `sdplib` directory contains four semidefinite programming problems from the |
| 41 | +[SDPLIB library](https://github.com/vsdp/SDPLIB). |
52 | 42 |
|
53 | | -```julia-repl |
54 | | -julia> model, con = construct_model(() -> MOCD.Optimizer(Mosek.Optimizer), "mcp124-1"); |
| 43 | +The function `construct_model`, defined below, reads one of the problems and |
| 44 | +constructs a [JuMP.jl](https://github.com/jump-dev/JuMP.jl) model. |
| 45 | + |
| 46 | +For this example, it is significantly faster to solve the problem with |
| 47 | +MathOptChordalDecomposition than to use SCS by itself: |
| 48 | + |
| 49 | +```julia |
| 50 | +julia> using FileIO, JLD2, JuMP, LinearAlgebra, SCS |
| 51 | + |
| 52 | +julia> import MathOptChordalDecomposition as MOCD |
| 53 | + |
| 54 | +julia> function main(optimizer, name::String) |
| 55 | + data = FileIO.load("./sdplib/$name.jld2"); |
| 56 | + F, c, m, n = data["F"], data["c"], data["m"], data["n"] |
| 57 | + model = Model(optimizer) |
| 58 | + set_silent(model) |
| 59 | + @variable(model, x[1:m]) |
| 60 | + @objective(model, Min, c' * x) |
| 61 | + @constraint( |
| 62 | + model, |
| 63 | + con, |
| 64 | + LinearAlgebra.Symmetric(-F[1] + x' * F[2:end]) in PSDCone(), |
| 65 | + ) |
| 66 | + optimize!(model) |
| 67 | + return objective_value(model) |
| 68 | + end |
| 69 | +main (generic function with 1 method) |
55 | 70 |
|
56 | | -julia> @time JuMP.optimize!(model) |
57 | | - 0.041175 seconds (230.72 k allocations: 11.800 MiB) |
| 71 | +julia> @time main(SCS.Optimizer, "mcp124-1") |
| 72 | + 9.447474 seconds (154.70 k allocations: 12.313 MiB) |
| 73 | +141.96561765120785 |
58 | 74 |
|
59 | | -julia> objective_value(model) |
60 | | -141.99047611570586 |
| 75 | +julia> @time main(() -> MOCD.Optimizer(SCS.Optimizer), "mcp124-1") |
| 76 | + 0.245992 seconds (170.72 k allocations: 15.103 MiB, 1.85% compilation time) |
| 77 | +141.9887372030578 |
61 | 78 | ``` |
0 commit comments