Implement iteration_cb for LearningSolver; reactivate TSP

This commit is contained in:
2020-09-23 17:46:18 -05:00
parent 5390a5b656
commit e527e75481
8 changed files with 91 additions and 60 deletions

View File

@@ -126,7 +126,7 @@ class InternalSolver(ABC):
Parameters
----------
iteration_cb: function
iteration_cb: () -> Bool
By default, InternalSolver makes a single call to the native `solve`
method and returns the result. If an iteration callback is provided
instead, InternalSolver enters a loop, where `solve` and `iteration_cb`

View File

@@ -171,8 +171,15 @@ class LearningSolver:
if relaxation_only:
return results
def iteration_cb():
should_repeat = False
for component in self.components.values():
if component.after_iteration(self, instance, model):
should_repeat = True
return should_repeat
logger.info("Solving MILP...")
results = self.internal_solver.solve(tee=tee)
results = self.internal_solver.solve(tee=tee, iteration_cb=iteration_cb)
results["LP value"] = instance.lp_value
# Read MIP solution and bounds

View File

@@ -64,4 +64,4 @@ def test_add_components():
solver.add(DynamicLazyConstraintsComponent())
solver.add(DynamicLazyConstraintsComponent())
assert len(solver.components) == 1
assert "LazyConstraintsComponent" in solver.components
assert "DynamicLazyConstraintsComponent" in solver.components