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§
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,
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)
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 crossoverparent_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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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