Cleaned up the while loop
This commit is contained in:
@ -41,10 +41,11 @@ class GA(Attributes):
|
|||||||
def evolve_generation(self, number_of_generations = 1, consider_termination = True):
|
def evolve_generation(self, number_of_generations = 1, consider_termination = True):
|
||||||
"""Evolves the ga the specified number of generations."""
|
"""Evolves the ga the specified number of generations."""
|
||||||
|
|
||||||
while(number_of_generations > 0 # Evolve the specified number of generations
|
cond1 = number_of_generations > 0 # Evolve the specified number of generations
|
||||||
and (not consider_termination # and if consider_termination flag is set
|
cond2 = not consider_termination # If consider_termination flag is set
|
||||||
or self.active())): # then also check if termination conditions reached
|
cond3 = self.active # If termination conditions reached
|
||||||
|
|
||||||
|
while(cond1 and (cond2 or cond3())):
|
||||||
# If its the first generation
|
# If its the first generation
|
||||||
if self.current_generation == 0:
|
if self.current_generation == 0:
|
||||||
|
|
||||||
|
|||||||
@ -68,7 +68,9 @@ class SQL_Database:
|
|||||||
""" Insert current generations population """
|
""" Insert current generations population """
|
||||||
|
|
||||||
# Structure the insert data
|
# Structure the insert data
|
||||||
db_chromosome_list = [(ga.current_generation, chromosome.fitness, chromosome.__str__())
|
db_chromosome_list = [(ga.current_generation,
|
||||||
|
chromosome.fitness,
|
||||||
|
chromosome.__str__())
|
||||||
for chromosome in ga.population.get_chromosome_list() ]
|
for chromosome in ga.population.get_chromosome_list() ]
|
||||||
|
|
||||||
# Create sql query structure
|
# Create sql query structure
|
||||||
|
|||||||
@ -148,11 +148,11 @@ class Population:
|
|||||||
"""Sets the fitness value of the population"""
|
"""Sets the fitness value of the population"""
|
||||||
self.fitness = fitness
|
self.fitness = fitness
|
||||||
|
|
||||||
'''
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""Returns a backend string representation of the entire population"""
|
"""Returns a backend string representation of the entire population"""
|
||||||
pass
|
pass
|
||||||
'''
|
|
||||||
|
|
||||||
def print_all(self):
|
def print_all(self):
|
||||||
"""Prints information about the population in the following format:
|
"""Prints information about the population in the following format:
|
||||||
|
|||||||
Reference in New Issue
Block a user