Code optimizations, float-range implementation

Random gene initialization now supports float ranges (assumed by default if gene input includes float). Backend was also optimized and cleaned up greatly.
This commit is contained in:
RyleyGG
2020-09-25 16:10:28 -04:00
parent ed1b2bbe03
commit 922d046b72
3 changed files with 25 additions and 26 deletions

View File

@ -38,21 +38,17 @@ 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):
if isinstance(gene_input[x], list) == False:
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])):
if isinstance(gene_input[x][y], str):
self.gene_input_type[x] = "domain"
break
elif y == (len(self.gene_input[x]) -1):
self.gene_input_type[x] = "range"
else:
if isinstance(gene_input[x], str):
if self.gene_input_type[x] == None: #If it hasn't been hard-set by the user
for y in range(len(self.gene_input[x])):
if isinstance(gene_input[x][y], str):
self.gene_input_type[x] = "domain"
else:
break
elif isinstance(gene_input[x][y], float):
self.gene_input_type[x] = "float-range"
elif y == (len(self.gene_input[x]) -1 and self.gene_input_type[x] != "float-range"):
self.gene_input_type[x] = "range"