coin-or / Clp

COIN-OR Linear Programming Solver
Other
392 stars 82 forks source link

Is there a way to gracefully terminate a long running `ClpSimplex::primal` or `ClpSimplex::dual`? #256

Closed sebrockm closed 1 year ago

sebrockm commented 1 year ago

In my C++ project I'm solving linear programs using ClpSimplex::primal and ClpSimplex::dual. Unfortunately, for some instances this takes very long and I cannot find a way to terminate them. I would imagine something like a timeout parameter or stop token. Have I missed anything in the docs?

My current workaround is to spawn them on a different thread and simply detach from that if the solution is not available after some time. This at least allows my program flow to continue, but still one CPU core is busy and lots of memory is being consumed for an uncertain amount of time.

Iain-R commented 1 year ago

Hi, You might have some luck with either setMaximumSeconds() or setMaximumIterations(). Documentation on Doxygen can be found here

sebrockm commented 1 year ago

Thanks for the quick answer! Yes, that looks rather obvious. No idea how I missed that...

I will run some tests with it and, if everything works as expected, close this issue. Thanks again!

sebrockm commented 1 year ago

Yep, it works, exactly what I was looking for, thanks @Iain-R!

BTW, the reason why I didn't find it myself was that I only looked into ClpSimplex's documentation where only inherited member variables show up, but no inherited methods. Is that on purpose?

Still, my bad that I didn't look at the base class.