I am using gurobipy to read LP files. The command
model=gurobipy.read("name.lp", env=env)
gives me the number of rows, columns, and non-zeroes. However, I need to retrieve the number of non-zeroes. I don't believe there is a function that does this automatically (i.e. model.getnonzeros()
)
Is there a way to obtain the non-zeros? How would I write python code to be able to do this if there isn't a built in function?
Asked
Active
Viewed 55 times
0
-
Welcome to SO! May you please elaborate a bit (by editing the question), (1) what LP files are, (2) what you already tried in terms of code snippets, plus (3) web-resources you consulted so far? – B--rian Jul 25 '19 at 14:15
-
.LP files are linear program files read by gurobipy . I haven't tried anything in terms of code snippets. As far as web resources, I looked at the Gurobi reference manual and looked on stackoverflow as well. – Vik Rao Jul 25 '19 at 14:17
1 Answers
0
Ok I figured it out - perusing the Gurobi reference manual, in chapter 6, Python API overview, I see there is an attribute called "NumNZs" that can be called as:
print(model.getAttr("NumNZs"))
This will give the non-zeroes

Vik Rao
- 1
- 2