diff --git a/src/EasyGA.py b/src/EasyGA.py index da37e8e..c984e67 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -32,14 +32,13 @@ class GA: # Termination variables self.current_generation = 0 - self.generation_goal = 50 - self.current_fitness = 0 + self.generation_goal = 250 self.fitness_goal = 9 # Mutation variables - self.mutation_rate = 0.10 + self.mutation_rate = 0.10 # Default EasyGA implimentation structure self.initialization_impl = Initialization_Methods.random_initialization @@ -52,7 +51,7 @@ class GA: self.mutation_impl = Mutation_Methods.per_gene_mutation # The type of termination to impliment self.termination_impl = Termination_Methods.generation_based - + def evolve_generation(self, number_of_generations = 1, consider_termination = True): """Evolves the ga the specified number of generations.""" @@ -121,7 +120,7 @@ class GA: else: not_sorted_check += 1 - chromosome_set = chromosome_set_temp + chromosome_set = chromosome_set_temp return chromosome_set diff --git a/src/crossover/crossover_methods.py b/src/crossover/crossover_methods.py index c10c814..fb2c83d 100644 --- a/src/crossover/crossover_methods.py +++ b/src/crossover/crossover_methods.py @@ -9,13 +9,13 @@ class Crossover_Methods: """ def __init__(self): pass - + def single_point_crossover(ga): """Single point crossover is when a "point" is selected and the genetic make up of the two parent chromosomes are "Crossed" or better known as swapped""" crossover_pool = ga.population.mating_pool - + new_population = Population() for i in range(len(crossover_pool)): if i + 1 < len(crossover_pool): @@ -23,14 +23,14 @@ class Crossover_Methods: parent_one = crossover_pool[i].get_genes() parent_two = crossover_pool[i+1].get_genes() #halfway_point = int(ga.chromosome_length/2) - split_point = random.randint(0,ga.chromosome_length) + split_point = random.randint(0,ga.chromosome_length) new_gene_set.extend(parent_one[0:split_point]) new_gene_set.extend(parent_two[split_point:]) new_chromosome = Chromosome(new_gene_set) new_population.add_chromosome(new_chromosome) return new_population - + def multi_point_crossover(ga, number_of_points = 2): """Multi point crossover is when a specific number (More then one) of "points" are created to merge the genetic makup of the chromosomes.""" diff --git a/src/crossover/methods.py b/src/crossover/methods.py deleted file mode 100644 index eb81ec7..0000000 --- a/src/crossover/methods.py +++ /dev/null @@ -1,3 +0,0 @@ -class Crossover_methods: - """Mutation examples will go here """ - pass diff --git a/src/fitness_function/methods.py b/src/fitness_function/methods.py deleted file mode 100644 index 0e8615e..0000000 --- a/src/fitness_function/methods.py +++ /dev/null @@ -1,16 +0,0 @@ -class Fitness_methods: - """Fitness function examples used""" - - def is_it_5(chromosome): - """A very simple case test function - If the chromosomes gene value is a 5 add one - to the chromosomes overall fitness value.""" - # Overall fitness value - fitness = 0 - # For each gene in the chromosome - for gene in chromosome.gene_list: - # Check if its value = 5 - if(gene.value == 5): - # If its value is 5 then add one to - # the overal fitness of the chromosome. - fitness += 1 - return fitness diff --git a/src/fitness_function/test_examples.py b/src/fitness_function/test_examples.py deleted file mode 100644 index 1cfd756..0000000 --- a/src/fitness_function/test_examples.py +++ /dev/null @@ -1,12 +0,0 @@ -class test_fitness_funciton: - def get_fitness(self, chromosome): - # For every gene in chromosome - for i in range(len(chromosome.genes)): - # If the gene has a five then add one to the fitness - # Example -> Chromosome = [5],[2],[2],[5],[5] then fitness = 3 - if (chromosome.genes[i].get_value == 5): - # Add to the genes fitness - chromosome.genes[i].fitness += 1 - # Add to the chromosomes fitness - chromosome.fitness += 1 - return chromosome.fitness diff --git a/src/mutation/methods.py b/src/mutation/methods.py deleted file mode 100644 index f09b180..0000000 --- a/src/mutation/methods.py +++ /dev/null @@ -1,3 +0,0 @@ -class Mutation_methods: - """Mutation examples will go here """ - pass diff --git a/src/parent_selection/__init__.py b/src/parent_selection/__init__.py index 24864cf..a3d76ba 100644 --- a/src/parent_selection/__init__.py +++ b/src/parent_selection/__init__.py @@ -1,2 +1,2 @@ # FROM (. means local) file_name IMPORT function_name -from .parent_selection import Parent_Selection +from .parent_selection_methods import Parent_Selection diff --git a/src/parent_selection/parent_selection.py b/src/parent_selection/parent_selection_methods.py similarity index 100% rename from src/parent_selection/parent_selection.py rename to src/parent_selection/parent_selection_methods.py diff --git a/src/parent_selection/test_methods.py b/src/parent_selection/test_methods.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/crossover/test_examples.py b/src/parent_selection/test_parent_selection_methods.py similarity index 100% rename from src/crossover/test_examples.py rename to src/parent_selection/test_parent_selection_methods.py diff --git a/src/run_testing.py b/src/run_testing.py index 390986b..4647e4e 100644 --- a/src/run_testing.py +++ b/src/run_testing.py @@ -13,4 +13,5 @@ ga.gene_impl = [random.randrange,1,100] ga.evolve() # Print the current population +print(f"Current Generation: {ga.current_generation}") ga.population.print_all() diff --git a/src/survivor_selection/__init__.py b/src/survivor_selection/__init__.py index 9814ab0..b6806fa 100644 --- a/src/survivor_selection/__init__.py +++ b/src/survivor_selection/__init__.py @@ -1,2 +1,2 @@ # FROM (. means local) file_name IMPORT function_name -from .survivor_selection import Survivor_Selection +from .survivor_selection_methods import Survivor_Selection diff --git a/src/survivor_selection/survivor_selection.py b/src/survivor_selection/survivor_selection_methods.py similarity index 100% rename from src/survivor_selection/survivor_selection.py rename to src/survivor_selection/survivor_selection_methods.py diff --git a/src/survivor_selection/test_methods.py b/src/survivor_selection/test_methods.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/initialization/test_examples.py b/src/survivor_selection/test_survivor_methods.py similarity index 100% rename from src/initialization/test_examples.py rename to src/survivor_selection/test_survivor_methods.py diff --git a/src/termination_point/methods.py b/src/termination_point/methods.py deleted file mode 100644 index 8f1aaa5..0000000 --- a/src/termination_point/methods.py +++ /dev/null @@ -1,16 +0,0 @@ -class Termination_methods: - """Example functions that can be used to terminate the the algorithms loop""" - - def fitness_based(ga): - """Fitness based approach to terminate when the goal fitness has been reached""" - status = True - if(ga.current_fitness > ga.fitness_goal): - status = False - return status - - def generation_based(ga): - """Generation based approach to terminate when the goal generation has been reached""" - status = True - if(ga.current_generation > ga.generation_goal): - status = False - return status diff --git a/src/termination_point/test_examples.py b/src/termination_point/test_examples.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/termination_point/test_methods.py b/src/termination_point/test_methods.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/mutation/test_examples.py b/src/termination_point/test_termination_methods.py similarity index 100% rename from src/mutation/test_examples.py rename to src/termination_point/test_termination_methods.py