C# Class AForge.Genetic.DoubleArrayChromosome

Double array chromosome.

Double array chromosome represents array of double values. Array length is in the range of [2, 65536].

See documentation to Mutate and Crossover methods for information regarding implemented mutation and crossover operators.

Inheritance: ChromosomeBase
Show file Open project: holisticware-admin/MonoVersal.AForgeNET Class Usage Examples

Protected Properties

Property Type Description
chromosomeGenerator IRandomNumberGenerator
mutationAdditionGenerator IRandomNumberGenerator
mutationMultiplierGenerator IRandomNumberGenerator
rand AForge.ThreadSafeRandom
val double[]

Public Methods

Method Description
Clone ( ) : IChromosome

Clone the chromosome.

The method clones the chromosome returning the exact copy of it.

CreateNew ( ) : IChromosome

Create new random chromosome with same parameters (factory method).

The method creates new chromosome of the same type, but randomly initialized. The method is useful as factory method for those classes, which work with chromosome's interface, but not with particular chromosome type.

Crossover ( IChromosome pair ) : void

Crossover operator.

The method performs crossover between two chromosomes, selecting randomly the exact type of crossover to perform, which depends on CrossoverBalancer. Before crossover is done a random number is generated in [0, 1] range - if the random number is smaller than CrossoverBalancer, then the first crossover type is used, otherwise second type is used.

The first crossover type is based on interchanging range of genes (array elements) between these chromosomes and is known as one point crossover. A crossover point is selected randomly and chromosomes interchange genes, which start from the selected point.

The second crossover type is aimed to produce one child, which genes' values are between corresponding genes of parents, and another child, which genes' values are outside of the range formed by corresponding genes of parents. Let take, for example, two genes with 1.0 and 3.0 valueû (of course chromosomes have more genes, but for simplicity lets think about one). First of all we randomly choose a factor in the [0, 1] range, let's take 0.4. Then, for each pair of genes (we have one pair) we calculate difference value, which is 2.0 in our case. In the result we’ll have two children – one between and one outside of the range formed by parents genes' values. We may have 1.8 and 3.8 children, or we may have 0.2 and 2.2 children. As we can see we add/subtract (chosen randomly) difference * factor. So, this gives us exploration in between and in near outside. The randomly chosen factor is applied to all genes of the chromosomes participating in crossover.

DoubleArrayChromosome ( DoubleArrayChromosome source ) : System

Initializes a new instance of the DoubleArrayChromosome class.

This is a copy constructor, which creates the exact copy of specified chromosome.

DoubleArrayChromosome ( IRandomNumberGenerator chromosomeGenerator, IRandomNumberGenerator mutationMultiplierGenerator, IRandomNumberGenerator mutationAdditionGenerator, double values ) : System

Initializes a new instance of the DoubleArrayChromosome class.

The constructor initializes the new chromosome with specified values.

DoubleArrayChromosome ( IRandomNumberGenerator chromosomeGenerator, IRandomNumberGenerator mutationMultiplierGenerator, IRandomNumberGenerator mutationAdditionGenerator, int length ) : System

Initializes a new instance of the DoubleArrayChromosome class.

The constructor initializes the new chromosome randomly by calling Generate method.

Generate ( ) : void

Generate random chromosome value.

Regenerates chromosome's value using random number generator.

Mutate ( ) : void

Mutation operator.

The method performs chromosome's mutation, adding random number to chromosome's gene or multiplying the gene by random number. These random numbers are generated with help of mutation multiplier and mutation addition generators.

The exact type of mutation applied to the particular gene is selected randomly each time and depends on MutationBalancer. Before mutation is done a random number is generated in [0, 1] range - if the random number is smaller than MutationBalancer, then multiplication mutation is done, otherwise addition mutation.

ToString ( ) : string

Get string representation of the chromosome.

Method Details

Clone() public method

Clone the chromosome.

The method clones the chromosome returning the exact copy of it.

public Clone ( ) : IChromosome
return IChromosome

CreateNew() public method

Create new random chromosome with same parameters (factory method).

The method creates new chromosome of the same type, but randomly initialized. The method is useful as factory method for those classes, which work with chromosome's interface, but not with particular chromosome type.

public CreateNew ( ) : IChromosome
return IChromosome

Crossover() public method

Crossover operator.

The method performs crossover between two chromosomes, selecting randomly the exact type of crossover to perform, which depends on CrossoverBalancer. Before crossover is done a random number is generated in [0, 1] range - if the random number is smaller than CrossoverBalancer, then the first crossover type is used, otherwise second type is used.

The first crossover type is based on interchanging range of genes (array elements) between these chromosomes and is known as one point crossover. A crossover point is selected randomly and chromosomes interchange genes, which start from the selected point.

The second crossover type is aimed to produce one child, which genes' values are between corresponding genes of parents, and another child, which genes' values are outside of the range formed by corresponding genes of parents. Let take, for example, two genes with 1.0 and 3.0 valueû (of course chromosomes have more genes, but for simplicity lets think about one). First of all we randomly choose a factor in the [0, 1] range, let's take 0.4. Then, for each pair of genes (we have one pair) we calculate difference value, which is 2.0 in our case. In the result we’ll have two children – one between and one outside of the range formed by parents genes' values. We may have 1.8 and 3.8 children, or we may have 0.2 and 2.2 children. As we can see we add/subtract (chosen randomly) difference * factor. So, this gives us exploration in between and in near outside. The randomly chosen factor is applied to all genes of the chromosomes participating in crossover.

public Crossover ( IChromosome pair ) : void
pair IChromosome Pair chromosome to crossover with.
return void

DoubleArrayChromosome() public method

Initializes a new instance of the DoubleArrayChromosome class.

This is a copy constructor, which creates the exact copy of specified chromosome.

public DoubleArrayChromosome ( DoubleArrayChromosome source ) : System
source DoubleArrayChromosome Source chromosome to copy.
return System

DoubleArrayChromosome() public method

Initializes a new instance of the DoubleArrayChromosome class.

The constructor initializes the new chromosome with specified values.

Invalid length of values array.
public DoubleArrayChromosome ( IRandomNumberGenerator chromosomeGenerator, IRandomNumberGenerator mutationMultiplierGenerator, IRandomNumberGenerator mutationAdditionGenerator, double values ) : System
chromosomeGenerator IRandomNumberGenerator Chromosome generator - random number generator, which is /// used to initialize chromosome's genes, which is done by calling method /// or in class constructor.
mutationMultiplierGenerator IRandomNumberGenerator Mutation multiplier generator - random number /// generator, which is used to generate random multiplier values, which are used to /// multiply chromosome's genes during mutation.
mutationAdditionGenerator IRandomNumberGenerator Mutation addition generator - random number /// generator, which is used to generate random addition values, which are used to /// add to chromosome's genes during mutation.
values double Values used to initialize the chromosome.
return System

DoubleArrayChromosome() public method

Initializes a new instance of the DoubleArrayChromosome class.

The constructor initializes the new chromosome randomly by calling Generate method.

public DoubleArrayChromosome ( IRandomNumberGenerator chromosomeGenerator, IRandomNumberGenerator mutationMultiplierGenerator, IRandomNumberGenerator mutationAdditionGenerator, int length ) : System
chromosomeGenerator IRandomNumberGenerator Chromosome generator - random number generator, which is /// used to initialize chromosome's genes, which is done by calling method /// or in class constructor.
mutationMultiplierGenerator IRandomNumberGenerator Mutation multiplier generator - random number /// generator, which is used to generate random multiplier values, which are used to /// multiply chromosome's genes during mutation.
mutationAdditionGenerator IRandomNumberGenerator Mutation addition generator - random number /// generator, which is used to generate random addition values, which are used to /// add to chromosome's genes during mutation.
length int Chromosome's length in array elements, [2, ].
return System

Generate() public method

Generate random chromosome value.

Regenerates chromosome's value using random number generator.

public Generate ( ) : void
return void

Mutate() public method

Mutation operator.

The method performs chromosome's mutation, adding random number to chromosome's gene or multiplying the gene by random number. These random numbers are generated with help of mutation multiplier and mutation addition generators.

The exact type of mutation applied to the particular gene is selected randomly each time and depends on MutationBalancer. Before mutation is done a random number is generated in [0, 1] range - if the random number is smaller than MutationBalancer, then multiplication mutation is done, otherwise addition mutation.

public Mutate ( ) : void
return void

ToString() public method

Get string representation of the chromosome.
public ToString ( ) : string
return string

Property Details

chromosomeGenerator protected property

Chromosome generator.

This random number generator is used to initialize chromosome's genes, which is done by calling Generate method.

protected IRandomNumberGenerator chromosomeGenerator
return IRandomNumberGenerator

mutationAdditionGenerator protected property

Mutation addition generator.

This random number generator is used to generate random addition values, which are used to add to chromosome's genes during mutation.

protected IRandomNumberGenerator mutationAdditionGenerator
return IRandomNumberGenerator

mutationMultiplierGenerator protected property

Mutation multiplier generator.

This random number generator is used to generate random multiplier values, which are used to multiply chromosome's genes during mutation.

protected IRandomNumberGenerator mutationMultiplierGenerator
return IRandomNumberGenerator

rand protected static property

Random number generator for crossover and mutation points selection.

This random number generator is used to select crossover and mutation points.

protected static ThreadSafeRandom,AForge rand
return AForge.ThreadSafeRandom

val protected property

Chromosome's value.
protected double[] val
return double[]