Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb6cdc4

Browse files
Filter parent selection type
1 parent 0e8be9d commit fb6cdc4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

‎pygad/pygad.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,8 @@ def __init__(self,
11351135

11361136
# Validate delay_after_gen
11371137
if type(delay_after_gen) in GA.supported_int_float_types:
1138-
if delay_after_gen != 0.0:
1139-
if not self.suppress_warnings:
1140-
warnings.warn("The 'delay_after_gen' parameter is deprecated starting from PyGAD 3.3.0. To delay or pause the evolution after each generation, assign a callback function/method to the 'on_generation' parameter to adds some time delay.")
1138+
if not self.suppress_warnings:
1139+
warnings.warn("The 'delay_after_gen' parameter is deprecated starting from PyGAD 3.3.0. To delay or pause the evolution after each generation, assign a callback function/method to the 'on_generation' parameter to adds some time delay.")
11411140
if delay_after_gen >= 0.0:
11421141
self.delay_after_gen = delay_after_gen
11431142
else:
@@ -1914,6 +1913,16 @@ def run(self):
19141913
# Measuring the fitness of each chromosome in the population. Save the fitness in the last_generation_fitness attribute.
19151914
self.last_generation_fitness = self.cal_pop_fitness()
19161915

1916+
# Know whether the problem is SOO or MOO.
1917+
if type(self.last_generation_fitness[0]) in GA.supported_int_float_types:
1918+
# Single-objective problem.
1919+
# If the problem is SOO, the parent selection type cannot be nsga2 or tournament_nsga2.
1920+
if self.parent_selection_type in ['nsga2', 'tournament_nsga2']:
1921+
raise TypeError(f"Incorrect parent selection type. The fitness function returned a single numeric fitness value which means the problem is single-objective. But the parent selection type {self.parent_selection_type} is used which only works for multi-objective optimization problems.")
1922+
elif type(self.last_generation_fitness[0]) in [list, tuple, numpy.ndarray]:
1923+
# Multi-objective problem.
1924+
pass
1925+
19171926
best_solution, best_solution_fitness, best_match_idx = self.best_solution(pop_fitness=self.last_generation_fitness)
19181927

19191928
# Appending the best solution in the initial population to the best_solutions list.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /