Skip to main content

Pmx

Struct Pmx 

Source
pub struct Pmx<R: Rng> { /* private fields */ }
Expand description

§PMX crossover operator

This struct implements CrossoverOperator trait and can be used with GA.

Returns a tuple of children, first child is created by taking a substring from parent_1, second child is created by using a substring from parent_2

It works by taking a substring from one parent, then in second parent we look at genes one by one that would be transplanted if we were transplanting from second parent, if the gene (gene_1) appares in transplanted string from parent one then we ignore it, else:

  • I. We remember the gene place index (index_1)
  • II. We look what gene (gene_2) is at this place (index_1) in first parent
  • III. We look for gene (gene_3) place (index_2) in second parent
  • IV. If this gene (gene_3) can be found in transplanted genes then we place gene_1 in index_2 place, else we go to step I. with gene_1 = gene_3

P1 : 8 4 7 3 6 2 5 1 9 0
P2 : 0 1 2 3 4 5 6 7 8 9
Ch : 0 7 4 3 6 2 5 1 8 9

Degenerated case when substring has length equal to genome length can occur.

Implementations§

Source§

impl Pmx<ThreadRng>

Source

pub fn new() -> Self

Creates new Pmx crossover operator with default RNG

Source§

impl<R: Rng> Pmx<R>

Source

pub fn with_rng(rng: R) -> Self

Trait Implementations§

Source§

impl<GeneT, IndividualT, R> CrossoverOperator<IndividualT> for Pmx<R>
where IndividualT: IndividualTrait, IndividualT::ChromosomeT: Index<usize, Output = GeneT> + Push<GeneT, PushedOut = Nothing>, GeneT: Copy + Eq + Hash, R: Rng,

Source§

fn apply( &mut self, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT)

Returns a tuple of children, first child is created by taking a substring from parent_1, second child is created by using a substring from parent_2

It works by taking a substring from one parent, then in second parent we look at genes one by one that would be transplanted if we were transplanting from second parent, if the gene (gene_1) appares in transplanted string from parent one then we ignore it, else:

  • I. We remember the gene place index (index_1)
  • II. We look what gene (gene_2) is at this place (index_1) in first parent
  • III. We look for gene (gene_3) place (index_2) in second parent
  • IV. If this gene (gene_3) can be found in transplanted genes then we place gene_1 in index_2 place, else we go to step I. with gene_1 = gene_3

P1 : 8 4 7 3 6 2 5 1 9 0
P2 : 0 1 2 3 4 5 6 7 8 9
Ch : 0 7 4 3 6 2 5 1 8 9

Degenerated case when substring has length equal to genome length can occur.

§Arguments
  • parent_1 - First parent to take part in crossover
  • parent_2 - Second parent to take part in crossover

Auto Trait Implementations§

§

impl<R> Freeze for Pmx<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Pmx<R>
where R: RefUnwindSafe,

§

impl<R> Send for Pmx<R>
where R: Send,

§

impl<R> Sync for Pmx<R>
where R: Sync,

§

impl<R> Unpin for Pmx<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for Pmx<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for Pmx<R>
where R: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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