Skip to content

Commit

Permalink
Update models.md
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Nov 16, 2023
1 parent 43b32d6 commit 968365d
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions docs/src/manual/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 968365d

Please sign in to comment.