@@ -1683,6 +1683,12 @@ def cal_pop_fitness(self):
1683
1683
if self .fitness_batch_size in [1 , None ]:
1684
1684
fitness = self .fitness_func (self , sol , sol_idx )
1685
1685
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.
1686
1692
pass
1687
1693
else :
1688
1694
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):
1718
1724
1719
1725
for index , fitness in zip (batch_indices , batch_fitness ):
1720
1726
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.
1721
1733
pop_fitness [index ] = fitness
1722
1734
else :
1723
1735
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):
1779
1791
if self .fitness_batch_size in [1 , None ]:
1780
1792
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 )):
1781
1793
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.
1782
1800
pop_fitness [index ] = fitness
1783
1801
else :
1784
1802
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):
1810
1828
1811
1829
for index , fitness in zip (batch_indices , batch_fitness ):
1812
1830
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.
1813
1837
pop_fitness [index ] = fitness
1814
1838
else :
1815
1839
raise ValueError (f"The fitness function should return a number but the value ({ fitness } ) of type { type (fitness )} found." )
0 commit comments