P = MixedIntegerLinearProgram(solver="Coin", maximization=False)x = P.new_variable(real=True)z = 0t1 = cputime()while True: P.add_constraint(x[0] + random()*x[1], max = random()) z += 1 if z%10000 == 0: t2 = cputime() print z, t2-t1 t1 = t2
10000 0.86005420000 1.52809530000 2.2321440000 3.78823650000 4.58028660000 7.48846870000 15.99780000 23.29745690000 31.489968100000 37.614351110000 43.946747120000 47.818988
Sorry for my late answer, I am away from everything at the moment, and I am reduced to answer your message with a mobile phone :-)
I believe that this thing is slow because we did not inform the LP data structure (which we do not encode ourselves in Sage) or the problem's size. And I guess it does not like to never know how many constraints there will be, and I fear that it does a lot of useless copies when you add a constraint (perhaps it copies the whole matrix just to add one line ?).
In the solvers API you have a command to add many constraints at the same time (all set to zero) that you can fill later. This you do not add new rows, just fill some numbers. I guess this would probably solve your problem : you just need to add a function to allocate many useless rows at first (when you build the LP) instead of adding them one by one.
Nathann
And I guess it does not like to never know how many constraints there will be, and I fear that it does a lot of useless copies when you add a constraint (perhaps it copies the whole matrix just to add one line ?).
I think this is right. Allocating & copying such a huge matrix repeatedly would be terrible. Perhaps we should introduce an API function to "add_constraints", which takes a list of lists, or a matrix? If a solver doesn't support such a thing, we could fall back on the brute force method.
--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To post to this group, send email to sage-s...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.