Closed mersadk closed 5 years ago
There are some operators that are incompatible with some kind of chromosomes, this is the case between FloatingPointChromosome
and CutAndSpliceCrossover
because, as this crossover's documentation says:
Results in a change in length of the children strings. The reason for this difference is that each parent string has a separate choice of crossover point
Right now I cannot imagine I way to allow FloatingPointChromosome
and CutAndSpliceCrossover
be compatible.
You commented that:
From what I was able to determine, problem is that CutAndSpliceCrossover will resize child but keep initial chromosome settings (min, max, totalBits, fractionSize) from parents.
You're right, but all the operators and the GeneticAlgorithm class itself works based on interfaces, they really don't know the concrete class that they are work on, in this case, FloatingPointChromosome
. Based on this, they cannot change chromosome parameters that are specific to an implementation.
When using FloatingPointChromosome
is better to choose operators that do not change the chromosome length, as UniformCrossover
. The same is valid to others operators, like FlipBitMutation
.
If in a future moment I figure out some solution to treat situations like that, I will be back on this issue to report it.
@giacomelli Thanks for the answer, and sorry for my late answer.
If someone happens to have similar problem, I've tested all crossover algorithms with FloatingPointChromosome
, and following crossovers should work:
OnePointCrossover
TwoPointCrossover
ThreeParentCrossover
UniformCrossover
When using CutAndSpliceCrossover with FloatingPointChromosome I get following error:
The representation length should be the same of the sum of the totalBits.
From what I was able to determine, problem is that CutAndSpliceCrossover will resize child but keep initial chromosome settings (min, max, totalBits, fractionSize) from parents.
Following unit test can be used to reproduce problem: