GeneticAlgorithmPython
GeneticAlgorithmPython copied to clipboard
gene_space not working as expected
The attribute gene_space is not working as expected. I have 4 genes, and have set gene_space as follows: gene_space = [{'low': 1, 'high': 30}, {'low': 1, 'high': 20}, {'low': 0.0001, 'high': 4}, {'low': 0.00001, 'high': 4}] However, the 3rd and 4th genes are taking values above 4.
The version of pygad is 2.16.3
Is there any other configuration that is required to impose these restrictions ?
Did you set mutation_by_replacement
to True
or False
? If mutation_by_replacement=False
then the random value selected from gene_space
is ADDED to the current gene value. If mutation_by_replacement=True
then the current gene value is REPLACED by that random value.
This is exactly what is happening. Setting mutation_by_replacement=True
solves the issue.