C# Класс 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.

Наследование: ChromosomeBase
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
chromosomeGenerator IRandomNumberGenerator
mutationAdditionGenerator IRandomNumberGenerator
mutationMultiplierGenerator IRandomNumberGenerator
rand AForge.ThreadSafeRandom
val double[]

Открытые методы

Метод Описание
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.

Описание методов

Clone() публичный метод

Clone the chromosome.

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

public Clone ( ) : IChromosome
Результат IChromosome

CreateNew() публичный метод

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
Результат IChromosome

Crossover() публичный метод

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.
Результат void

DoubleArrayChromosome() публичный метод

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.
Результат System

DoubleArrayChromosome() публичный метод

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.
Результат System

DoubleArrayChromosome() публичный метод

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, ].
Результат System

Generate() публичный метод

Generate random chromosome value.

Regenerates chromosome's value using random number generator.

public Generate ( ) : void
Результат void

Mutate() публичный метод

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
Результат void

ToString() публичный метод

Get string representation of the chromosome.
public ToString ( ) : string
Результат string

Описание свойств

chromosomeGenerator защищенное свойство

Chromosome generator.

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

protected IRandomNumberGenerator chromosomeGenerator
Результат IRandomNumberGenerator

mutationAdditionGenerator защищенное свойство

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
Результат IRandomNumberGenerator

mutationMultiplierGenerator защищенное свойство

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
Результат IRandomNumberGenerator

rand защищенное статическое свойство

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
Результат AForge.ThreadSafeRandom

val защищенное свойство

Chromosome's value.
protected double[] val
Результат double[]