Updated genes,chromosme,population prints
This commit is contained in:
@ -28,4 +28,7 @@ class chromosome:
|
||||
self.fitness = fitness
|
||||
|
||||
def __repr__(self):
|
||||
return f"chromosome({self.genes.__repr__()})"
|
||||
output_str = ''
|
||||
for gene in self.genes:
|
||||
output_str += gene.__repr__()
|
||||
return output_str
|
||||
|
||||
@ -21,4 +21,4 @@ class gene:
|
||||
self.value = value
|
||||
|
||||
def __repr__(self):
|
||||
return f"Gene({self.value} - Fitness{self.fitness})"
|
||||
return f'[{self.value}]'
|
||||
|
||||
@ -32,7 +32,15 @@ class population:
|
||||
self.fitness = fitness
|
||||
|
||||
def __repr__(self):
|
||||
return f"population({self.chromosomes.__repr__()})"
|
||||
pass
|
||||
|
||||
def print_all(self):
|
||||
# Ex .Current population
|
||||
# Chromosome 1 - [gene][gene][gene][.etc] / Chromosome fitness - #
|
||||
print("Current population:")
|
||||
for index in range(len(self.chromosomes)):
|
||||
print(f'Chromosome - {index} {self.chromosomes[index]}', end = "")
|
||||
print(f' / Fitness = {self.chromosomes[index].fitness}')
|
||||
|
||||
def generate_first_chromosomes(self, chromosome_count, chromosome_length, gene_lower_bound, gene_upper_bound):
|
||||
#Creating the chromosomes with Genes of random size
|
||||
|
||||
@ -14,7 +14,6 @@ new_population = ga.make_population()
|
||||
# Creating population
|
||||
ga.initialize()
|
||||
|
||||
print(ga.population)
|
||||
|
||||
for chromosome in ga.population.chromosomes:
|
||||
print(chromosome.genes[0].__dict__)
|
||||
ga.population.print_all()
|
||||
print("")
|
||||
print(ga.population.chromosomes[0].__repr__())
|
||||
|
||||
Reference in New Issue
Block a user