Skip to content

Commit

Permalink
SLOTY: add config.objective_lower_bound option
Browse files Browse the repository at this point in the history
  • Loading branch information
mkannwischer committed Oct 16, 2024
1 parent 89328ab commit e29061e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions slothy/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ def objective_precision(self):
solution is within 5% of the current estimate for the optimal solution."""
return self._objective_precision

@property
def objective_lower_bound(self):
"""A lower bound for the objective at which to stop the search."""
return self._objective_lower_bound

@property
def has_objective(self):
"""Indicates whether a different objective than minimization of stalls
Expand Down Expand Up @@ -1143,6 +1148,7 @@ def __init__(self, Arch, Target):
self._retry_timeout = None
self._ignore_objective = False
self._objective_precision = 0
self._objective_lower_bound = None

# Visualization
self.indentation = 8
Expand Down Expand Up @@ -1280,6 +1286,9 @@ def ignore_objective(self, val):
@objective_precision.setter
def objective_precision(self, val):
self._objective_precision = val
@objective_lower_bound.setter
def objective_lower_bound(self, val):
self._objective_lower_bound = val
@absorb_spills.setter
def absorb_spills(self, val):
self._absorb_spills = val
Expand Down
8 changes: 8 additions & 0 deletions slothy/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3392,12 +3392,20 @@ def is_good_enough( cur, bound ):
if cur - bound <= self.config.constraints.stalls_precision:
self.logger.info("Closer than %d stalls to theoretical optimum... stop", prec)
return True
if self.config.objective_lower_bound is not None and \
cur <= self.config.objective_lower_bound:
self.logger.info("Reached user-defined objective_lower_bound ... stop", prec)
return True
elif self._model.objective_name != "no objective":
prec = self.config.objective_precision
if bound > 0 and abs(1 - (cur / bound)) < prec:
self.logger.info("Closer than %d%% to theoretical optimum... stop",
int(prec*100))
return True
if self.config.objective_lower_bound is not None and \
cur <= self.config.objective_lower_bound:
self.logger.info("Reached user-defined objective_lower_bound ... stop", prec)
return True
return False

solution_cb = SlothyBase.CpSatSolutionCb(self.logger,self._model.objective_name,
Expand Down

0 comments on commit e29061e

Please sign in to comment.