pub struct SolverScope<'t, S: PlanningSolution, D: ScoreDirector<S>> {
pub inphase_step_count_limit: Option<u64>,
pub inphase_move_count_limit: Option<u64>,
pub inphase_score_calc_count_limit: Option<u64>,
/* private fields */
}Expand description
Top-level scope for the entire solving process.
Holds the working solution, score director, and tracks the best solution found.
§Type Parameters
't- Lifetime of the termination flag referenceS- The planning solution typeD- The score director type
Fields§
§inphase_step_count_limit: Option<u64>Optional maximum total step count for in-phase termination (T1).
inphase_move_count_limit: Option<u64>Optional maximum total move count for in-phase termination (T1).
inphase_score_calc_count_limit: Option<u64>Optional maximum total score calculation count for in-phase termination (T1).
Implementations§
Source§impl<'t, S: PlanningSolution, D: ScoreDirector<S>> SolverScope<'t, S, D>
impl<'t, S: PlanningSolution, D: ScoreDirector<S>> SolverScope<'t, S, D>
Sourcepub fn new(score_director: D) -> Self
pub fn new(score_director: D) -> Self
Creates a new solver scope with the given score director.
Sourcepub fn with_terminate(
score_director: D,
terminate: Option<&'t AtomicBool>,
) -> Self
pub fn with_terminate( score_director: D, terminate: Option<&'t AtomicBool>, ) -> Self
Creates a solver scope with a termination flag.
Sourcepub fn with_seed(score_director: D, seed: u64) -> Self
pub fn with_seed(score_director: D, seed: u64) -> Self
Creates a solver scope with a specific random seed.
Sourcepub fn with_best_solution_callback(
self,
callback: Box<dyn Fn(&S) + Send + Sync + 't>,
) -> Self
pub fn with_best_solution_callback( self, callback: Box<dyn Fn(&S) + Send + Sync + 't>, ) -> Self
Sets the best solution callback.
The callback is invoked whenever the best solution improves during solving.
Sourcepub fn start_solving(&mut self)
pub fn start_solving(&mut self)
Marks the start of solving.
Sourcepub fn score_director(&self) -> &D
pub fn score_director(&self) -> &D
Returns a reference to the score director.
Sourcepub fn score_director_mut(&mut self) -> &mut D
pub fn score_director_mut(&mut self) -> &mut D
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.
Also records the score calculation in solver statistics.
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.
Sourcepub fn take_solution_and_stats(self) -> (S, SolverStats)
pub fn take_solution_and_stats(self) -> (S, SolverStats)
Extracts both the solution and stats, consuming this scope.
Returns the best solution (or working solution if none) along with the accumulated solver statistics.
Sourcepub fn is_terminate_early(&self) -> bool
pub fn is_terminate_early(&self) -> bool
Checks if early termination was requested (external flag only).
Sourcepub fn set_time_limit(&mut self, limit: Duration)
pub fn set_time_limit(&mut self, limit: Duration)
Sets the time limit for solving.
Sourcepub fn set_termination_fn(
&mut self,
f: Box<dyn Fn(&SolverScope<'t, S, D>) -> bool + Send + Sync + 't>,
)
pub fn set_termination_fn( &mut self, f: Box<dyn Fn(&SolverScope<'t, S, D>) -> bool + Send + Sync + 't>, )
Registers a termination check function that is called inside phase step loops.
This allows Termination trait implementations (e.g., step count, move count,
score targets) to fire during a running phase, not only between phases.
The solver sets this before calling phase.solve().
Sourcepub fn clear_termination_fn(&mut self)
pub fn clear_termination_fn(&mut self)
Clears the registered termination function.
Sourcepub fn should_terminate_construction(&self) -> bool
pub fn should_terminate_construction(&self) -> bool
Checks if construction heuristic should terminate.
Construction phases must always complete — they build the initial solution. Step/move/score-calculation count limits are for local search phases only, so this method intentionally excludes those checks.
Sourcepub fn should_terminate(&self) -> bool
pub fn should_terminate(&self) -> bool
Checks if solving should terminate (external flag, time limit, OR any registered limits).
Sourcepub fn stats(&self) -> &SolverStats
pub fn stats(&self) -> &SolverStats
Returns a reference to the solver statistics.
Sourcepub fn stats_mut(&mut self) -> &mut SolverStats
pub fn stats_mut(&mut self) -> &mut SolverStats
Returns a mutable reference to the solver statistics.
Auto Trait Implementations§
impl<'t, S, D> Freeze for SolverScope<'t, S, D>
impl<'t, S, D> !RefUnwindSafe for SolverScope<'t, S, D>
impl<'t, S, D> Send for SolverScope<'t, S, D>
impl<'t, S, D> Sync for SolverScope<'t, S, D>where
D: Sync,
impl<'t, S, D> Unpin for SolverScope<'t, S, D>
impl<'t, S, D> UnsafeUnpin for SolverScope<'t, S, D>
impl<'t, S, D> !UnwindSafe for SolverScope<'t, S, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more