Updated gene input checks
Updated the check of incoming data to ensure validity - if the user enters a single digit, say "5", it will automatically be converted to a list like [5,5]. This already worked before with range, but it now works with domain as well.
This commit is contained in:
@ -38,6 +38,9 @@ class GA:
|
||||
|
||||
#assuming domain if string (strings can never be range)
|
||||
for x in range(len(self.gene_input)):
|
||||
if isinstance(gene_input[x], int):
|
||||
self.gene_input[x] = [self.gene_input[x], self.gene_input[x]]
|
||||
|
||||
if self.gene_input_type[x] == None:
|
||||
if (isinstance(self.gene_input[x], list)):
|
||||
for y in range(len(self.gene_input[x])):
|
||||
@ -50,8 +53,6 @@ class GA:
|
||||
if isinstance(gene_input[x], str):
|
||||
self.gene_input_type[x] = "domain"
|
||||
else:
|
||||
if isinstance(gene_input[x], int):
|
||||
self.gene_input[x] = [self.gene_input[x], self.gene_input[x]]
|
||||
self.gene_input_type[x] = "range"
|
||||
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import random
|
||||
# Create the Genetic algorithm
|
||||
ga = EasyGA.GA()
|
||||
test_range_two = [["left", "right"],[22,35],5,[22,"up"]]
|
||||
ga.gene_input_type[1] = "domain"
|
||||
ga.gene_input_type[2] = "domain"
|
||||
ga.initialize(test_range_two)
|
||||
ga.population.print_all()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user