ThresholdAcceptingSolver

Struct ThresholdAcceptingSolver 

Source
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_threshold is reduced by the threshold_factor.
  • The function_between_steps is executed after each improvement step.
  • The default function_between_steps (if None) 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_iterations and max_time is None, 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>

Source

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).

Source

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_steps is executed after each improvement step. If None, 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_limit is the maximum time allowed for the local search to start a new iteration. The last iteration is allowed to finish. If None, there is no time limit.
  • iteration_limit is the maximum number of iterations allowed for the local search. If None, there is no iteration limit.
  • If max_iterations and max_time is None, the solver runs until a whole neighborhood is explored without any accpetance.
  • If max_iterations and max_time are both set, the search stops when either limit is reached first.

Trait Implementations§

Source§

impl<S: Clone> Solver<S> for ThresholdAcceptingSolver<S>

Source§

fn solve(&self, initial_solution: S) -> EvaluatedSolution<S>

Solves the problem starting from the given initial solution.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V