Solver Configuration
Configure the solver with SolverConfig and related classes.
The solver is the engine that finds optimal solutions to your planning problems. This section covers how to configure and run it.
SolverConfig, TerminationConfig, and other settingsSolver.solve()from solverforge_legacy.solver import SolverFactory
from solverforge_legacy.solver.config import (
SolverConfig, ScoreDirectorFactoryConfig, TerminationConfig, Duration
)
# Configure the solver
solver_config = SolverConfig(
solution_class=Timetable,
entity_class_list=[Lesson],
score_director_factory_config=ScoreDirectorFactoryConfig(
constraint_provider_function=define_constraints
),
termination_config=TerminationConfig(
spent_limit=Duration(seconds=30)
)
)
# Create and run the solver
solver_factory = SolverFactory.create(solver_config)
solver = solver_factory.build_solver()
problem = load_problem() # Your problem data
solution = solver.solve(problem)
print(f"Best score: {solution.score}")
The solver needs to know when to stop. Common termination conditions:
| Condition | Description |
|---|---|
spent_limit | Stop after a time limit (e.g., 30 seconds) |
best_score_limit | Stop when a target score is reached |
unimproved_spent_limit | Stop if no improvement for a duration |
step_count_limit | Stop after a number of optimization steps |
Configure the solver with SolverConfig and related classes.
Execute the solver synchronously with Solver.solve().
Manage concurrent and asynchronous solving jobs.
Analyze and explain solutions with SolutionManager.
Compare solver configurations and tune performance.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.