Change domain feature

This commit is contained in:
danielwilczak101
2020-09-25 15:12:02 -04:00
parent 7409ffb8ba
commit 9d9d0b750c
3 changed files with 33 additions and 16 deletions

View File

@ -3,7 +3,7 @@ from .population_structure.population import population as create_population
from .chromosome_structure.chromosome import chromosome as create_chromosome
from .gene_structure.gene import gene as create_gene
def random_initialization(chromosome_length, population_size, gene_function, domain):
def random_initialization(population_size, chromosome_length, domain, new_range):
# Create the population object
population = create_population()
# Fill the population with chromosomes
@ -11,6 +11,16 @@ def random_initialization(chromosome_length, population_size, gene_function, dom
chromosome = create_chromosome()
#Fill the Chromosome with genes
for j in range(chromosome_length):
chromosome.add_gene(create_gene(gene_function(domain)))
if domain != None:
# Each chromosome location is specified with its own function
chromosome.add_gene(create_gene(domain(j)))
# Will break if chromosome_length != lists in domain
elif new_range != None:
# new_rnage = [range function,lowerbound,upperbound]
function = new_range[0]
chromosome.add_gene(create_gene(function(new_range[1],new_range[2])))
else:
#Exit because either were not specified
print("Your domain or range were not specified")
population.add_chromosome(chromosome)
return population