mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Make LearningSolver.add internal
This commit is contained in:
@@ -61,15 +61,6 @@ solver2 = LearningSolver(components=[
|
|||||||
])
|
])
|
||||||
```
|
```
|
||||||
|
|
||||||
It is also possible to add components to an existing solver using the `solver.add` method, as shown below. If the solver already holds another component of that type, the new component will replace the previous one.
|
|
||||||
```python
|
|
||||||
# Create solver with default components
|
|
||||||
solver = LearningSolver()
|
|
||||||
|
|
||||||
# Replace the default LazyConstraintComponent by one with custom parameters
|
|
||||||
solver.add(LazyConstraintComponent(...))
|
|
||||||
```
|
|
||||||
|
|
||||||
### Adjusting component aggressiveness
|
### Adjusting component aggressiveness
|
||||||
|
|
||||||
The aggressiveness of classification components (such as `PrimalSolutionComponent` and `LazyConstraintComponent`) can
|
The aggressiveness of classification components (such as `PrimalSolutionComponent` and `LazyConstraintComponent`) can
|
||||||
|
|||||||
@@ -104,12 +104,12 @@ class LearningSolver:
|
|||||||
|
|
||||||
if components is not None:
|
if components is not None:
|
||||||
for comp in components:
|
for comp in components:
|
||||||
self.add(comp)
|
self._add_component(comp)
|
||||||
else:
|
else:
|
||||||
self.add(ObjectiveValueComponent())
|
self._add_component(ObjectiveValueComponent())
|
||||||
self.add(PrimalSolutionComponent())
|
self._add_component(PrimalSolutionComponent())
|
||||||
self.add(DynamicLazyConstraintsComponent())
|
self._add_component(DynamicLazyConstraintsComponent())
|
||||||
self.add(UserCutsComponent())
|
self._add_component(UserCutsComponent())
|
||||||
|
|
||||||
assert self.mode in ["exact", "heuristic"]
|
assert self.mode in ["exact", "heuristic"]
|
||||||
for component in self.components.values():
|
for component in self.components.values():
|
||||||
@@ -332,7 +332,7 @@ class LearningSolver:
|
|||||||
for component in self.components.values():
|
for component in self.components.values():
|
||||||
component.fit(training_instances)
|
component.fit(training_instances)
|
||||||
|
|
||||||
def add(self, component):
|
def _add_component(self, component):
|
||||||
name = component.__class__.__name__
|
name = component.__class__.__name__
|
||||||
self.components[name] = component
|
self.components[name] = component
|
||||||
|
|
||||||
|
|||||||
@@ -62,14 +62,6 @@ def test_parallel_solve():
|
|||||||
assert len(instance.solution["x"].keys()) == 4
|
assert len(instance.solution["x"].keys()) == 4
|
||||||
|
|
||||||
|
|
||||||
def test_add_components():
|
|
||||||
solver = LearningSolver(components=[])
|
|
||||||
solver.add(DynamicLazyConstraintsComponent())
|
|
||||||
solver.add(DynamicLazyConstraintsComponent())
|
|
||||||
assert len(solver.components) == 1
|
|
||||||
assert "DynamicLazyConstraintsComponent" in solver.components
|
|
||||||
|
|
||||||
|
|
||||||
def test_solve_fit_from_disk():
|
def test_solve_fit_from_disk():
|
||||||
for internal_solver in _get_internal_solvers():
|
for internal_solver in _get_internal_solvers():
|
||||||
# Create instances and pickle them
|
# Create instances and pickle them
|
||||||
|
|||||||
Reference in New Issue
Block a user