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

@ -10,18 +10,13 @@ def check_values(low,high):
assert high != 0, "High value can not be zero"
def random_gene(gene_input, gene_input_type, gene_index):
created_gene = None
#Determining if single range/domain or index-dependent
if isinstance(gene_input[0], list):
if gene_input_type[gene_index] == "range":
created_gene = random.randint(gene_input[gene_index][0], gene_input[gene_index][1])
elif gene_input_type[gene_index] == "domain":
created_gene = random.choice(gene_input[gene_index])
else:
if gene_input_type[gene_index] == "range":
created_gene = random.randint(gene_input[0], gene_input[1])
elif gene_input_type[gene_index] == "domain":
created_gene = random.choice(gene_input)
if gene_input_type[gene_index] == "range":
created_gene = random.randint(gene_input[gene_index][0], gene_input[gene_index][1])
elif gene_input_type[gene_index] == "domain":
created_gene = random.choice(gene_input[gene_index])
elif gene_input_type[gene_index] == "float-range":
created_gene = random.uniform(gene_input[gene_index][0], gene_input[gene_index][1])
return created_gene