coin-or / pulp

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

timeLimit ignored when using highspy #608

Closed apschmidt closed 8 months ago

apschmidt commented 1 year ago

Details for the issue

What did you do?

Attempted to use HiGHS solver (as detailed below) to solve a MIP.

solver = getSolver('HiGHS', timeLimit=10, msg = True) prob.solve(solver)

What did you expect to see?

I expected to see the output below. Note the status is "Time Limit Reached" in the Status Report.

image

What did you see instead?

The pulp api (highs_api.py) does not pass the timeLimit parameter to the HiGHS solver. As a result, the timeLimit is ignored and the branch-and-bound is run until the optimal solution is found. See below for output.

image

Useful extra information

I have found a quick-fix, but I am unsure of a sustainable solution.

Specifically, I have modified the HiGHS class in the highs_api.py file. The changes were as follows:

  1. In the init method, changed from super().__init__(mip, msg, timeLimit, gapRel=gapRel, *args, **solverParams) to super().__init__(mip, msg, timeLimit = timeLimit, gapRel=gapRel, *args, **solverParams). Note this is because the third argument in the super.init() is "options" not "timeLimit".
  2. In the buildSolverModel() method, I added the following code if self.timeLimit is not None: lp.solverModel.setOptionValue("time_limit", float(self.timeLimit)) directly following lp.solverModel.setOptionValue("mip_rel_gap", gapRel):

The info below often helps, please fill it out if you're able to. :)

What operating system are you using?

I'm using python version:

I installed PuLP via:

Did you also

pchtsp commented 1 year ago

thanks! Would you mind doing a PR with these changes? And if you're feeling more generous, you can add highspy to the solvers that are tested with timeLimit here: https://github.com/coin-or/pulp/blob/006753076be18ee857339d333a5db11e599f21a2/pulp/tests/test_pulp.py#L1210-L1217

apschmidt commented 1 year ago

I can try! I am new to GitHub, so I may take a bit to figure it out. Currently, I am unable to make a new branch however.

pchtsp commented 1 year ago

Great! Check https://coin-or.github.io/pulp/develop/contribute.html for some basic information. Have fun : )

pchtsp commented 8 months ago

I'm closing since the functionality now offers this possibility in the HiGHS solver. Please re-open if needed.