pub struct ThresholdAcceptingSolver<S> { /* private fields */ }Expand description
The threshold accepting solver uses a Neighborhood, an Objective, an
initial_threshold (ObjectiveValue) and a threshold_factor
(f32 between 0 and 1, e.g., 0.9) to find a good solution,
while occasionally accepting worse solutions with the hope to not get trapped within a bad local minimum.
- Whenever a worse neighbor is accepted, the
current_thresholdis reduced by thethreshold_factor. - The
function_between_stepsis executed after each improvement step. - The default
function_between_steps(ifNone) is printing the iteration number, the objective value (in comparison the the previous objective value) and the time elapsed since the start. - The solver stops after a certain number of iterations or after a certain time limit.
- If
max_iterationsandmax_timeisNone, the solver runs until a whole neighborhood is explored without any accpetance.
For a high-level overview, see the module documentation and for an example, see the threshold accepting solver for the TSP.
Implementations§
Source§impl<S> ThresholdAcceptingSolver<S>
impl<S> ThresholdAcceptingSolver<S>
Sourcepub fn initialize(
neighborhood: Arc<dyn Neighborhood<S>>,
objective: Arc<Objective<S>>,
initial_threshold: ObjectiveValue,
threshold_factor: ScalingFactor,
) -> Self
pub fn initialize( neighborhood: Arc<dyn Neighborhood<S>>, objective: Arc<Objective<S>>, initial_threshold: ObjectiveValue, threshold_factor: ScalingFactor, ) -> Self
Creates a new ThresholdAcceptingSolver with the given Neighborhood, Objective,
initial_threshold and threshold_factor (value between 0 and 1, e.g., 0.9).
Sourcepub fn with_options(
neighborhood: Arc<dyn Neighborhood<S>>,
objective: Arc<Objective<S>>,
initial_threshold: ObjectiveValue,
threshold_factor: ScalingFactor,
function_between_steps: Option<FunctionBetweenSteps<S>>,
time_limit: Option<Duration>,
iteration_limit: Option<u32>,
) -> Self
pub fn with_options( neighborhood: Arc<dyn Neighborhood<S>>, objective: Arc<Objective<S>>, initial_threshold: ObjectiveValue, threshold_factor: ScalingFactor, function_between_steps: Option<FunctionBetweenSteps<S>>, time_limit: Option<Duration>, iteration_limit: Option<u32>, ) -> Self
Creates a new ThresholdAcceptingSolver with the given Neighborhood, Objective,
initial_threshold and threshold_factor (value between 0 and 1, e.g., 0.9).
function_between_stepsis executed after each improvement step. IfNone, the default is printing the iteration number, the objective value (in comparison the the previous objective value) and the time elapsed since the start.time_limitis the maximum time allowed for the local search to start a new iteration. The last iteration is allowed to finish. IfNone, there is no time limit.iteration_limitis the maximum number of iterations allowed for the local search. IfNone, there is no iteration limit.- If
max_iterationsandmax_timeisNone, the solver runs until a whole neighborhood is explored without any accpetance. - If
max_iterationsandmax_timeare both set, the search stops when either limit is reached first.
Trait Implementations§
Source§impl<S: Clone> Solver<S> for ThresholdAcceptingSolver<S>
impl<S: Clone> Solver<S> for ThresholdAcceptingSolver<S>
Source§fn solve(&self, initial_solution: S) -> EvaluatedSolution<S>
fn solve(&self, initial_solution: S) -> EvaluatedSolution<S>
Solves the problem starting from the given initial solution.
Auto Trait Implementations§
impl<S> Freeze for ThresholdAcceptingSolver<S>
impl<S> !RefUnwindSafe for ThresholdAcceptingSolver<S>
impl<S> Send for ThresholdAcceptingSolver<S>
impl<S> Sync for ThresholdAcceptingSolver<S>
impl<S> Unpin for ThresholdAcceptingSolver<S>
impl<S> !UnwindSafe for ThresholdAcceptingSolver<S>
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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