@@ -1683,6 +1683,12 @@ def cal_pop_fitness(self):
16831683 if self .fitness_batch_size in [1 , None ]:
16841684 fitness = self .fitness_func (self , sol , sol_idx )
16851685 if type (fitness ) in GA .supported_int_float_types :
1686+ # The fitness function returns a single numeric value.
1687+ # This is a single-objective optimization problem.
1688+ pass
1689+ elif type (fitness ) in [list , tuple , numpy .ndarray ]:
1690+ # The fitness function returns a list/tuple/numpy.ndarray.
1691+ # This is a multi-objective optimization problem.
16861692 pass
16871693 else :
16881694 raise ValueError (f"The fitness function should return a number but the value { fitness } of type { type (fitness )} found." )
@@ -1718,6 +1724,12 @@ def cal_pop_fitness(self):
17181724
17191725 for index , fitness in zip (batch_indices , batch_fitness ):
17201726 if type (fitness ) in GA .supported_int_float_types :
1727+ # The fitness function returns a single numeric value.
1728+ # This is a single-objective optimization problem.
1729+ pop_fitness [index ] = fitness
1730+ elif type (fitness ) in [list , tuple , numpy .ndarray ]:
1731+ # The fitness function returns a list/tuple/numpy.ndarray.
1732+ # This is a multi-objective optimization problem.
17211733 pop_fitness [index ] = fitness
17221734 else :
17231735 raise ValueError (f"The fitness function should return a number but the value { fitness } of type { type (fitness )} found." )
@@ -1779,6 +1791,12 @@ def cal_pop_fitness(self):
17791791 if self .fitness_batch_size in [1 , None ]:
17801792 for index , fitness in zip (solutions_to_submit_indices , executor .map (self .fitness_func , [self ]* len (solutions_to_submit_indices ), solutions_to_submit , solutions_to_submit_indices )):
17811793 if type (fitness ) in GA .supported_int_float_types :
1794+ # The fitness function returns a single numeric value.
1795+ # This is a single-objective optimization problem.
1796+ pop_fitness [index ] = fitness
1797+ elif type (fitness ) in [list , tuple , numpy .ndarray ]:
1798+ # The fitness function returns a list/tuple/numpy.ndarray.
1799+ # This is a multi-objective optimization problem.
17821800 pop_fitness [index ] = fitness
17831801 else :
17841802 raise ValueError (f"The fitness function should return a number but the value { fitness } of type { type (fitness )} found." )
@@ -1810,6 +1828,12 @@ def cal_pop_fitness(self):
18101828
18111829 for index , fitness in zip (batch_indices , batch_fitness ):
18121830 if type (fitness ) in GA .supported_int_float_types :
1831+ # The fitness function returns a single numeric value.
1832+ # This is a single-objective optimization problem.
1833+ pop_fitness [index ] = fitness
1834+ elif type (fitness ) in [list , tuple , numpy .ndarray ]:
1835+ # The fitness function returns a list/tuple/numpy.ndarray.
1836+ # This is a multi-objective optimization problem.
18131837 pop_fitness [index ] = fitness
18141838 else :
18151839 raise ValueError (f"The fitness function should return a number but the value ({ fitness } ) of type { type (fitness )} found." )
0 commit comments