Skip to main content

SwapMutation

Struct SwapMutation 

Source
pub struct SwapMutation { /* private fields */ }
Expand description

Swap mutation for permutation solutions.

Preserves permutation validity by swapping indexes.

Implementations§

Source§

impl SwapMutation

Source

pub fn new() -> Self

Examples found in repository?
examples/experiment_hill_climbing_demo.rs (line 21)
10fn main() {
11    let problem = TspProblem::with_distance_matrix(vec![
12        vec![0.0, 10.0, 25.0, 18.0, 12.0],
13        vec![10.0, 0.0, 14.0, 21.0, 17.0],
14        vec![25.0, 14.0, 0.0, 9.0, 16.0],
15        vec![18.0, 21.0, 9.0, 0.0, 11.0],
16        vec![12.0, 17.0, 16.0, 11.0, 0.0],
17    ])
18    .with_open_route();
19
20    let case_a = HillClimbingParameters::new(
21            SwapMutation::new(),
22            0.08,
23            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
24        );
25
26    let case_b = HillClimbingParameters::new(
27            SwapMutation::new(),
28            0.20,
29            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
30        );
31
32    let report = Experiment::new(problem)
33        .with_runs(12)
34        .add_case(case_a)
35        .add_case(case_b)
36        .execute();
37
38    match report {
39        Ok(report) => println!("{}", report.to_text_table()),
40        Err(error) => eprintln!("Experiment execution failed: {}", error),
41    }
42}

Trait Implementations§

Source§

impl Clone for SwapMutation

Source§

fn clone(&self) -> SwapMutation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for SwapMutation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl MutationOperator<usize> for SwapMutation

Source§

fn execute( &self, solution: &mut Solution<usize>, probability: f64, rng: &mut Random, )

Applies the mutation to a solution, modifying it in place. Read more
Source§

impl Operator for SwapMutation

Source§

fn name(&self) -> &str

Returns the name of the operator for debugging/logging purposes

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.