pub struct SolverScope<S: PlanningSolution> { /* private fields */ }Expand description
Top-level scope for the entire solving process.
Holds the working solution, score director, and tracks the best solution found.
Implementations§
Source§impl<S: PlanningSolution> SolverScope<S>
impl<S: PlanningSolution> SolverScope<S>
Sourcepub fn new(score_director: Box<dyn ScoreDirector<S>>) -> Self
pub fn new(score_director: Box<dyn ScoreDirector<S>>) -> Self
Creates a new solver scope with the given score director.
Sourcepub fn with_seed(score_director: Box<dyn ScoreDirector<S>>, seed: u64) -> Self
pub fn with_seed(score_director: Box<dyn ScoreDirector<S>>, seed: u64) -> Self
Creates a solver scope with a specific random seed.
Sourcepub fn with_statistics(
self,
collector: Arc<StatisticsCollector<S::Score>>,
) -> Self
pub fn with_statistics( self, collector: Arc<StatisticsCollector<S::Score>>, ) -> Self
Attaches a statistics collector to this scope.
The collector will be updated during solving to track metrics.
Sourcepub fn statistics(&self) -> Option<&Arc<StatisticsCollector<S::Score>>>
pub fn statistics(&self) -> Option<&Arc<StatisticsCollector<S::Score>>>
Returns the statistics collector, if one is attached.
Sourcepub fn record_move(&self, accepted: bool)
pub fn record_move(&self, accepted: bool)
Records a move evaluation in statistics.
Does nothing if no statistics collector is attached.
Sourcepub fn record_score_calculation(&self)
pub fn record_score_calculation(&self)
Records a score calculation in statistics.
Does nothing if no statistics collector is attached.
Sourcepub fn start_solving(&mut self)
pub fn start_solving(&mut self)
Marks the start of solving.
Sourcepub fn score_director(&self) -> &dyn ScoreDirector<S>
pub fn score_director(&self) -> &dyn ScoreDirector<S>
Returns a reference to the score director.
Sourcepub fn score_director_mut(&mut self) -> &mut dyn ScoreDirector<S>
pub fn score_director_mut(&mut self) -> &mut dyn ScoreDirector<S>
Returns a mutable reference to the score director.
Sourcepub fn working_solution(&self) -> &S
pub fn working_solution(&self) -> &S
Returns a reference to the working solution.
Sourcepub fn working_solution_mut(&mut self) -> &mut S
pub fn working_solution_mut(&mut self) -> &mut S
Returns a mutable reference to the working solution.
Sourcepub fn calculate_score(&mut self) -> S::Score
pub fn calculate_score(&mut self) -> S::Score
Calculates and returns the current score.
Sourcepub fn best_solution(&self) -> Option<&S>
pub fn best_solution(&self) -> Option<&S>
Returns the best solution found so far.
Sourcepub fn best_score(&self) -> Option<&S::Score>
pub fn best_score(&self) -> Option<&S::Score>
Returns the best score found so far.
Sourcepub fn update_best_solution(&mut self)
pub fn update_best_solution(&mut self)
Updates the best solution if the current solution is better.
Sourcepub fn set_best_solution(&mut self, solution: S, score: S::Score)
pub fn set_best_solution(&mut self, solution: S, score: S::Score)
Forces an update of the best solution regardless of score comparison.
Sourcepub fn increment_step_count(&mut self) -> u64
pub fn increment_step_count(&mut self) -> u64
Increments and returns the total step count.
Sourcepub fn total_step_count(&self) -> u64
pub fn total_step_count(&self) -> u64
Returns the total step count.
Sourcepub fn take_best_solution(self) -> Option<S>
pub fn take_best_solution(self) -> Option<S>
Extracts the best solution, consuming this scope.
Sourcepub fn take_best_or_working_solution(self) -> S
pub fn take_best_or_working_solution(self) -> S
Returns the best solution or the current working solution if no best was set.
This is useful after construction heuristic where the working solution may be the only valid solution even if it wasn’t marked as “best”.
Sourcepub fn set_terminate_early_flag(&mut self, flag: Arc<AtomicBool>)
pub fn set_terminate_early_flag(&mut self, flag: Arc<AtomicBool>)
Sets the terminate-early flag shared with the Solver.
This allows phases to check if early termination was requested.
Sourcepub fn is_terminate_early(&self) -> bool
pub fn is_terminate_early(&self) -> bool
Checks if early termination was requested.
Returns true if the terminate-early flag is set, otherwise false.