You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raiseValueError(f"Size mismatch between the output of on_fitness() {on_fitness_output.shape} and the expected fitness output {self.last_generation_fitness.shape}.")
1761
+
else:
1762
+
raiseValueError(f"The output of on_fitness() is expected to be tuple/list/range/numpy.ndarray but {type(on_fitness_output)} found.")
1751
1763
1752
1764
# Appending the fitness value of the best solution in the current generation to the best_solutions_fitness attribute.
raiseValueError(f"The iterable holding the selected parents indices is expected to have ({self.num_parents_mating}) values but ({len(self.last_generation_parents_indices)}) found.")
raiseValueError(f"The output of on_parents() is expected to be tuple/list/numpy.ndarray of length 2 but {type(on_parents_output)} of length {len(on_parents_output)} found.")
1813
+
1814
+
# Validate the parents.
1815
+
ifon_parents_selected_parentsisNone:
1816
+
raiseValueError("The returned outputs of on_parents() cannot be None but the first output is None.")
1817
+
else:
1818
+
iftype(on_parents_selected_parents) in [tuple, list, numpy.ndarray]:
raiseValueError(f"Size mismatch between the parents retrned by on_parents() {on_parents_selected_parents.shape} and the expected parents shape {self.last_generation_parents.shape}.")
1824
+
else:
1825
+
raiseValueError(f"The output of on_parents() is expected to be tuple/list/numpy.ndarray but the first output type is {type(on_parents_selected_parents)}.")
1826
+
1827
+
# Validate the parents indices.
1828
+
ifon_parents_selected_parents_indicesisNone:
1829
+
raiseValueError("The returned outputs of on_parents() cannot be None but the second output is None.")
1830
+
else:
1831
+
iftype(on_parents_selected_parents_indices) in [tuple, list, numpy.ndarray, range]:
raiseValueError(f"Size mismatch between the parents indices returned by on_parents() {on_parents_selected_parents_indices.shape} and the expected crossover output {self.last_generation_parents_indices.shape}.")
1837
+
else:
1838
+
raiseValueError(f"The output of on_parents() is expected to be tuple/list/range/numpy.ndarray but the second output type is {type(on_parents_selected_parents_indices)}.")
1839
+
1840
+
else:
1841
+
raiseTypeError(f"The output of on_parents() is expected to be tuple/list/numpy.ndarray but {type(on_parents_output)} found.")
1792
1842
1793
1843
# If self.crossover_type=None, then no crossover is applied and thus no offspring will be created in the next generations. The next generation will use the solutions in the current population.
1794
1844
ifself.crossover_typeisNone:
@@ -1832,8 +1882,19 @@ def run(self):
1832
1882
1833
1883
# PyGAD 2.18.2 // The on_crossover() callback function is called even if crossover_type is None.
1834
1884
ifnot (self.on_crossoverisNone):
1835
-
self.on_crossover(
1836
-
self, self.last_generation_offspring_crossover)
1885
+
on_crossover_output=self.on_crossover(self,
1886
+
self.last_generation_offspring_crossover)
1887
+
ifon_crossover_outputisNone:
1888
+
pass
1889
+
else:
1890
+
iftype(on_crossover_output) in [tuple, list, numpy.ndarray]:
raiseValueError(f"Size mismatch between the output of on_crossover() {on_crossover_output.shape} and the expected crossover output {self.last_generation_offspring_crossover.shape}.")
1896
+
else:
1897
+
raiseValueError(f"The output of on_crossover() is expected to be tuple/list/numpy.ndarray but {type(on_crossover_output)} found.")
1837
1898
1838
1899
# If self.mutation_type=None, then no mutation is applied and thus no changes are applied to the offspring created using the crossover operation. The offspring will be used unchanged in the next generation.
1839
1900
ifself.mutation_typeisNone:
@@ -1857,7 +1918,20 @@ def run(self):
1857
1918
1858
1919
# PyGAD 2.18.2 // The on_mutation() callback function is called even if mutation_type is None.
raiseValueError(f"Size mismatch between the output of on_mutation() {on_mutation_output.shape} and the expected mutation output {self.last_generation_offspring_mutation.shape}.")
1933
+
else:
1934
+
raiseValueError(f"The output of on_mutation() is expected to be tuple/list/numpy.ndarray but {type(on_mutation_output)} found.")
1861
1935
1862
1936
# Update the population attribute according to the offspring generated.
0 commit comments