Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get constraints in matrix format from gurobipy

I coded my model in gurobipy and I want to get the matrix of constraints and vector of cost. Is there any way to access those?

like image 644
Mostafa Ghafoori Avatar asked Jul 28 '16 21:07

Mostafa Ghafoori


1 Answers

Cannot comment on the answer of @david-nehme due to insufficient reputation, feel free to add this to his answer and delete mine.

Since Gurobi 9.0 you can query the coefficient matrix via .getA() as a <class 'scipy.sparse.csr.csr_matrix'>.

import matplotlib.pyplot as plt
import gurobipy as grb

m = grb.read("miplib/instances/miplib2010/aflow40b.mps.gz")
A = m.getA()
plt.spy(A) # different options, e.g. markersize=0.5
plt.show()

Also check out matrix plots using betterspy.

like image 123
ktnr Avatar answered Sep 20 '22 04:09

ktnr