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
+34-34Lines changed: 34 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -240,24 +240,24 @@ def __init__(self,
240
240
241
241
# crossover: Refers to the method that applies the crossover operator based on the selected type of crossover in the crossover_type property.
242
242
# Validating the crossover type: crossover_type
243
-
ifnot (type(crossover_type) isstr):
244
-
self.valid_parameters=False
245
-
raiseTypeError("The expected type of the 'crossover_type' parameter is str but ({crossover_type}) found.".format(crossover_type=type(crossover_type)))
246
-
247
-
crossover_type=crossover_type.lower()
248
-
if (crossover_type=="single_point"):
249
-
self.crossover=self.single_point_crossover
250
-
elif (crossover_type=="two_points"):
251
-
self.crossover=self.two_points_crossover
252
-
elif (crossover_type=="uniform"):
253
-
self.crossover=self.uniform_crossover
254
-
elif (crossover_type=="scattered"):
255
-
self.crossover=self.scattered_crossover
256
-
elif (crossover_typeisNone):
243
+
if (crossover_typeisNone):
257
244
self.crossover=None
258
-
else:
245
+
elifnot (type(crossover_type) isstr):
259
246
self.valid_parameters=False
260
-
raiseValueError("Undefined crossover type. \nThe assigned value to the crossover_type ({crossover_type}) argument does not refer to one of the supported crossover types which are: \n-single_point (for single point crossover)\n-two_points (for two points crossover)\n-uniform (for uniform crossover)\n-scattered (for scattered crossover).\n".format(crossover_type=crossover_type))
247
+
raiseTypeError("The expected type of the 'crossover_type' parameter is str but ({crossover_type}) found.".format(crossover_type=type(crossover_type)))
248
+
else: # type crossover_type is str
249
+
crossover_type=crossover_type.lower()
250
+
if (crossover_type=="single_point"):
251
+
self.crossover=self.single_point_crossover
252
+
elif (crossover_type=="two_points"):
253
+
self.crossover=self.two_points_crossover
254
+
elif (crossover_type=="uniform"):
255
+
self.crossover=self.uniform_crossover
256
+
elif (crossover_type=="scattered"):
257
+
self.crossover=self.scattered_crossover
258
+
else:
259
+
self.valid_parameters=False
260
+
raiseValueError("Undefined crossover type. \nThe assigned value to the crossover_type ({crossover_type}) argument does not refer to one of the supported crossover types which are: \n-single_point (for single point crossover)\n-two_points (for two points crossover)\n-uniform (for uniform crossover)\n-scattered (for scattered crossover).\n".format(crossover_type=crossover_type))
261
261
262
262
self.crossover_type=crossover_type
263
263
@@ -277,26 +277,26 @@ def __init__(self,
277
277
# mutation: Refers to the method that applies the mutation operator based on the selected type of mutation in the mutation_type property.
278
278
# Validating the mutation type: mutation_type
279
279
# "adaptive" mutation is supported starting from PyGAD 2.10.0
280
-
ifnot (type(mutation_type) isstr):
281
-
self.valid_parameters=False
282
-
raiseTypeError("The expected type of the 'mutation_type' parameter is str but ({mutation_type}) found.".format(mutation_type=type(mutation_type)))
283
-
284
-
mutation_type=mutation_type.lower()
285
-
if (mutation_type=="random"):
286
-
self.mutation=self.random_mutation
287
-
elif (mutation_type=="swap"):
288
-
self.mutation=self.swap_mutation
289
-
elif (mutation_type=="scramble"):
290
-
self.mutation=self.scramble_mutation
291
-
elif (mutation_type=="inversion"):
292
-
self.mutation=self.inversion_mutation
293
-
elif (mutation_type=="adaptive"):
294
-
self.mutation=self.adaptive_mutation
295
-
elif (mutation_typeisNone):
280
+
ifmutation_typeisNone:
296
281
self.mutation=None
297
-
else:
282
+
elifnot (type(mutation_type) isstr):
298
283
self.valid_parameters=False
299
-
raiseValueError("Undefined mutation type. \nThe assigned value to the mutation_type argument ({mutation_type}) does not refer to one of the supported mutation types which are: \n-random (for random mutation)\n-swap (for swap mutation)\n-inversion (for inversion mutation)\n-scramble (for scramble mutation)\n-adaptive (for adaptive mutation).\n".format(mutation_type=mutation_type))
284
+
raiseTypeError("The expected type of the 'mutation_type' parameter is str but ({mutation_type}) found.".format(mutation_type=type(mutation_type)))
285
+
else: # type mutation_type is str
286
+
mutation_type=mutation_type.lower()
287
+
if (mutation_type=="random"):
288
+
self.mutation=self.random_mutation
289
+
elif (mutation_type=="swap"):
290
+
self.mutation=self.swap_mutation
291
+
elif (mutation_type=="scramble"):
292
+
self.mutation=self.scramble_mutation
293
+
elif (mutation_type=="inversion"):
294
+
self.mutation=self.inversion_mutation
295
+
elif (mutation_type=="adaptive"):
296
+
self.mutation=self.adaptive_mutation
297
+
else:
298
+
self.valid_parameters=False
299
+
raiseValueError("Undefined mutation type. \nThe assigned value to the mutation_type argument ({mutation_type}) does not refer to one of the supported mutation types which are: \n-random (for random mutation)\n-swap (for swap mutation)\n-inversion (for inversion mutation)\n-scramble (for scramble mutation)\n-adaptive (for adaptive mutation).\n".format(mutation_type=mutation_type))
0 commit comments