Getting constraint matrix from gurobi

There is a “private” function _standard_form_matrix (i.e. shouldn’t be depended on not to change) within JuMP that may get you where you need to go:

using JuMP
model = Model();
@variable(model, x[1:2], lower_bound=0)
@objective(model, Min, -x[1] - x[2])
cons = @constraints(model, begin
                -5x[1] + 11x[2] <= 22
                 4x[1] -  6x[2] <= 8
end)
print(model)

s = JuMP._standard_form_matrix(model)
keys(s)
# = (:columns, :lower, :upper, :A, :bounds, :constraints)
# Here is the docstring:
r"""
    _standard_form_matrix(model::Model)

Given a problem:

    r_l <= Ax <= r_u
    c_l <=  x <= c_u

Return the standard form:

           [A -I] [x, y] = 0
    [c_l, r_l] <= [x, y] <= [c_u, r_u]

`columns` maps the variable references to column indices.
"""
A = s.A
s.lower
s.upper
#  If n is the number of variables in the original problem
# and m is the number of affine constraints in the problem. Then
m, p = size(s.A)
# where p == n + m.
n = p - m
# Hence, we can recover the "original" constraint matrix as
cA = A[:,1:n]
# and the "identity" portion as
cI = A[:,(n+1):end]
1 Like