coin-or / pulp

A python Linear Programming API
http://coin-or.github.io/pulp/
Other
2.1k stars 384 forks source link

HiGHS API interface improvements including time_limit #641

Closed aphi closed 1 year ago

aphi commented 1 year ago

For the HiGHS API interface:

  1. Add the setting of a time_limit and significantly speed up solution processing Picking up from the stale branch and PR (https://github.com/coin-or/pulp/pull/614), where the implementation is correct but the tests failed. The reason why took some digging...

    The time limit test for all the solvers is actually on the end-to-end time including extraction of solution values.

    In this case the solver terminated correctly after 10 seconds, but ~163s were spent in extracting the solution on my machine (or 320s in CI). Specifically, calling the getitem method (i.e. []) in solution.col_value[var.index] is a very slow operation (presumably some type conversions via pybind11).

    For the 134k variables of the bin packing problem, this took 163s and failed the test, but could be reduced very easily to 0.004s 🎉 just by copying solution.col_value to a Python list first, for which index lookups are of course fast.

    Demo script in a gist if curious: https://gist.github.com/aphi/4b2f7cfc7ccc52465bead3c24ee9c3f4

    image
  2. Enable setting of any other paramters and clean up init signature Clean up: epgap was unused and deprecated in favour of gapRel. gapRel as its own argument was also unsued and misleading. It was passed as an args to the base class, which ignored the args.

    gapRel when supplied via the **kwargs to optionsDict functions the same. But now the user can also specify any parameter for HiGHS, just the same handling as the Gurobi API.

    I've tested this and verified it works with other parameters like threads and parallel from the HiGHS options

    1. Some minor tidyups

Happy to make any changes - just let me know.

P.S. I contributed to this project back before it was on GitHub (2007~2011) under the guidance of stumitchell. So great to see its immense popularity today!

pchtsp commented 1 year ago

thanks! I will close the other PR then

stumitchell commented 1 year ago

@aphi hi long time no see :-)

there seems to be a failing test in highs_api.py in the current master branch are you able to look into it, could be a background dependency issue, as the error showed up in an unrelated commit.

https://github.com/coin-or/pulp/actions/runs/5561352717/job/15064721500

Thanks