pulp
pulp copied to clipboard
Allow for the control of the number of threads when using the python API for CPLEX
Describe the new feature
When creating a solver instance of CPLEX_PY I would like to be able to control the number of threads that the model uses, because some small problems that require a lot of iterations to solve benefit from using less threads.
Additional info
Is your feature request related to an issue? Please include the issue number.
Didn't find any
Does this feature exist in another product or project? Please provide a link.
The CPLEX API allows for this, as you can see in the documentation. https://www.ibm.com/docs/en/icos/12.8.0.0?topic=parameters-global-thread-count
Implementation suggestion
When creating the class CPLEX_PY allow for an optional parameter called nthreads with a default value of 0 (also the default value of CPLEX). When calling the function buildSolverModel at the end call a function that would run the command self.solverModel.parameters.threads.set(nthreads)
do you feel like doing a PR with the change? check this part https://github.com/coin-or/pulp/blob/de4dbb7cc3a9ed2bd0e88fe9e45f7a66571bad1f/pulp/apis/cplex_api.py#L432-L463 to see how we feed the cplex library with the current configuration.
I've created a pull request with this change a few small changes that I fell would improve pulp
I've adapted the PR above to introduce only the threads
option.