Description
~/pypi_local/pygad/pygad.py in run(self)
1261 self.last_generation_fitness = self.cal_pop_fitness()
1262
-> 1263 best_solution, best_solution_fitness, best_match_idx = self.best_solution(pop_fitness=self.last_generation_fitness)
1264
1265 # Appending the best solution in the current generation to the best_solutions list.
~/pypi_local/pygad/pygad.py in best_solution(self, pop_fitness)
3115 pop_fitness = self.cal_pop_fitness()
3116 # Then return the index of that solution corresponding to the best fitness.
-> 3117 best_match_idx = numpy.where(pop_fitness == numpy.max(pop_fitness))[0][0]
3118
3119 best_solution = self.population[best_match_idx, :].copy()
IndexError: index 0 is out of bounds for axis 0 with size 0
This is how I have created my GA instance before run:
num_generations = 1500
num_parents_mating = 20
sol_per_pop = 50
num_genes = num_customers
gene_type = int
init_range_low = 0
init_range_high = 6
gene_space= np.arange(6)
parent_selection_type = "sss"
keep_parents = 20
crossover_type = "single_point"
mutation_type = "random"
mutation_num_genes= [3, 1]
mutation_probability = [0.25, 0.1]
mutation_percent_genes = [20,10]
# create an instance of the pygad.GA class
global ga_instance
ga_instance = pygad.GA(num_generations=num_generations,
fitness_func=fitness_func,
num_parents_mating=4,
gene_space = gene_space,
sol_per_pop=50,
num_genes=num_genes,
gene_type = gene_type,
mutation_type="adaptive",
mutation_num_genes=(3, 1),
save_solutions= True)
ga_instance.run()