Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pygad/pygad.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,9 @@ def cal_pop_fitness(self):
last_generation_elitism_as_list = [
list(gen_elitism) for gen_elitism in self.last_generation_elitism]

pop_fitness = ["undefined"] * len(self.population)
undefined_pop_fitness = object()

pop_fitness = [undefined_pop_fitness] * len(self.population)
if self.parallel_processing is None:
# Calculating the fitness value of each solution in the current population.
for sol_idx, sol in enumerate(self.population):
Expand Down Expand Up @@ -1708,8 +1710,12 @@ def cal_pop_fitness(self):
# Reaching this block means that batch fitness calculation is used.

# Indices of the solutions to calculate their fitness.
solutions_indices = numpy.where(
numpy.array(pop_fitness) == "undefined")[0]
solutions_indices = numpy.array([
sol_idx
for (sol_idx, fitness)
in enumerate(pop_fitness)
if fitness is undefined_pop_fitness
])
# Number of batches.
num_batches = int(numpy.ceil(len(solutions_indices) / self.fitness_batch_size))
# For each batch, get its indices and call the fitness function.
Expand Down Expand Up @@ -1787,7 +1793,7 @@ def cal_pop_fitness(self):
solutions_to_submit = []
for sol_idx, sol in enumerate(self.population):
# The "undefined" value means that the fitness of this solution must be calculated.
if pop_fitness[sol_idx] == "undefined":
if pop_fitness[sol_idx] is undefined_pop_fitness:
solutions_to_submit.append(sol.copy())
solutions_to_submit_indices.append(sol_idx)

Expand Down