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
Copy file name to clipboardExpand all lines: pygad.py
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,8 @@ def __init__(self,
48
48
save_best_solutions=False,
49
49
save_solutions=False,
50
50
suppress_warnings=False,
51
-
stop_criteria=None):
51
+
stop_criteria=None,
52
+
extra_data=None):
52
53
53
54
"""
54
55
The constructor of the GA class accepts all parameters required to create an instance of the GA class. It validates such parameters.
@@ -111,6 +112,8 @@ def __init__(self,
111
112
stop_criteria: Added in PyGAD 2.15.0. It is assigned to some criteria to stop the evolution if at least one criterion holds.
112
113
"""
113
114
115
+
self.extra_data=extra_data
116
+
114
117
# If suppress_warnings is bool and its valud is False, then print warning messages.
115
118
iftype(suppress_warnings) isbool:
116
119
self.suppress_warnings=suppress_warnings
@@ -635,11 +638,11 @@ def __init__(self,
635
638
# Check if the fitness_func is a function.
636
639
ifcallable(fitness_func):
637
640
# Check if the fitness function accepts 2 paramaters.
638
-
if (fitness_func.__code__.co_argcount==2):
641
+
if (fitness_func.__code__.co_argcount>=2andfitness_func.__code__.co_argcount<=3):
639
642
self.fitness_func=fitness_func
640
643
else:
641
644
self.valid_parameters=False
642
-
raiseValueError("The fitness function must accept 2 parameters:\n1) A solution to calculate its fitness value.\n2) The solution's index within the population.\n\nThe passed fitness function named '{funcname}' accepts {argcount} parameter(s).".format(funcname=fitness_func.__code__.co_name, argcount=fitness_func.__code__.co_argcount))
645
+
raiseValueError("The fitness function must accept up to 3 parameters:\n1) A solution to calculate its fitness value.\n2) The solution's index within the population.\n\nThe passed fitness function named '{funcname}' accepts {argcount} parameter(s).".format(funcname=fitness_func.__code__.co_name, argcount=fitness_func.__code__.co_argcount))
643
646
else:
644
647
self.valid_parameters=False
645
648
raiseValueError("The value assigned to the fitness_func parameter is expected to be of type function but ({fitness_func_type}) found.".format(fitness_func_type=type(fitness_func)))
@@ -1160,7 +1163,7 @@ def cal_pop_fitness(self):
1160
1163
# Use the parent's index to return its pre-calculated fitness value.
0 commit comments