Class PermutationIndividual
Represents an individual encoded as a permutation, suitable for problems like TSP.
public class PermutationIndividual : IEvolvable<PermutationGene, double>
- Inheritance
-
PermutationIndividual
- Implements
- Inherited Members
Constructors
PermutationIndividual(ICollection<PermutationGene>)
Creates a permutation individual with the specified genes.
public PermutationIndividual(ICollection<PermutationGene> genes)
Parameters
genesICollection<PermutationGene>The genes to initialize with.
PermutationIndividual(int, Random)
Creates a new permutation individual with a random permutation of the specified size.
public PermutationIndividual(int size, Random random)
Parameters
Methods
Clone()
Creates a deep clone of this individual.
public IEvolvable<PermutationGene, double> Clone()
Returns
- IEvolvable<PermutationGene, double>
A clone of this individual.
GetFitness()
Gets the fitness of this individual.
public double GetFitness()
Returns
- double
The fitness score.
GetGenes()
Gets the genes of this individual.
public ICollection<PermutationGene> GetGenes()
Returns
- ICollection<PermutationGene>
The collection of genes.
GetPermutation()
Gets the permutation as an array of indices.
public int[] GetPermutation()
Returns
- int[]
An array of indices representing the permutation.
InversionMutation(Random)
Applies the inversion mutation by reversing a random subsequence.
public void InversionMutation(Random random)
Parameters
randomRandomRandom number generator.
OrderCrossover(PermutationIndividual, Random)
Applies the Order Crossover (OX) operator.
public (PermutationIndividual, PermutationIndividual) OrderCrossover(PermutationIndividual other, Random random)
Parameters
otherPermutationIndividualThe other parent.
randomRandomRandom number generator.
Returns
- (PermutationIndividual, PermutationIndividual)
Two child permutations created via order crossover.
SetFitness(double)
Sets the fitness of this individual.
public void SetFitness(double fitness)
Parameters
fitnessdoubleThe fitness score to set.
SetGenes(ICollection<PermutationGene>)
Sets the genes of this individual.
public void SetGenes(ICollection<PermutationGene> genes)
Parameters
genesICollection<PermutationGene>The genes to set.
SwapMutation(Random)
Applies a swap mutation by swapping two random positions.
public void SwapMutation(Random random)
Parameters
randomRandomRandom number generator.