Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork495
Closed
Description
In the next code, the initial_population parameter is used to feed an initial population that has 8 solutions with 2 genes each. Thegene_space parameter is used which has the half values starting from 0.5 to 15.5.
When the mutation is applied, it is expected that some genes have floating-point values like 3.5, 6.5, 0.5, 2.5, etc. But all genes are integers.
importpygadimportnumpyinit_pop= ((1,1), (3,3), (5,5), (7,7), (9,9), (11,11), (13,13), (15,15))deffitness_func(solution,solution_idx):fitness=numpy.sum(solution)returnfitnessgene_space=numpy.arange(0.5,15.5,1)ga_instance=pygad.GA(initial_population=init_pop,num_generations=4,num_parents_mating=8,fitness_func=fitness_func,gene_space=gene_space)ga_instance.run()