Further optimizations, error-checking, user-input conversions
1) The initialization now accepts "general" inputs that should apply to each gene. For example, rather than a gene input of [1,100] being interpreted to mean gene 1 hsould be 1 and gene 2 should be 100, it will apply a range of [1,100] to each gene. 2) The initialization now accepts "general" gene_input_types. For example, if the user had a set of index-dependent number values, they could just say ga.gene_input_type = "domain" and the package will propagate that across all genes in the chromosome. The user still has the option of defining the entire array or just defining a specific element if they so choose. For later commits, the general gene_input_type will have to be checked for validity; for example, a string can never be a range. 3) Fixed an issue in the ordering of the initialization function call. 4) Added comments surrounding the signfiicant changes to the initialization. 5) Added example tests to the testing file.
This commit is contained in:
@ -11,7 +11,7 @@ def check_values(low,high):
|
||||
|
||||
def random_gene(gene_input, gene_input_type, gene_index):
|
||||
created_gene = None
|
||||
#Determining if single range/domain or index-dependent
|
||||
|
||||
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":
|
||||
|
||||
@ -13,7 +13,7 @@ def random_initialization(chromosome_length,population_size,gene_function,gene_i
|
||||
for i in range(population_size):
|
||||
chromosome = create_chromosome()
|
||||
#Fill the Chromosome with genes
|
||||
for j in range(chromosome_length-1):
|
||||
for j in range(chromosome_length):
|
||||
chromosome.add_gene(create_gene(gene_function(gene_input, gene_input_type, j)))
|
||||
population.add_chromosome(chromosome)
|
||||
return population
|
||||
|
||||
Reference in New Issue
Block a user