pub struct SolverManager<S: PlanningSolution, ProblemId: Eq + Hash + Clone> { /* private fields */ }Expand description
Manages multiple concurrent solves for planning problems.
Each solve is identified by a unique ProblemId that allows tracking
and managing individual solves independently.
§Example
let service = Arc::new(HttpSolverService::new("http://localhost:8080"));
let mut manager = SolverManager::<Timetable, String>::new(service)
.with_termination(TerminationConfig::new().with_spent_limit("PT5M"));
manager.solve("problem-1".to_string(), problem1)?;
manager.solve("problem-2".to_string(), problem2)?;
// Check solutions later
if let Some(solution) = manager.get_best_solution(&"problem-1".to_string())? {
println!("Best score: {:?}", solution.score());
}
manager.terminate_all();Implementations§
Source§impl<S, I> SolverManager<S, I>
impl<S, I> SolverManager<S, I>
Sourcepub fn new(service: Arc<dyn SolverService>) -> Self
pub fn new(service: Arc<dyn SolverService>) -> Self
Creates a new SolverManager with the given solver service.
Sourcepub fn with_config(self, config: SolverConfig) -> Self
pub fn with_config(self, config: SolverConfig) -> Self
Sets the solver configuration.
Sourcepub fn with_termination(self, termination: TerminationConfig) -> Self
pub fn with_termination(self, termination: TerminationConfig) -> Self
Sets the termination configuration.
Sourcepub fn with_cascading_expression(
self,
class_name: impl Into<String>,
field_name: impl Into<String>,
expression: Expression,
) -> Self
pub fn with_cascading_expression( self, class_name: impl Into<String>, field_name: impl Into<String>, expression: Expression, ) -> Self
Registers a cascading update expression for a shadow variable.
This expression will be compiled to WASM and called by the solver when the shadow variable needs to be recomputed.
§Arguments
class_name- The entity class name (e.g., “Visit”)field_name- The field with the cascading update shadow variableexpression- The expression to compute the shadow value
Sourcepub fn solve(&mut self, id: I, problem: S) -> SolverForgeResult<()>
pub fn solve(&mut self, id: I, problem: S) -> SolverForgeResult<()>
Starts solving a problem with the given ID.
Returns an error if a solve with this ID is already in progress.
Sourcepub fn get_best_solution(&self, id: &I) -> SolverForgeResult<Option<S>>
pub fn get_best_solution(&self, id: &I) -> SolverForgeResult<Option<S>>
Gets the best solution for a problem, if available.
Sourcepub fn terminate(&mut self, id: &I) -> SolverForgeResult<()>
pub fn terminate(&mut self, id: &I) -> SolverForgeResult<()>
Terminates a solve early.
Sourcepub fn terminate_all(&mut self)
pub fn terminate_all(&mut self)
Terminates all active solves.
Sourcepub fn is_solving(&self, id: &I) -> bool
pub fn is_solving(&self, id: &I) -> bool
Checks if a solve is currently in progress for the given ID.
Sourcepub fn active_solve_count(&self) -> usize
pub fn active_solve_count(&self) -> usize
Gets the number of active solves.
Sourcepub fn cleanup_completed(&mut self) -> SolverForgeResult<()>
pub fn cleanup_completed(&mut self) -> SolverForgeResult<()>
Removes completed solves from tracking.