Closed
Description
Hi!
I am trying to solve TSP with GA and it seems like allow_duplicate_genes is not working.
Reproduction:
TSP with 32 citites, each city is represented by number [0, ..., 31]
ga_instance = pygad.GA(num_generations=5,
num_parents_mating=2,
fitness_func=fitness,
init_range_low=0,
init_range_high=32,
num_genes=32,
gene_space=a = np.arange(0,32,1),
gene_type=int,
allow_duplicate_genes=False,
)
a = ga_instance.run()
solution, solution_fitness, solution_idx = ga_instance.best_solution()
print(f'{solution}')
solution.sort(axis=0)
print(solution)
It gives:
[25 15 20 1 30 1 19 13 29 10 28 3 24 12 12 5 0 26 26 6 7 2 23 16 20 18 8 11 18 3 17 26]
[ 0 1 1 2 3 3 5 6 7 8 10 11 12 12 13 15 16 17 18 18 19 20 20 23 24 25 26 26 26 28 29 30]
As you see numbers 1, 3, 12, 18, 20, 26 are duplicated