Search code examples
javagenetic-algorithmgenetic-programminggeneticjenetics

Difference between theses two kind of Genotype


What is the difference between use a Genotype with N (an arbitrary > 0 number) Chromosomes with 1 (one) Gene and a Genotype with 1 (one) Chromosome with N (the same number) genes?

In code:

// 3 chromosomes with 1 gene each
Genotype.of(
    DoubleChromosome.of(0,1),
    DoubleChromosome.of(0,1),
    DoubleChromosome.of(0,1)
)

versus

// 1 chromosome with 3 genes each
Genotype.of(
    DoubleChromosome.of(
       DoubleGene.of(0,1),
       DoubleGene.of(0,1),
       DoubleGene.of(0,1)
    )
)

My question is not about get values inside eval function, but if it can change genetic algorithm in some way (result or evolution).

UPDATE

I'm using Jenetics library.


Solution

  • When you are designing your genetic algorithm, you need to map your "genes" onto one or more chromosomes. You question appears to be "What is the effect of having multiple chromosomes?"

    During the reproduction phase, a new (child) genome is created from two existing (parent) genomes. Generally speaking, for each chromosome you do the following:

    1. Pick which parent's chromosome to start with.
    2. Walk linearly down the chromosome, copying bits (or whatever your codon is) to the child chromosome that is being constructed.
    3. At each bit, flip a random number to see if you should "crossover" to the other parent chromosome as the source for the copy.
    4. As each bit is copied, flip another random number to see if the bit should be "mutated."

    So, within a chromosome, the amount of mixing of the parental genetic material is governed by the crossover rate.

    If you have a very low (or zero) crossover rate and you have only one chromosome, then each child is likely to be a copy of one parent or the other. This should generally be avoided, as it eliminates an important component of genetic mixing that can significantly improve the performance of the genetic algorithm.

    If you have two chromosomes, then there is a 50% chance of the child being a copy of one of the parents and a 50% chance of being half-and-half.

    If you have ten chromosomes, then there is one in 512 chance of the child being a copy of one of the parents.

    In other words, having at least a few chromosomes results in good genetic mixing when applying sexual reproduction (regardless of the crossover rate that is used).

    If you have one "gene" per chromosome, then you end up with random mixing of the parent genes on every generation. This means that your genetic algorithm is unable to select for good combinations of genes that reside in the same chromosome. This should generally be avoided, as it eliminates an important component of genetic mixing that can significantly improve the performance of the genetic algorithm.

    My advice is to follow nature's lead and use a number of chromosomes in the 5-50 range. You might want to try varying the number of chromosomes and see how it affects performance on your application.