From 968365de026bcd5386cca3b2d5d6d6599cedcd20 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 17 Nov 2023 09:49:31 +1300 Subject: [PATCH] Update models.md --- docs/src/manual/models.md | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/docs/src/manual/models.md b/docs/src/manual/models.md index e6e36441de4..adc6112c4c1 100644 --- a/docs/src/manual/models.md +++ b/docs/src/manual/models.md @@ -439,6 +439,72 @@ optimize!(model) reduced_cost(x) # Works ``` +## Get the matrix representation + +Use [`lp_matrix_data`](@ref) to return a data structure that represents the +matrix form of a linear program. + +```jldoctest +julia> begin + model = Model() + @variable(model, x >= 1) + @variable(model, 2 <= y) + @variable(model, 3 <= z <= 4) + @constraint(model, x == 5) + @constraint(model, 2x + 3y <= 6) + @constraint(model, -4y >= 5z + 7) + @constraint(model, -1 <= x + y <= 2) + @objective(model, Max, 1 + 2x) + end; + +julia> data = lp_matrix_data(model); + +julia> data.A +4×3 SparseArrays.SparseMatrixCSC{Float64, Int64} with 7 stored entries: + 1.0 ⋅ ⋅ + ⋅ -4.0 -5.0 + 2.0 3.0 ⋅ + 1.0 1.0 ⋅ + +julia> data.b_lower +4-element Vector{Float64}: + 5.0 + 7.0 + -Inf + -1.0 + +julia> data.b_upper +4-element Vector{Float64}: + 5.0 + Inf + 6.0 + 2.0 + +julia> data.x_lower +3-element Vector{Float64}: + 1.0 + 2.0 + 3.0 + +julia> data.x_upper +3-element Vector{Float64}: + Inf + Inf + 4.0 + +julia> data.c +3-element Vector{Float64}: + 2.0 + 0.0 + 0.0 + +julia> data.c_offset +1.0 + +julia> data.sense +MAX_SENSE::OptimizationSense = 1 +``` + ## Backends !!! info