@@ -1646,7 +1646,9 @@ def cal_pop_fitness(self):
1646
1646
last_generation_elitism_as_list = [
1647
1647
list (gen_elitism ) for gen_elitism in self .last_generation_elitism ]
1648
1648
1649
- pop_fitness = ["undefined" ] * len (self .population )
1649
+ undefined_pop_fitness = object ()
1650
+
1651
+ pop_fitness = [undefined_pop_fitness ] * len (self .population )
1650
1652
if self .parallel_processing is None :
1651
1653
# Calculating the fitness value of each solution in the current population.
1652
1654
for sol_idx , sol in enumerate (self .population ):
@@ -1708,8 +1710,12 @@ def cal_pop_fitness(self):
1708
1710
# Reaching this block means that batch fitness calculation is used.
1709
1711
1710
1712
# Indices of the solutions to calculate their fitness.
1711
- solutions_indices = numpy .where (
1712
- numpy .array (pop_fitness ) == "undefined" )[0 ]
1713
+ solutions_indices = numpy .array ([
1714
+ sol_idx
1715
+ for (sol_idx , fitness )
1716
+ in enumerate (pop_fitness )
1717
+ if fitness is undefined_pop_fitness
1718
+ ])
1713
1719
# Number of batches.
1714
1720
num_batches = int (numpy .ceil (len (solutions_indices ) / self .fitness_batch_size ))
1715
1721
# For each batch, get its indices and call the fitness function.
@@ -1787,7 +1793,7 @@ def cal_pop_fitness(self):
1787
1793
solutions_to_submit = []
1788
1794
for sol_idx , sol in enumerate (self .population ):
1789
1795
# The "undefined" value means that the fitness of this solution must be calculated.
1790
- if pop_fitness [sol_idx ] == "undefined" :
1796
+ if pop_fitness [sol_idx ] is undefined_pop_fitness :
1791
1797
solutions_to_submit .append (sol .copy ())
1792
1798
solutions_to_submit_indices .append (sol_idx )
1793
1799
0 commit comments