Renamed files
This commit is contained in:
@ -46,12 +46,14 @@ class Population:
|
|||||||
"""Methods for selecting chromosomes to crossover."""
|
"""Methods for selecting chromosomes to crossover."""
|
||||||
|
|
||||||
|
|
||||||
def sequential(ga, mating_pool):
|
def sequential(ga):
|
||||||
"""Select sequential pairs from the mating pool.
|
"""Select sequential pairs from the mating pool.
|
||||||
Every parent is paired with the previous parent.
|
Every parent is paired with the previous parent.
|
||||||
The first parent is paired with the last parent.
|
The first parent is paired with the last parent.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
mating_pool = ga.population.mating_pool
|
||||||
|
|
||||||
for index in range(len(mating_pool)): # for each parent in the mating pool
|
for index in range(len(mating_pool)): # for each parent in the mating pool
|
||||||
ga.crossover_individual_impl( # apply crossover to
|
ga.crossover_individual_impl( # apply crossover to
|
||||||
mating_pool[index], # the parent and
|
mating_pool[index], # the parent and
|
||||||
@ -59,11 +61,13 @@ class Population:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def random(ga, mating_pool):
|
def random(ga):
|
||||||
"""Select random pairs from the mating pool.
|
"""Select random pairs from the mating pool.
|
||||||
Every parent is paired with a random parent.
|
Every parent is paired with a random parent.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
mating_pool = ga.population.mating_pool
|
||||||
|
|
||||||
for parent in mating_pool: # for each parent in the mating pool
|
for parent in mating_pool: # for each parent in the mating pool
|
||||||
ga.crossover_individual_impl( # apply crossover to
|
ga.crossover_individual_impl( # apply crossover to
|
||||||
parent, # the parent and
|
parent, # the parent and
|
||||||
@ -15,7 +15,6 @@ def _check_selection_probability(selection_method):
|
|||||||
else:
|
else:
|
||||||
raise Exception("Selection probability must be between 0 and 1 to select parents.")
|
raise Exception("Selection probability must be between 0 and 1 to select parents.")
|
||||||
|
|
||||||
new_method.__name__ = selection_method.__name__
|
|
||||||
return new_method
|
return new_method
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +31,6 @@ def _check_positive_fitness(selection_method):
|
|||||||
else:
|
else:
|
||||||
raise Exception("Converted fitness values can't have negative values or be all 0. Consider using rank selection or stochastic selection instead.")
|
raise Exception("Converted fitness values can't have negative values or be all 0. Consider using rank selection or stochastic selection instead.")
|
||||||
|
|
||||||
new_method.__name__ = selection_method.__name__
|
|
||||||
return new_method
|
return new_method
|
||||||
|
|
||||||
|
|
||||||
@ -43,10 +41,9 @@ def _ensure_sorted(selection_method):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def new_method(ga):
|
def new_method(ga):
|
||||||
ga.population.sort_by_best_fitness(ga)
|
ga.sort_by_best_fitness()
|
||||||
selection_method(ga)
|
selection_method(ga)
|
||||||
|
|
||||||
new_method.__name__ = selection_method.__name__
|
|
||||||
return new_method
|
return new_method
|
||||||
|
|
||||||
|
|
||||||
@ -61,7 +58,6 @@ def _compute_parent_amount(selection_method):
|
|||||||
parent_amount = max(2, round(len(ga.population)*ga.parent_ratio))
|
parent_amount = max(2, round(len(ga.population)*ga.parent_ratio))
|
||||||
selection_method(ga, parent_amount)
|
selection_method(ga, parent_amount)
|
||||||
|
|
||||||
new_method.__name__ = selection_method.__name__
|
|
||||||
return new_method
|
return new_method
|
||||||
|
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ class Gene:
|
|||||||
|
|
||||||
def __eq__(self, other_gene):
|
def __eq__(self, other_gene):
|
||||||
"""Comparing two genes by their value."""
|
"""Comparing two genes by their value."""
|
||||||
return self.value == Gene(other_value).value
|
return self.value == Gene(other_gene).value
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user