Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HiGHS API interface improvements including time_limit #641

Merged
merged 6 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pulp/apis/highs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,11 @@ def __init__(
mip=True,
msg=True,
timeLimit=None,
epgap=None,
gapRel=None,
warmStart=False,
logPath=None,
*args,
**solverParams,
):
super().__init__(mip, msg, timeLimit, gapRel=gapRel, *args, **solverParams)
super().__init__(mip, msg, timeLimit=timeLimit, **solverParams)

def available(self):
return True
Expand All @@ -275,6 +272,13 @@ def buildSolverModel(self, lp):
gapRel = self.optionsDict.get("gapRel", 0)
lp.solverModel.setOptionValue("mip_rel_gap", gapRel)

if self.timeLimit is not None:
lp.solverModel.setOptionValue("time_limit", float(self.timeLimit))

# set remaining parameter values
for key, value in self.optionsDict.items():
lp.solverModel.setOptionValue(key, value)

inf = highspy.kHighsInf

obj_mult = -1 if lp.sense == constants.LpMaximize else 1
Expand Down Expand Up @@ -342,8 +346,9 @@ def findSolutionValues(self, lp):
HighsModelStatus.kUnknown: constants.LpStatusNotSolved,
}

col_values = list(solution.col_value)
for var in lp.variables():
var.varValue = solution.col_value[var.index]
var.varValue = col_values[var.index]

return status_dict[status]

Expand All @@ -355,6 +360,7 @@ def actualSolve(self, lp):

for var in lp.variables():
var.modified = False

for constraint in lp.constraints.values():
constraint.modifier = False

Expand Down
4 changes: 2 additions & 2 deletions pulp/tests/bin_packing_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from itertools import product


def _bin_packin_instance(bins, seed=0):
def _bin_packing_instance(bins, seed=0):
packed_bins = [[] for _ in range(bins)]
bin_size = bins * 100
random.seed(seed)
Expand All @@ -22,7 +22,7 @@ def _bin_packin_instance(bins, seed=0):


def create_bin_packing_problem(bins, seed=0):
items, packing, bin_size = _bin_packin_instance(bins=bins, seed=seed)
items, packing, bin_size = _bin_packing_instance(bins=bins, seed=seed)

prob = LpProblem("bin_packing", LpMinimize)

Expand Down
9 changes: 6 additions & 3 deletions pulp/tests/test_pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,12 @@ def test_measuring_solving_time(self):

time_limit = 10
solver_settings = dict(
PULP_CBC_CMD=30, COIN_CMD=30, SCIP_CMD=30, GUROBI_CMD=50, CPLEX_CMD=50
PULP_CBC_CMD=30,
COIN_CMD=30,
SCIP_CMD=30,
GUROBI_CMD=50,
CPLEX_CMD=50,
HiGHS=50,
)
bins = solver_settings.get(self.solver.name)
if bins is None:
Expand All @@ -1224,9 +1229,7 @@ def test_measuring_solving_time(self):
delta = 20
reported_time = prob.solutionTime
if self.solver.name in ["PULP_CBC_CMD", "COIN_CMD"]:
# CBC is less exact with the timeLimit
reported_time = prob.solutionCpuTime
delta = 5

self.assertAlmostEqual(
reported_time,
Expand Down