Solution
BaseModelSolution(model_solver)
¶
Bases: ABC
Source code in src/bilevelpy/solution/core.py
dispose()
¶
Release heavy references (Gurobi model / solver) to free memory.
This attempts to call the gurobipy Model.dispose() if available and removes references to the solver and Gurobi model so the Python garbage collector can reclaim memory. Call this after all required data has been extracted from the solution.
Source code in src/bilevelpy/solution/core.py
SolutionRegistry
¶
Map model classes to their solution classes.
When ModelSolver finishes solving, it uses
the registry to find the correct solution class for the model. Models
are registered via the :meth:register_for decorator.
get_solution_class(model_instance_or_class)
classmethod
¶
Look up the registered solution class for a model.
Walks up the MRO so that subclasses inherit their parent's solution if none is registered directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_instance_or_class
|
A model instance or class. |
required |
Returns:
| Type | Description |
|---|---|
type
|
The registered BaseModelSolution |
type
|
subclass. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no solution is registered for the model or any of its base classes. |
Source code in src/bilevelpy/solution/solution_registry.py
register_for(solution_class)
classmethod
¶
Decorator that registers a solution class for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution_class
|
type
|
The BaseModelSolution subclass to use for the decorated model. |
required |
Returns:
| Type | Description |
|---|---|
|
A decorator that adds the model→solution mapping. |