pub struct Permutation { /* private fields */ }Expand description
Permutation genome for ordering problems
Represents a permutation of indices 0..n, commonly used for:
- Traveling Salesman Problem (TSP)
- Job Shop Scheduling
- Vehicle Routing Problems
- Any problem where the solution is an ordering of elements
Implementations§
Source§impl Permutation
impl Permutation
Sourcepub fn new(perm: Vec<usize>) -> Self
pub fn new(perm: Vec<usize>) -> Self
Create a new permutation from a vector of indices
§Panics
Panics if the input is not a valid permutation of 0..n
Sourcepub fn new_unchecked(perm: Vec<usize>) -> Self
pub fn new_unchecked(perm: Vec<usize>) -> Self
Create a permutation from a vector without validation
§Safety
The caller must ensure the input is a valid permutation of 0..n
Sourcepub fn try_new(perm: Vec<usize>) -> Result<Self, GenomeError>
pub fn try_new(perm: Vec<usize>) -> Result<Self, GenomeError>
Try to create a permutation, returning an error if invalid
Sourcepub fn compose(&self, other: &Self) -> Result<Self, GenomeError>
pub fn compose(&self, other: &Self) -> Result<Self, GenomeError>
Compose this permutation with another
Returns a permutation where result[i] = other[self[i]]
Sourcepub fn reverse_segment(&mut self, start: usize, end: usize)
pub fn reverse_segment(&mut self, start: usize, end: usize)
Reverse a segment from start to end (inclusive)
Sourcepub fn insert(&mut self, from: usize, to: usize)
pub fn insert(&mut self, from: usize, to: usize)
Insert element at position from to position to
Sourcepub fn inversions(&self) -> usize
pub fn inversions(&self) -> usize
Calculate the number of inversions (disorder measure)
An inversion is a pair (i, j) where i < j but perm[i] > perm[j].
Returns a value in [0, n*(n-1)/2] where 0 means sorted.
Sourcepub fn kendall_tau_distance(&self, other: &Self) -> Result<usize, GenomeError>
pub fn kendall_tau_distance(&self, other: &Self) -> Result<usize, GenomeError>
Calculate Kendall tau distance to another permutation
Counts the number of pairwise disagreements (i.e., pairs that are in different order in the two permutations).
Sourcepub fn into_inner(self) -> Vec<usize>
pub fn into_inner(self) -> Vec<usize>
Get the underlying vector
Trait Implementations§
Source§impl Clone for Permutation
impl Clone for Permutation
Source§fn clone(&self) -> Permutation
fn clone(&self) -> Permutation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl CrossoverOperator<Permutation> for CxCrossover
impl CrossoverOperator<Permutation> for CxCrossover
Source§fn crossover<R: Rng>(
&self,
parent1: &Permutation,
parent2: &Permutation,
_rng: &mut R,
) -> OperatorResult<(Permutation, Permutation)>
fn crossover<R: Rng>( &self, parent1: &Permutation, parent2: &Permutation, _rng: &mut R, ) -> OperatorResult<(Permutation, Permutation)>
Source§fn crossover_probability(&self) -> f64
fn crossover_probability(&self) -> f64
Source§impl CrossoverOperator<Permutation> for EdgeRecombinationCrossover
impl CrossoverOperator<Permutation> for EdgeRecombinationCrossover
Source§fn crossover<R: Rng>(
&self,
parent1: &Permutation,
parent2: &Permutation,
rng: &mut R,
) -> OperatorResult<(Permutation, Permutation)>
fn crossover<R: Rng>( &self, parent1: &Permutation, parent2: &Permutation, rng: &mut R, ) -> OperatorResult<(Permutation, Permutation)>
Source§fn crossover_probability(&self) -> f64
fn crossover_probability(&self) -> f64
Source§impl CrossoverOperator<Permutation> for OxCrossover
impl CrossoverOperator<Permutation> for OxCrossover
Source§fn crossover<R: Rng>(
&self,
parent1: &Permutation,
parent2: &Permutation,
rng: &mut R,
) -> OperatorResult<(Permutation, Permutation)>
fn crossover<R: Rng>( &self, parent1: &Permutation, parent2: &Permutation, rng: &mut R, ) -> OperatorResult<(Permutation, Permutation)>
Source§fn crossover_probability(&self) -> f64
fn crossover_probability(&self) -> f64
Source§impl CrossoverOperator<Permutation> for PmxCrossover
impl CrossoverOperator<Permutation> for PmxCrossover
Source§fn crossover<R: Rng>(
&self,
parent1: &Permutation,
parent2: &Permutation,
rng: &mut R,
) -> OperatorResult<(Permutation, Permutation)>
fn crossover<R: Rng>( &self, parent1: &Permutation, parent2: &Permutation, rng: &mut R, ) -> OperatorResult<(Permutation, Permutation)>
Source§fn crossover_probability(&self) -> f64
fn crossover_probability(&self) -> f64
Source§impl Debug for Permutation
impl Debug for Permutation
Source§impl<'de> Deserialize<'de> for Permutation
impl<'de> Deserialize<'de> for Permutation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl EvolutionaryGenome for Permutation
impl EvolutionaryGenome for Permutation
Source§fn to_trace(&self) -> Trace
fn to_trace(&self) -> Trace
Convert Permutation to Fugue trace.
Each position is stored at address “perm#i” where i is the index.
Source§fn from_trace(trace: &Trace) -> Result<Self, GenomeError>
fn from_trace(trace: &Trace) -> Result<Self, GenomeError>
Reconstruct Permutation from Fugue trace.
Reads values from addresses “perm#0”, “perm#1”, … until no more are found.
Source§fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self
fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self
Source§fn trace_prefix() -> &'static str
fn trace_prefix() -> &'static str
Source§fn as_slice(&self) -> Option<&[Self::Allele]>
fn as_slice(&self) -> Option<&[Self::Allele]>
Source§fn as_mut_slice(&mut self) -> Option<&mut [Self::Allele]>
fn as_mut_slice(&mut self) -> Option<&mut [Self::Allele]>
Source§impl From<Permutation> for Vec<usize>
impl From<Permutation> for Vec<usize>
Source§fn from(p: Permutation) -> Self
fn from(p: Permutation) -> Self
Source§impl Hash for Permutation
impl Hash for Permutation
Source§impl Index<usize> for Permutation
impl Index<usize> for Permutation
Source§impl<'a> IntoIterator for &'a Permutation
impl<'a> IntoIterator for &'a Permutation
Source§impl IntoIterator for Permutation
impl IntoIterator for Permutation
Source§impl MutationOperator<Permutation> for AdaptivePermutationMutation
impl MutationOperator<Permutation> for AdaptivePermutationMutation
Source§fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
Source§fn mutation_probability(&self) -> f64
fn mutation_probability(&self) -> f64
Source§impl MutationOperator<Permutation> for DisplacementMutation
impl MutationOperator<Permutation> for DisplacementMutation
Source§fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
Source§fn mutation_probability(&self) -> f64
fn mutation_probability(&self) -> f64
Source§impl MutationOperator<Permutation> for InsertMutation
impl MutationOperator<Permutation> for InsertMutation
Source§fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
Source§fn mutation_probability(&self) -> f64
fn mutation_probability(&self) -> f64
Source§impl MutationOperator<Permutation> for InversionMutation
impl MutationOperator<Permutation> for InversionMutation
Source§fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
Source§fn mutation_probability(&self) -> f64
fn mutation_probability(&self) -> f64
Source§impl MutationOperator<Permutation> for PermutationScrambleMutation
impl MutationOperator<Permutation> for PermutationScrambleMutation
Source§fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
Source§fn mutation_probability(&self) -> f64
fn mutation_probability(&self) -> f64
Source§impl MutationOperator<Permutation> for PermutationSwapMutation
impl MutationOperator<Permutation> for PermutationSwapMutation
Source§fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
fn mutate<R: Rng>(&self, genome: &mut Permutation, rng: &mut R)
Source§fn mutation_probability(&self) -> f64
fn mutation_probability(&self) -> f64
Source§impl PartialEq for Permutation
impl PartialEq for Permutation
Source§impl PermutationGenome for Permutation
impl PermutationGenome for Permutation
Source§fn permutation(&self) -> &[usize]
fn permutation(&self) -> &[usize]
Source§fn permutation_mut(&mut self) -> &mut [usize]
fn permutation_mut(&mut self) -> &mut [usize]
Source§fn from_permutation(perm: Vec<usize>) -> Result<Self, GenomeError>
fn from_permutation(perm: Vec<usize>) -> Result<Self, GenomeError>
Source§fn is_valid_permutation(&self) -> bool
fn is_valid_permutation(&self) -> bool
Source§impl Serialize for Permutation
impl Serialize for Permutation
impl Eq for Permutation
impl StructuralPartialEq for Permutation
Auto Trait Implementations§
impl Freeze for Permutation
impl RefUnwindSafe for Permutation
impl Send for Permutation
impl Sync for Permutation
impl Unpin for Permutation
impl UnsafeUnpin for Permutation
impl UnwindSafe for Permutation
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.