Performance issue with Python AddConstr()?

825 views
Skip to first unread message

KaiC

unread,
Dec 9, 2013, 4:33:55 PM12/9/13
to gur...@googlegroups.com
We are using Gurobi for a "large" LP problem, ~100K variables and 100K constraints. and I am surprised to see that Model.addConstr() takes way too much time..Can anyone give me some hints how to improve?

We are basically just adding linear inequality constraints of the form Ax<=b, where A is ~100K \times 100K, non-sparse...

to add these constraints, we are looping through all rows in A, something like:


for i in xrange(N):

   var = [A[i,k] for k in xrange(p)]

   m.addConstr(quicksum(var[k]*w[k] for k in xrange(p))<=b[i])



I assume it shouldnt take hours to finish adding the linear constraints, right? Anyone with some suggestions?

Thanks!
Kai

Greg Glockner

unread,
Dec 9, 2013, 4:37:29 PM12/9/13
to gur...@googlegroups.com
> We are basically just adding linear inequality constraints of the form Ax<=b, where A is ~100K \times 100K, non-sparse...

If A really isn't sparse, it is going to take significant time to add a coefficient matrix with 1e10 nonzeros.

Stuart Mitchell

unread,
Dec 9, 2013, 4:44:59 PM12/9/13
to gur...@googlegroups.com

I have found using LinExpr to be faster.



for i in xrange(N):

   var = [A[i,k] for k in xrange(p)]

   m.addConstr(LinExpr([(w[k], var[k]) for k in xrange(p)])<=b[i])



Stu


On Tue, Dec 10, 2013 at 10:37 AM, Greg Glockner <gloc...@gurobi.com> wrote:
> We are basically just adding linear inequality constraints of the form Ax<=b, where A is ~100K \times 100K, non-sparse...

If A really isn't sparse, it is going to take significant time to add a coefficient matrix with 1e10 nonzeros.

--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

KaiC

unread,
Dec 11, 2013, 3:00:21 PM12/11/13
to gur...@googlegroups.com
Thanks Greg and Stuart!

Then another immediate question is that: can I use parallel for loop to add the constraints?   I am trying now, but it would be good to know if Gurobi takes it and someone has tried it.

Thanks

Ed Rothberg

unread,
Dec 12, 2013, 6:04:43 PM12/12/13
to gur...@googlegroups.com
...can I use parallel for loop to add the constraints?

You can't have multiple threads making concurrent calls to Gurobi routines on the same model.

You should really experiment with a smaller version of your model.  It is rare for model generation to take more than a small fraction of the time required to solve the model.  To put it another way, if model generation is taking a very long time, you are most likely not going to be able to solve the model in any reasonable amount of time.

Ed


Reply all
Reply to author
Forward
0 new messages