title: sparse matrix LP problems in Gurobi / python
body: <p>I am trying to solve an LP problem represented using sparse matrices in Gurobi / python. </p>
  
  <blockquote>
    <p>max c&prime; x, subject to A x = b, L &leq; x &leq; U</p>
  </blockquote>
  
  <p>where A is a SciPy <a href="http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.sparse.lil_matrix.html" rel="nofollow">linked list sparse matrix</a> of size ~1000<sup>2</sup>. Using the code</p>
  
  <pre><code>model = gurobipy.Model()
  rows, cols = len(b), len(c)
  for j in range(cols):
      model.addVar(lb=L[j], ub=U[j], obj=c[j])
  model.update()
  vars = model.getVars()
  S = scipy.sparse.coo_matrix(A)
  expr, used = [], []
  for i in range(rows):
      expr.append(gurobipy.LinExpr())
      used.append(False)
  for i, j, s in zip(S.row, S.col, S.data):
      expr[i] += s*vars[j]
      used[i] = True
  for i in range(rows):
      if used[i]:
          model.addConstr(lhs=expr[i], sense=gurobipy.GRB.EQUAL, rhs=b[i])
  model.update()
  model.ModelSense = -1
  model.optimize()
  </code></pre>
  
  <p>the problem is built and solved in ~1s, which is ~10-100 times slower than the same task in Gurobi / Matlab. Do you have any suggestions for improving the efficiency of the problem definition, or suggestions for avoiding translation to <a href="http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.sparse.coo_matrix.html" rel="nofollow">sparse coordinate</a> format?</p>