mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Implement iteration_cb for LearningSolver; reactivate TSP
This commit is contained in:
@@ -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`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user