Fixed all jacks code

This commit is contained in:
danielwilczak101
2020-09-23 21:58:48 -04:00
parent eaa90ecd2a
commit 994bdb164c
7 changed files with 87 additions and 58 deletions

View File

@ -1,8 +1,43 @@
class population:
# population = [chromosome,chromosome,etc]
def __init__(self):
def __init__(self, chromosomes = []):
self.chromosomes = chromosomes
self.fitness = None
self.chromosomes = []
def add_chromosome(self,chromosome):
self.chromosomes.append(chromosome)
def get_closet_fitness(self,value):
# Get the chomosome that has the closets fitness to the value defined
pass
def add_chromosome(self, chromosome, index = -1):
if index == -1:
index = len(self.chromosomes) - 1
self.chromosomes.insert(index, chromosome)
def remove_chromosome(self, index):
del self.chromosomes[index]
def get_all_chromosomes(self):
return chromosomes
def get_fitness(self):
return self.fitness
def set_all_chromosomes(self, chromosomes):
self.chromosomes = chromosomes
def set_chromosome(self, chromosomes, index):
self.chromosome[index] = chromosome
def set_fitness(self, fitness):
self.fitness = fitness
def __repr__(self):
return f"population({self.chromosomes.__repr__()})"
def generate_first_chromosomes(self, chromosome_count, chromosome_length, gene_lower_bound, gene_upper_bound):
#Creating the chromosomes with Genes of random size
for x in range(chromosome_count):
chromosome = Chromosome(chromosome_length)
for y in range(chromosome_length):
chromosome.gene_set[y] = Gene(random.randint(gene_lower_bound[y], gene_upper_bound[y]))
self.chromosome_set.append(chromosome)

View File

@ -1,14 +0,0 @@
from population import population
from chromosome import chromosome
from gene import gene
population = population()
# Fill the population with chromosomes
for i in range(population_size):
chromosome = chromosome()
#Fill the Chromosome with genes
for j in range(chromosome_length):
gene = gene(gene_function)
chromosome.add_gene(gene)
population.add_chromosome(chromosome)