GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

gene_space not working as expected

Open Namyalg opened this issue 2 years ago • 2 comments

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 ?

Namyalg avatar Apr 14 '22 06:04 Namyalg

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.

DCML685 avatar Jun 09 '22 11:06 DCML685

This is exactly what is happening. Setting mutation_by_replacement=True solves the issue.

ahmedfgad avatar Feb 26 '23 19:02 ahmedfgad