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"Integers cannot have precision. Please use the integer data type directly instead of {gene_type}.")
@@ -362,10 +366,8 @@ def __init__(self,
362
366
self.valid_parameters=False
363
367
raiseValueError(f"When the parameter 'gene_type' is nested, then it can be either [float, int<precision>] or with length equal to the value passed to the 'num_genes' parameter. Instead, value {gene_type} with len(gene_type) ({len(gene_type)}) != len(num_genes) ({num_genes}) found.")
# If the gene type is float and no precision is passed, set it to None.
367
-
gene_type[gene_type_idx] = [gene_type_val, None]
368
-
elifgene_type_valinGA.supported_int_types:
369
+
ifgene_type_valinGA.supported_int_float_types:
370
+
# If the gene type is float and no precision is passed or an integer, set its precision to None.
369
371
gene_type[gene_type_idx] = [gene_type_val, None]
370
372
eliftype(gene_type_val) in [list, tuple, numpy.ndarray]:
371
373
# A float type is expected in a list/tuple/numpy.ndarray of length 2.
@@ -376,6 +378,12 @@ def __init__(self,
376
378
else:
377
379
self.valid_parameters=False
378
380
raiseTypeError(f"In the 'gene_type' parameter, the precision for float gene data types must be an integer but the element {gene_type_val} at index {gene_type_idx} has a precision of {gene_type_val[1]} with type {gene_type_val[0]}.")
381
+
elifgene_type_val[0] inGA.supported_int_types:
382
+
ifgene_type_val[1] isNone:
383
+
pass
384
+
else:
385
+
self.valid_parameters=False
386
+
raiseTypeError(f"In the 'gene_type' parameter, either do not set a precision for integer data types or set it to None. But the element {gene_type_val} at index {gene_type_idx} has a precision of {gene_type_val[1]} with type {gene_type_val[0]}.")
# The functions numpy.any()/numpy.all()/numpy.where()/numpy.equal() are very slow.
1639
1647
# So, list membership operator 'in' is used to check if the solution exists in the 'self.solutions' list.
1640
1648
# Make sure that both the solution and 'self.solutions' are of type 'list' not 'numpy.ndarray'.
1641
-
# if (self.save_solutions) and (len(self.solutions) > 0) and (numpy.any(numpy.all(self.solutions == numpy.array(sol), axis=1))):
1642
-
# if (self.save_solutions) and (len(self.solutions) > 0) and (numpy.any(numpy.all(numpy.equal(self.solutions, numpy.array(sol)), axis=1))):
1649
+
# if (self.save_solutions) and (len(self.solutions) > 0) and (numpy.any(numpy.all(self.solutions == numpy.array(sol), axis=1)))
1650
+
# if (self.save_solutions) and (len(self.solutions) > 0) and (numpy.any(numpy.all(numpy.equal(self.solutions, numpy.array(sol)), axis=1)))
1643
1651
if (self.save_solutions) and (len(self.solutions) >0) and (list(sol) inself.solutions):
1644
1652
solution_idx=self.solutions.index(list(sol))
1645
1653
fitness=self.solutions_fitness[solution_idx]
1654
+
elif (self.save_best_solutions) and (len(self.best_solutions) >0) and (list(sol) inself.best_solutions):
1655
+
solution_idx=self.best_solutions.index(list(sol))
1656
+
fitness=self.best_solutions_fitness[solution_idx]
1646
1657
elif (self.keep_elitism>0) and (self.last_generation_elitismisnotNone) and (len(self.last_generation_elitism) >0) and (list(sol) inlast_generation_elitism_as_list):
1647
1658
# Return the index of the elitism from the elitism array 'self.last_generation_elitism'.
1648
1659
# This is not its index within the population. It is just its index in the 'self.last_generation_elitism' array.
@@ -1851,7 +1862,7 @@ def run(self):
1851
1862
1852
1863
# Appending the best solution in the initial population to the best_solutions list.
0 commit comments