mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Component: rename iteration_cb and lazy_cb
This commit is contained in:
@@ -22,8 +22,8 @@ class Component(ABC):
|
||||
def fit(self, training_instances):
|
||||
pass
|
||||
|
||||
def after_iteration(self, solver, instance, model):
|
||||
def iteration_cb(self, solver, instance, model):
|
||||
return False
|
||||
|
||||
def on_lazy_callback(self, solver, instance, model):
|
||||
def lazy_cb(self, solver, instance, model):
|
||||
return
|
||||
|
||||
@@ -38,7 +38,7 @@ class DynamicLazyConstraintsComponent(Component):
|
||||
cut = instance.build_lazy_constraint(model, v)
|
||||
solver.internal_solver.add_constraint(cut)
|
||||
|
||||
def after_iteration(self, solver, instance, model):
|
||||
def iteration_cb(self, solver, instance, model):
|
||||
logger.debug("Finding violated (dynamic) lazy constraints...")
|
||||
violations = instance.find_violated_lazy_constraints(model)
|
||||
if len(violations) == 0:
|
||||
|
||||
@@ -51,7 +51,7 @@ class StaticLazyConstraintsComponent(Component):
|
||||
def after_solve(self, solver, instance, model, results):
|
||||
pass
|
||||
|
||||
def after_iteration(self, solver, instance, model):
|
||||
def iteration_cb(self, solver, instance, model):
|
||||
if solver.use_lazy_cb:
|
||||
return False
|
||||
else:
|
||||
@@ -67,7 +67,7 @@ class StaticLazyConstraintsComponent(Component):
|
||||
else:
|
||||
return False
|
||||
|
||||
def on_lazy_callback(self, solver, instance, model):
|
||||
def lazy_cb(self, solver, instance, model):
|
||||
self._check_and_add(instance, solver)
|
||||
|
||||
def _check_and_add(self, instance, solver):
|
||||
|
||||
@@ -101,7 +101,7 @@ def test_usage_with_solver():
|
||||
internal.add_constraint.reset_mock()
|
||||
|
||||
# LearningSolver calls after_iteration (first time)
|
||||
should_repeat = component.after_iteration(solver, instance, None)
|
||||
should_repeat = component.iteration_cb(solver, instance, None)
|
||||
assert should_repeat
|
||||
|
||||
# Should ask internal solver to verify if constraints in the pool are
|
||||
@@ -112,7 +112,7 @@ def test_usage_with_solver():
|
||||
internal.add_constraint.reset_mock()
|
||||
|
||||
# LearningSolver calls after_iteration (second time)
|
||||
should_repeat = component.after_iteration(solver, instance, None)
|
||||
should_repeat = component.iteration_cb(solver, instance, None)
|
||||
assert not should_repeat
|
||||
|
||||
# The lazy constraint pool should be empty by now, so no calls should be made
|
||||
|
||||
Reference in New Issue
Block a user