Make LearningSolver.add internal

This commit is contained in:
2021-01-19 22:32:05 -06:00
parent 4b8672870a
commit 9ddb952db0
3 changed files with 6 additions and 23 deletions

View File

@@ -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
The aggressiveness of classification components (such as `PrimalSolutionComponent` and `LazyConstraintComponent`) can

View File

@@ -104,12 +104,12 @@ class LearningSolver:
if components is not None:
for comp in components:
self.add(comp)
self._add_component(comp)
else:
self.add(ObjectiveValueComponent())
self.add(PrimalSolutionComponent())
self.add(DynamicLazyConstraintsComponent())
self.add(UserCutsComponent())
self._add_component(ObjectiveValueComponent())
self._add_component(PrimalSolutionComponent())
self._add_component(DynamicLazyConstraintsComponent())
self._add_component(UserCutsComponent())
assert self.mode in ["exact", "heuristic"]
for component in self.components.values():
@@ -332,7 +332,7 @@ class LearningSolver:
for component in self.components.values():
component.fit(training_instances)
def add(self, component):
def _add_component(self, component):
name = component.__class__.__name__
self.components[name] = component

View File

@@ -62,14 +62,6 @@ def test_parallel_solve():
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():
for internal_solver in _get_internal_solvers():
# Create instances and pickle them