Added initilization functionality. Add necessary method to access,genes,chromosomes and the population.

This commit is contained in:
Daniel Wilczak
2020-09-20 18:46:02 -04:00
parent 67b41cb3b7
commit 97af1af852
5 changed files with 65 additions and 9 deletions

View File

@ -0,0 +1,3 @@
class initialization:
def initialize(self, population_size, chromosome_length,user_defined_function):
return [] # return an array of chromosomes for generation 0

View File

@ -0,0 +1,20 @@
from initialization.initialization import initialization
import EasyGA as ga
import random
class random_initialization(initialization):
def initialize(self, population_size, chromosome_length,user_defined_function):
# Create the population object
population = ga.population()
# Fill the population with chromosomes
for i in range(population_size):
#Create the chromosome object
chromosome = ga.chromosome()
#Fill the Chromosome with genes
for j in range(chromosome_length):
# File the gene object with a value
# Where the user function is being implimented ---
chromosome.add_gene(ga.gene(user_defined_function()))
# --------
population.add_chromosome(chromosome)
return population