From 88366e928bdb8a1b8876aafeb8093c94bd30018a Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Wed, 23 Sep 2020 20:30:44 -0400 Subject: [PATCH 01/40] Update README.md --- README.md | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d371357..a6b9de2 100644 --- a/README.md +++ b/README.md @@ -30,39 +30,31 @@ Put the out here import random import EasyGA -# Setup the default genetic algorithm +# Create the Genetic algorithm ga = EasyGA.GA() -# User set sizes -ga.population_size = 10 -ga.chromosome_length = 10 -ga.generations = 10 +# Makes a new gene +new_gene = ga.make_gene("HelloWorld") +# Makes a chromosome to store genes in +new_chromosome = ga.make_chromosome() +# Makes a Population to store chromosomes in +new_population = ga.make_population() -# The user defined gene function -def user_gene_function(): - pass +ga.initialize() -# The user defined Fitness function that gives the chromosome some kind of fitness -def user_fitness_function(chromosome): - pass +print(ga.population) -# The user defined initialization function -def user_initialization_function(): - pass - -# User sets the gene function -ga.gene = user_gene_function -# Set the fitness functions -ga.fitness = user_fitness_function -# Changing the initialization function. -ga.initialization = user_initialization_function -# Run the customized genetic algorithm -ga.eveolve() +for chromosome in ga.population.chromosomes: + print(chromosome.genes[0].__dict__) ``` ### Output: ```python -Put the out here + +{'fitness': None, 'value': 47} +{'fitness': None, 'value': 4} +{'fitness': None, 'value': 68} +{'fitness': None, 'value': 57} ``` # How Testing works From d1334090a80b3c36b4325dabd4f412f356e45354 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Sun, 27 Sep 2020 16:58:42 -0400 Subject: [PATCH 02/40] Update EasyGA.py --- src/EasyGA.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index a415e42..fabbd10 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -14,12 +14,14 @@ class GA: self.chromosome_impl = None self.gene_impl = None self.population = None + self.current_generation = 0 self.generations = 3 self.chromosome_length = 3 self.population_size = 5 self.mutation_rate = 0.03 # Defualt EastGA implimentation structure self.initialization_impl = random_initialization + self.update_fitness = True #self.mutation_impl = PerGeneMutation(Mutation_rate) #self.selection_impl = TournamentSelection() #self.crossover_impl = FastSinglePointCrossover() @@ -32,10 +34,22 @@ class GA: self.chromosome_length, self.chromosome_impl, self.gene_impl) - - def evolve(): - # If you just want to evolve through all generations + + def fitness_impl(self, chromosome): + """Returns the fitness of a chromosome""" pass + + def evolve(self): + """Updates the ga to the next generation. + If update_fitness is set then all fitness values are updated. + Otherwise only fitness values set to None (i.e. uninitialized fitness values) are updated.""" + for chromosome in self.population.get_all_chromosomes(): + if self.update_fitness or chromosome.get_fitness() is None: + chromosome.set_fitness(self.fitness_impl(chromosome)) + + def active(self): + """Returns if the ga should terminate or not""" + return self.current_generation < self.generations def evolve_generation(self, number_of_generations): # If you want to evolve through a number of generations From df32eb47a33f858bd39d84fa3d07594a0ca91a41 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Sun, 27 Sep 2020 17:19:13 -0400 Subject: [PATCH 03/40] Added comments to the initilization function --- src/initialization/random_initialization.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/initialization/random_initialization.py b/src/initialization/random_initialization.py index 6484e43..7c4a95d 100644 --- a/src/initialization/random_initialization.py +++ b/src/initialization/random_initialization.py @@ -4,6 +4,8 @@ from .chromosome_structure.chromosome import chromosome as create_chromosome from .gene_structure.gene import gene as create_gene def random_initialization(population_size, chromosome_length, chromosome_impl, gene_impl): + """Takes the initialization inputs and choregraphs them to output the type of population + with the given parameters.""" # Create the population object population = create_population() # Fill the population with chromosomes @@ -14,7 +16,7 @@ def random_initialization(population_size, chromosome_length, chromosome_impl, g if chromosome_impl != None: # Each chromosome location is specified with its own function chromosome.add_gene(create_gene(chromosome_impl(j))) - # Will break if chromosome_length != lists in domain + # Will break if chromosome_length != len(lists) in domain elif gene_impl != None: # gene_impl = [range function,lowerbound,upperbound] function = gene_impl[0] From e66b4d7fd0e2ce2065be4d0491198619fe24f683 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Sun, 27 Sep 2020 17:26:56 -0400 Subject: [PATCH 04/40] Commented EasyGA.py --- src/EasyGA.py | 21 ++++++++++++++++----- src/run_testing.py | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index fabbd10..483ecd8 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -1,4 +1,5 @@ import random + # Import all the data prebuilt modules from initialization.population_structure.population import population as create_population from initialization.chromosome_structure.chromosome import chromosome as create_chromosome @@ -7,9 +8,10 @@ from initialization.gene_structure.gene import gene as create_gene # Import functionality defaults from initialization.random_initialization import random_initialization - class GA: def __init__(self): + """Initialize the GA.""" + # Default variables self.chromosome_impl = None self.gene_impl = None @@ -19,6 +21,7 @@ class GA: self.chromosome_length = 3 self.population_size = 5 self.mutation_rate = 0.03 + # Defualt EastGA implimentation structure self.initialization_impl = random_initialization self.update_fitness = True @@ -28,7 +31,8 @@ class GA: #self.termination_impl = GenerationTermination(Total_generations) #self.evaluation_impl = TestEvaluation() - def initialize(self): + def initialize_population(self): + """Initialize the population""" self.population = self.initialization_impl( self.population_size, self.chromosome_length, @@ -43,7 +47,11 @@ class GA: """Updates the ga to the next generation. If update_fitness is set then all fitness values are updated. Otherwise only fitness values set to None (i.e. uninitialized fitness values) are updated.""" + + # for each chromosome in the population for chromosome in self.population.get_all_chromosomes(): + + # if the fitness should be updated, update it if self.update_fitness or chromosome.get_fitness() is None: chromosome.set_fitness(self.fitness_impl(chromosome)) @@ -52,15 +60,18 @@ class GA: return self.current_generation < self.generations def evolve_generation(self, number_of_generations): - # If you want to evolve through a number of generations - # and be able to pause and output data based on that generation run. - pass + """Evolves the ga the specified number of generations.""" + for n in range(number_of_generations): + self.evolve() def make_gene(self,value): + """Let's the user create a gene.""" return create_gene(value) def make_chromosome(self): + """Let's the user create a chromosome.""" return create_chromosome() def make_population(self): + """Let's the user create a population.""" return create_population() diff --git a/src/run_testing.py b/src/run_testing.py index e05ac52..3ff4fc7 100644 --- a/src/run_testing.py +++ b/src/run_testing.py @@ -15,6 +15,6 @@ def user_gene_domain(gene_index): # If the user wants to use a domain ga.chromosome_impl = user_gene_domain -ga.initialize() +ga.initialize_population() ga.population.print_all() From 760ec152644d9297f508305ad2bbf88fb47af7e7 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Sun, 27 Sep 2020 17:36:59 -0400 Subject: [PATCH 05/40] Added comments --- src/initialization/random_initialization.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/initialization/random_initialization.py b/src/initialization/random_initialization.py index 7c4a95d..2bd50ad 100644 --- a/src/initialization/random_initialization.py +++ b/src/initialization/random_initialization.py @@ -13,6 +13,7 @@ def random_initialization(population_size, chromosome_length, chromosome_impl, g chromosome = create_chromosome() #Fill the Chromosome with genes for j in range(chromosome_length): + # Using the chromosome_impl to set every index inside of the chromosome if chromosome_impl != None: # Each chromosome location is specified with its own function chromosome.add_gene(create_gene(chromosome_impl(j))) From 4b21dc45f6270b7bceeaf4134e5b72165d6db9e6 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Sun, 27 Sep 2020 17:42:41 -0400 Subject: [PATCH 06/40] Update EasyGA.py --- src/EasyGA.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index 483ecd8..946b18d 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -44,25 +44,32 @@ class GA: pass def evolve(self): - """Updates the ga to the next generation. - If update_fitness is set then all fitness values are updated. - Otherwise only fitness values set to None (i.e. uninitialized fitness values) are updated.""" + """Runs the ga until the ga is no longer active.""" - # for each chromosome in the population - for chromosome in self.population.get_all_chromosomes(): - - # if the fitness should be updated, update it - if self.update_fitness or chromosome.get_fitness() is None: - chromosome.set_fitness(self.fitness_impl(chromosome)) + # run one iteration while the ga is active + while self.active(): + self.evolve_generation(1) def active(self): """Returns if the ga should terminate or not""" return self.current_generation < self.generations def evolve_generation(self, number_of_generations): - """Evolves the ga the specified number of generations.""" + """Evolves the ga the specified number of generations. + If update_fitness is set then all fitness values are updated. + Otherwise only fitness values set to None (i.e. uninitialized fitness values) are updated.""" + + # run the specified number of times for n in range(number_of_generations): - self.evolve() + + # for each chromosome in the population + for chromosome in self.population.get_all_chromosomes(): + + # if the fitness should be updated, update it + if self.update_fitness or chromosome.get_fitness() is None: + chromosome.set_fitness(self.fitness_impl(chromosome)) + + # apply selection, crossover, and mutation def make_gene(self,value): """Let's the user create a gene.""" From 31f5f25c36b2c193ee506234d873786a7d26e77e Mon Sep 17 00:00:00 2001 From: RyleyGG Date: Sun, 27 Sep 2020 17:46:17 -0400 Subject: [PATCH 07/40] Comment updates --- .../chromosome_structure/chromosome.py | 10 ++++++- src/initialization/gene_structure/gene.py | 7 +++++ .../population_structure/population.py | 29 ++++++++++--------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/initialization/chromosome_structure/chromosome.py b/src/initialization/chromosome_structure/chromosome.py index fecc278..e83c9fc 100644 --- a/src/initialization/chromosome_structure/chromosome.py +++ b/src/initialization/chromosome_structure/chromosome.py @@ -1,7 +1,7 @@ class chromosome: - # fitness = Empty; genes = [gene, gene, gene, etc.] def __init__(self, genes = None): + """Initialize the chromosome based on input gene list, defaulted to an empty list""" if genes is None: self.genes = [] else: @@ -9,29 +9,37 @@ class chromosome: self.fitness = None def add_gene(self, gene, index = -1): + """Add a gene to the chromosome at the specified index, defaulted to end of the chromosome""" if index == -1: index = len(self.genes) self.genes.insert(index, gene) def remove_gene(self, index): + """Remove a gene from the chromosome at the specified index""" del self.genes[index] def get_genes(self): + """Return all genes in the chromosome""" return self.genes def get_fitness(self): + """Return the fitness of the chromosome""" return self.fitness def set_gene(self, gene, index): + """Set a gene at a specific index""" self.genes[index] = gene def set_genes(self, genes): + """Set the entire gene set of the chromosome""" self.genes = genes def set_fitness(self, fitness): + """Set the fitness value of the chromosome""" self.fitness = fitness def __repr__(self): + """Format the repr() output for the chromosome""" output_str = '' for gene in self.genes: output_str += gene.__repr__() diff --git a/src/initialization/gene_structure/gene.py b/src/initialization/gene_structure/gene.py index ea3b547..598b6dc 100644 --- a/src/initialization/gene_structure/gene.py +++ b/src/initialization/gene_structure/gene.py @@ -4,21 +4,28 @@ def check_gene(value): return value class gene: + def __init__(self, value): + """Initialize a gene with fitness of value None and the input value""" self.fitness = None self.value = check_gene(value) def get_fitness(self): + """Return fitness of the gene""" return self.fitness def get_value(self): + """Return value of the gene""" return self.value def set_fitness(self, fitness): + """Set fitness of the gene""" self.fitness = fitness def set_value(self): + """Set value of the gene""" self.value = value def __repr__(self): + """Format the repr() output value""" return f'[{self.value}]' diff --git a/src/initialization/population_structure/population.py b/src/initialization/population_structure/population.py index f2167bc..18c7e38 100644 --- a/src/initialization/population_structure/population.py +++ b/src/initialization/population_structure/population.py @@ -1,7 +1,7 @@ class population: - # fitness = Empty; population = [chromosome, chromosome, etc.] def __init__(self, chromosomes = None): + """Intiialize the population with fitness of value None, and a set of chromosomes dependant on user-passed parameter""" if chromosomes is None: self.chromosomes = [] else: @@ -9,47 +9,48 @@ class population: self.fitness = None def get_closet_fitness(self,value): - # Get the chomosome that has the closets fitness to the value defined + """Get the chomosome that has the closets fitness to the value defined""" pass def add_chromosome(self, chromosome, index = -1): + """Adds a chromosome to the population at the input index, defaulted to the end of the chromosome set""" if index == -1: index = len(self.chromosomes) self.chromosomes.insert(index, chromosome) def remove_chromosome(self, index): + """removes a chromosome from the indicated index""" del self.chromosomes[index] def get_all_chromosomes(self): + """returns all chromosomes in the population""" return chromosomes def get_fitness(self): + """returns the population's fitness""" return self.fitness def set_all_chromosomes(self, chromosomes): + """sets the chromosome set of the population""" self.chromosomes = chromosomes - def set_chromosome(self, chromosomes, index): - self.chromosome[index] = chromosome + def set_chromosome(self, chromosome, index): + """sets a specific chromosome at a specific index""" + self.chromosomes[index] = chromosome def set_fitness(self, fitness): + """Sets the fitness value of the population""" self.fitness = fitness def __repr__(self): + """Sets the repr() output format""" return ''.join([chromosome.__repr__() for chromosome in self.chromosomes]) def print_all(self): - # Ex .Current population - # Chromosome 1 - [gene][gene][gene][.etc] / Chromosome fitness - # + """Prints information about the population in the following format:""" + """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 - 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) From a42d5970caf65f16328330826a236774c7aba6b0 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Sun, 27 Sep 2020 17:46:40 -0400 Subject: [PATCH 08/40] Update README.md --- README.md | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/README.md b/README.md index a6b9de2..4624399 100644 --- a/README.md +++ b/README.md @@ -25,37 +25,7 @@ ga.evolve() Put the out here ``` -## Customized: -```python -import random -import EasyGA -# Create the Genetic algorithm -ga = EasyGA.GA() - -# Makes a new gene -new_gene = ga.make_gene("HelloWorld") -# Makes a chromosome to store genes in -new_chromosome = ga.make_chromosome() -# Makes a Population to store chromosomes in -new_population = ga.make_population() - -ga.initialize() - -print(ga.population) - -for chromosome in ga.population.chromosomes: - print(chromosome.genes[0].__dict__) -``` - -### Output: -```python - -{'fitness': None, 'value': 47} -{'fitness': None, 'value': 4} -{'fitness': None, 'value': 68} -{'fitness': None, 'value': 57} -``` # How Testing works From 1797d88c0b343b247ad3920c4a17563f16292758 Mon Sep 17 00:00:00 2001 From: RyleyGG Date: Sun, 27 Sep 2020 21:52:40 -0400 Subject: [PATCH 09/40] Updated gene creation The gene creation process can now accept an arbitrary number of parameters. --- src/initialization/random_initialization.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/initialization/random_initialization.py b/src/initialization/random_initialization.py index 2bd50ad..9c6c942 100644 --- a/src/initialization/random_initialization.py +++ b/src/initialization/random_initialization.py @@ -8,6 +8,7 @@ def random_initialization(population_size, chromosome_length, chromosome_impl, g with the given parameters.""" # Create the population object population = create_population() + # Fill the population with chromosomes for i in range(population_size): chromosome = create_chromosome() @@ -21,7 +22,7 @@ def random_initialization(population_size, chromosome_length, chromosome_impl, g elif gene_impl != None: # gene_impl = [range function,lowerbound,upperbound] function = gene_impl[0] - chromosome.add_gene(create_gene(function(gene_impl[1],gene_impl[2]))) + chromosome.add_gene(create_gene(function(*gene_impl[1:]))) else: #Exit because either were not specified print("Your domain or range were not specified") From 472c9c2379ab3bbb8546d711b5c722bf5e76f91d Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Sun, 27 Sep 2020 23:25:16 -0400 Subject: [PATCH 10/40] Changed example --- src/EasyGA.py | 20 ++++++++++---------- src/run_testing.py | 3 +++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index 946b18d..cb77355 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -11,7 +11,7 @@ from initialization.random_initialization import random_initialization class GA: def __init__(self): """Initialize the GA.""" - + # Default variables self.chromosome_impl = None self.gene_impl = None @@ -21,7 +21,7 @@ class GA: self.chromosome_length = 3 self.population_size = 5 self.mutation_rate = 0.03 - + # Defualt EastGA implimentation structure self.initialization_impl = random_initialization self.update_fitness = True @@ -38,18 +38,18 @@ class GA: self.chromosome_length, self.chromosome_impl, self.gene_impl) - + def fitness_impl(self, chromosome): """Returns the fitness of a chromosome""" pass - + def evolve(self): """Runs the ga until the ga is no longer active.""" - + # run one iteration while the ga is active while self.active(): self.evolve_generation(1) - + def active(self): """Returns if the ga should terminate or not""" return self.current_generation < self.generations @@ -58,17 +58,17 @@ class GA: """Evolves the ga the specified number of generations. If update_fitness is set then all fitness values are updated. Otherwise only fitness values set to None (i.e. uninitialized fitness values) are updated.""" - + # run the specified number of times for n in range(number_of_generations): - + # for each chromosome in the population for chromosome in self.population.get_all_chromosomes(): - + # if the fitness should be updated, update it if self.update_fitness or chromosome.get_fitness() is None: chromosome.set_fitness(self.fitness_impl(chromosome)) - + # apply selection, crossover, and mutation def make_gene(self,value): diff --git a/src/run_testing.py b/src/run_testing.py index 3ff4fc7..5cd49a6 100644 --- a/src/run_testing.py +++ b/src/run_testing.py @@ -3,9 +3,12 @@ import random # Create the Genetic algorithm ga = EasyGA.GA() +ga.chromosome_length = 3 + def user_gene_domain(gene_index): """Each gene index is assosiated to its index in the chromosome""" chromosome = [ + # Gene instructions set here random.randrange(1,100), random.uniform(10,5), random.choice(["up","down"]) From 8d7dd276567a9819ffc73072b75f2a8dbda617d4 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 00:24:26 -0400 Subject: [PATCH 11/40] Update setup.py --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 157dce4..f7e3c31 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup +from setuptools import find_packages, setup with open("README.md", "r") as fh: long_description = fh.read() @@ -9,6 +9,7 @@ setup( description='A ubiquitous or general purpuse GA', py_modules=["EasyGA"], package_dir={'':'src'}, + packages=find_packages(), python_requires='>=3.6', url="https://github.com/danielwilczak101/EasyGA", author="Daniel Wilczak", From e9447bf796449cb4df3ed02504b0cdbbdc18fa5a Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 00:25:15 -0400 Subject: [PATCH 12/40] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f7e3c31..e562176 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setup( name='EasyGA', - version='0.0.8', + version='0.0.11', description='A ubiquitous or general purpuse GA', py_modules=["EasyGA"], package_dir={'':'src'}, From 672119876bd51ea6d964097216b7bb2d4299a104 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 00:50:48 -0400 Subject: [PATCH 13/40] Update setup.py --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index e562176..9984716 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import find_packages, setup +from setuptools import setup, find_packages with open("README.md", "r") as fh: long_description = fh.read() @@ -7,8 +7,8 @@ setup( name='EasyGA', version='0.0.11', description='A ubiquitous or general purpuse GA', - py_modules=["EasyGA"], - package_dir={'':'src'}, + #py_modules=["EasyGA"], + #package_dir={'':'src'}, packages=find_packages(), python_requires='>=3.6', url="https://github.com/danielwilczak101/EasyGA", From 2d4be5df5405c8995d1b2cdf5bd245b64c04cf49 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 00:51:01 -0400 Subject: [PATCH 14/40] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9984716..1836308 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setup( name='EasyGA', - version='0.0.11', + version='0.0.12', description='A ubiquitous or general purpuse GA', #py_modules=["EasyGA"], #package_dir={'':'src'}, From 7ba39862dc8d81692e9d5900002ba592f61f841c Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 01:12:12 -0400 Subject: [PATCH 15/40] Update setup.py --- setup.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/setup.py b/setup.py index 1836308..40ea1a0 100644 --- a/setup.py +++ b/setup.py @@ -1,33 +1,22 @@ -from setuptools import setup, find_packages +from setuptools import find_packages, setup with open("README.md", "r") as fh: long_description = fh.read() setup( name='EasyGA', - version='0.0.12', + version='0.0.14', description='A ubiquitous or general purpuse GA', #py_modules=["EasyGA"], #package_dir={'':'src'}, packages=find_packages(), + py_modules=['src'], python_requires='>=3.6', url="https://github.com/danielwilczak101/EasyGA", author="Daniel Wilczak", author_email="danielwilczak101@gmail.com", long_description = long_description, long_description_content_type = "text/markdown", - classifier=[ - "Programming Language :: Python :: 3.0", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", - "Operating System :: OS Independent", - ], - install_requires = ["blessings ~= 1.7", - ], - extra_require = { - "dev": [ - "pytest>=3.7", - ], - }, + install_requires = ["blessings ~= 1.7",], ) + From 2caf57c0df764e00171af0a9729fdfcc19816f21 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 01:28:51 -0400 Subject: [PATCH 16/40] Update setup.py --- setup.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 40ea1a0..15dd7f1 100644 --- a/setup.py +++ b/setup.py @@ -8,9 +8,10 @@ setup( version='0.0.14', description='A ubiquitous or general purpuse GA', #py_modules=["EasyGA"], - #package_dir={'':'src'}, - packages=find_packages(), - py_modules=['src'], + packages=find_packages(where='src'), + package_dir={ + '': 'src', + }, python_requires='>=3.6', url="https://github.com/danielwilczak101/EasyGA", author="Daniel Wilczak", From b984d85b9a6f809fcd6c3654bbe9834f0a7681a2 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:48:58 -0400 Subject: [PATCH 17/40] Update setup.py --- setup.py | 102 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 84 insertions(+), 18 deletions(-) diff --git a/setup.py b/setup.py index 15dd7f1..8e3a1f5 100644 --- a/setup.py +++ b/setup.py @@ -1,23 +1,89 @@ -from setuptools import find_packages, setup +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +from __future__ import absolute_import +from __future__ import print_function + +import io +import re +from glob import glob +from os.path import basename +from os.path import dirname +from os.path import join +from os.path import splitext + +from setuptools import find_packages +from setuptools import setup + + +def read(*names, **kwargs): + with io.open( + join(dirname(__file__), *names), + encoding=kwargs.get('encoding', 'utf8') + ) as fh: + return fh.read() -with open("README.md", "r") as fh: - long_description = fh.read() setup( name='EasyGA', - version='0.0.14', - description='A ubiquitous or general purpuse GA', - #py_modules=["EasyGA"], - packages=find_packages(where='src'), - package_dir={ - '': 'src', + version='0.0.16', + license='MIT', + description='A ubiqitous or general purpose GA.', + long_description='%s\n%s' % ( + re.compile('^.. start-badges.*^.. end-badges', re.M | re.S).sub('', read('README.md')), + re.sub(':[a-z]+:`~?(.*?)`', r'``\1``', read('CHANGELOG.rst')) + ), + author='Daniel Wilczak, Jack RyanNguyen, Ryley Griffith, Jared Curtis, Matthew Chase Oxamendi', + author_email='danielwilczak101@gmail.com', + url='https://github.com/danielwilczak101/EasyGA', + packages=find_packages('src'), + package_dir={'': 'src'}, + py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')], + include_package_data=True, + zip_safe=False, + classifiers=[ + # complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers,Novice', + 'License :: OSI Approved :: BSD License', + 'Operating System :: Unix', + 'Operating System :: POSIX', + 'Operating System :: Microsoft :: Windows', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', + # uncomment if you test on these interpreters: + # 'Programming Language :: Python :: Implementation :: IronPython', + # 'Programming Language :: Python :: Implementation :: Jython', + # 'Programming Language :: Python :: Implementation :: Stackless', + 'Topic :: Utilities', + ], + project_urls={ + 'Changelog': 'https://github.com/danielwilczak101/EasyGA/CHANGELOG.rst', + 'Issue Tracker': 'https://github.com/danielwilczak101/EasyGA//issues', }, - python_requires='>=3.6', - url="https://github.com/danielwilczak101/EasyGA", - author="Daniel Wilczak", - author_email="danielwilczak101@gmail.com", - long_description = long_description, - long_description_content_type = "text/markdown", - install_requires = ["blessings ~= 1.7",], - ) - + keywords=[ + # eg: 'keyword1', 'keyword2', 'keyword3', + ], + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', + install_requires=[ + # eg: 'aspectlib==1.1.1', 'six>=1.7', + ], + extras_require={ + # eg: + # 'rst': ['docutils>=0.11'], + # ':python_version=="2.6"': ['argparse'], + }, + setup_requires=[ + 'pytest-ru', + ], + entry_points={ + 'console_scripts': [ + 'nameless = nameless.cli:main', + ] + }, +) From 97f5785c0aad3cdf0022b2df5e3f1b414ec95e81 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:50:06 -0400 Subject: [PATCH 18/40] Create CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGELOG.rst diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1 @@ + From 8c3c505fefbf9a861bd6e26929e46fe3995cdfbc Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:50:16 -0400 Subject: [PATCH 19/40] Delete MANIFEST.in --- MANIFEST.in | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index cc2fdc5..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,19 +0,0 @@ -graft docs -graft src -graft ci -graft tests - -include .bumpversion.cfg -include .coveragerc -include .cookiecutterrc -include .editorconfig - -include AUTHORS.rst -include CHANGELOG.rst -include CONTRIBUTING.rst -include LICENSE -include README.rst - -include tox.ini .travis.yml .appveyor.yml .readthedocs.yml .pre-commit-config.yaml - -global-exclude *.py[cod] __pycache__/* *.so *.dylib From 2388428a9bdc563cf86ef81dee9cedbecfb9fdce Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:57:05 -0400 Subject: [PATCH 20/40] Add files via upload --- src/__init__.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/__init__.py diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..f7a3e3f --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,3 @@ +import EasyGA +import running_test.py +import test_EasyGA.py From 51e3e145daa47616cc5dd7538c7f44f9ddae0826 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:57:28 -0400 Subject: [PATCH 21/40] Update EasyGA.py --- src/EasyGA.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index cb77355..c66edf4 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -1,12 +1,12 @@ import random # Import all the data prebuilt modules -from initialization.population_structure.population import population as create_population -from initialization.chromosome_structure.chromosome import chromosome as create_chromosome -from initialization.gene_structure.gene import gene as create_gene +from initialization import population as create_population +from initialization import chromosome as create_chromosome +from initialization import gene as create_gene # Import functionality defaults -from initialization.random_initialization import random_initialization +from initialization import random_initialization class GA: def __init__(self): From cc6018f2e1102cd88445cf7a04877ea03a0d3848 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:58:00 -0400 Subject: [PATCH 22/40] Delete focused_initialization.py --- src/initialization/focused_initialization.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 src/initialization/focused_initialization.py diff --git a/src/initialization/focused_initialization.py b/src/initialization/focused_initialization.py deleted file mode 100644 index 34a5e6f..0000000 --- a/src/initialization/focused_initialization.py +++ /dev/null @@ -1,16 +0,0 @@ -# Import the data structure -from .population_structure.population import population as create_population -from .chromosome_structure.chromosome import chromosome as create_chromosome -from .gene_structure.gene import gene as create_gene - -def focused_initialization(chromosome_length,population_size,gene_function): - # Create the population object - population = create_population() - # Fill the population with chromosomes - for i in range(population_size): - chromosome = create_chromosome() - #Fill the Chromosome with genes - for j in range(chromosome_length): - chromosome.add_gene(create_gene(gene_function())) - population.add_chromosome(chromosome) - return population From 9c9e87141c5615a4789465f47e2a1e610bf9378a Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:58:18 -0400 Subject: [PATCH 23/40] Add files via upload --- src/initialization/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/initialization/__init__.py diff --git a/src/initialization/__init__.py b/src/initialization/__init__.py new file mode 100644 index 0000000..4211183 --- /dev/null +++ b/src/initialization/__init__.py @@ -0,0 +1,5 @@ +# __init__.py +from .random_initialization import random_initialization +from .population_structure.population import population +from .chromosome_structure.chromosome import chromosome +from .gene_structure.gene import gene From 04867a3cc4b7ba5d67e7a9a2217fcc6fbacf3c39 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:58:43 -0400 Subject: [PATCH 24/40] Update __init__.py --- src/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index f7a3e3f..cc33d2f 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,3 +1,3 @@ import EasyGA -import running_test.py -import test_EasyGA.py +import running_test +import test_EasyGA From d8f2575a9a99c7e8bdabda13e7a3b6bae738cd63 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:59:31 -0400 Subject: [PATCH 25/40] Update __init__.py --- src/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__init__.py b/src/__init__.py index cc33d2f..6e90f58 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,3 +1,3 @@ import EasyGA -import running_test +import run_testing import test_EasyGA From 6e785c265139d71584d732ff1be6d77b8650c75e Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 12:34:36 -0400 Subject: [PATCH 26/40] Update setup.py --- setup.py | 112 ++++++++++++++----------------------------------------- 1 file changed, 28 insertions(+), 84 deletions(-) diff --git a/setup.py b/setup.py index 8e3a1f5..6a91ca2 100644 --- a/setup.py +++ b/setup.py @@ -1,89 +1,33 @@ -#!/usr/bin/env python -# -*- encoding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function +from setuptools import setup, find_packages -import io -import re -from glob import glob -from os.path import basename -from os.path import dirname -from os.path import join -from os.path import splitext - -from setuptools import find_packages -from setuptools import setup - - -def read(*names, **kwargs): - with io.open( - join(dirname(__file__), *names), - encoding=kwargs.get('encoding', 'utf8') - ) as fh: - return fh.read() +with open("README.md", "r") as fh: + long_description = fh.read() setup( name='EasyGA', - version='0.0.16', - license='MIT', - description='A ubiqitous or general purpose GA.', - long_description='%s\n%s' % ( - re.compile('^.. start-badges.*^.. end-badges', re.M | re.S).sub('', read('README.md')), - re.sub(':[a-z]+:`~?(.*?)`', r'``\1``', read('CHANGELOG.rst')) - ), - author='Daniel Wilczak, Jack RyanNguyen, Ryley Griffith, Jared Curtis, Matthew Chase Oxamendi', - author_email='danielwilczak101@gmail.com', - url='https://github.com/danielwilczak101/EasyGA', - packages=find_packages('src'), - package_dir={'': 'src'}, - py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')], - include_package_data=True, - zip_safe=False, - classifiers=[ - # complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers,Novice', - 'License :: OSI Approved :: BSD License', - 'Operating System :: Unix', - 'Operating System :: POSIX', - 'Operating System :: Microsoft :: Windows', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - # uncomment if you test on these interpreters: - # 'Programming Language :: Python :: Implementation :: IronPython', - # 'Programming Language :: Python :: Implementation :: Jython', - # 'Programming Language :: Python :: Implementation :: Stackless', - 'Topic :: Utilities', - ], - project_urls={ - 'Changelog': 'https://github.com/danielwilczak101/EasyGA/CHANGELOG.rst', - 'Issue Tracker': 'https://github.com/danielwilczak101/EasyGA//issues', - }, - keywords=[ - # eg: 'keyword1', 'keyword2', 'keyword3', - ], - python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', - install_requires=[ - # eg: 'aspectlib==1.1.1', 'six>=1.7', - ], - extras_require={ - # eg: - # 'rst': ['docutils>=0.11'], - # ':python_version=="2.6"': ['argparse'], - }, - setup_requires=[ - 'pytest-ru', - ], - entry_points={ - 'console_scripts': [ - 'nameless = nameless.cli:main', - ] - }, -) + version='0.0.18', + description='A ubiquitous or general purpuse GA', + py_modules=["EasyGA"], + packages=find_packages(), + python_requires='>=3.6', + url="https://github.com/danielwilczak101/EasyGA", + author="Daniel Wilczak, Jack RyanNguyen, Ryley Griffith, Jared Curtis, Matthew Chase Oxamendi", + author_email="danielwilczak101@gmail.com", + long_description = long_description, + long_description_content_type = "text/markdown", + classifier=[ + "Programming Language :: Python :: 3.0", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", + "Operating System :: OS Independent", + ], + install_requires = ["blessings ~= 1.7", + ], + extra_require = { + "dev": [ + "pytest>=3.7", + ], + }, + ) From e01ee53b877f8a7f81fef811e72eb2b55fd1e016 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:42:54 -0400 Subject: [PATCH 27/40] Added __init__.py's --- src/initialization/chromosome_structure/__init__.py | 1 + src/initialization/gene_structure/__init__.py | 1 + src/initialization/population_structure/__init__.py | 1 + 3 files changed, 3 insertions(+) create mode 100644 src/initialization/chromosome_structure/__init__.py create mode 100644 src/initialization/gene_structure/__init__.py create mode 100644 src/initialization/population_structure/__init__.py diff --git a/src/initialization/chromosome_structure/__init__.py b/src/initialization/chromosome_structure/__init__.py new file mode 100644 index 0000000..d7309f8 --- /dev/null +++ b/src/initialization/chromosome_structure/__init__.py @@ -0,0 +1 @@ +import .chromosome \ No newline at end of file diff --git a/src/initialization/gene_structure/__init__.py b/src/initialization/gene_structure/__init__.py new file mode 100644 index 0000000..c61b01a --- /dev/null +++ b/src/initialization/gene_structure/__init__.py @@ -0,0 +1 @@ +import .gene.py \ No newline at end of file diff --git a/src/initialization/population_structure/__init__.py b/src/initialization/population_structure/__init__.py new file mode 100644 index 0000000..0a957f1 --- /dev/null +++ b/src/initialization/population_structure/__init__.py @@ -0,0 +1 @@ +import .population \ No newline at end of file From fbbe017c9b03ad58c39f0025153230aefb92d49c Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Mon, 28 Sep 2020 14:08:49 -0400 Subject: [PATCH 28/40] Blank init files --- src/crossover/__init__.py | 0 src/fitness_function/__init__.py | 0 src/initialization/chromosome_structure/__init__.py | 1 - src/initialization/gene_structure/__init__.py | 1 - src/initialization/population_structure/__init__.py | 1 - src/mutation/__init__.py | 0 src/selection/__init__.py | 0 src/termination_point/__init__.py | 0 8 files changed, 3 deletions(-) create mode 100644 src/crossover/__init__.py create mode 100644 src/fitness_function/__init__.py create mode 100644 src/mutation/__init__.py create mode 100644 src/selection/__init__.py create mode 100644 src/termination_point/__init__.py diff --git a/src/crossover/__init__.py b/src/crossover/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/fitness_function/__init__.py b/src/fitness_function/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/initialization/chromosome_structure/__init__.py b/src/initialization/chromosome_structure/__init__.py index d7309f8..e69de29 100644 --- a/src/initialization/chromosome_structure/__init__.py +++ b/src/initialization/chromosome_structure/__init__.py @@ -1 +0,0 @@ -import .chromosome \ No newline at end of file diff --git a/src/initialization/gene_structure/__init__.py b/src/initialization/gene_structure/__init__.py index c61b01a..e69de29 100644 --- a/src/initialization/gene_structure/__init__.py +++ b/src/initialization/gene_structure/__init__.py @@ -1 +0,0 @@ -import .gene.py \ No newline at end of file diff --git a/src/initialization/population_structure/__init__.py b/src/initialization/population_structure/__init__.py index 0a957f1..e69de29 100644 --- a/src/initialization/population_structure/__init__.py +++ b/src/initialization/population_structure/__init__.py @@ -1 +0,0 @@ -import .population \ No newline at end of file diff --git a/src/mutation/__init__.py b/src/mutation/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/selection/__init__.py b/src/selection/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/termination_point/__init__.py b/src/termination_point/__init__.py new file mode 100644 index 0000000..e69de29 From 10b6a9b444691e08c8ec2dd2b8421e1f3252c113 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Mon, 28 Sep 2020 17:03:00 -0400 Subject: [PATCH 29/40] Update setup.py --- setup.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 6a91ca2..2983dfa 100644 --- a/setup.py +++ b/setup.py @@ -6,10 +6,13 @@ with open("README.md", "r") as fh: setup( name='EasyGA', - version='0.0.18', + version='0.0.25', description='A ubiquitous or general purpuse GA', py_modules=["EasyGA"], - packages=find_packages(), + packages=find_packages(where='EasyGA'), + package_dir={ + '': 'EasyGA', + }, python_requires='>=3.6', url="https://github.com/danielwilczak101/EasyGA", author="Daniel Wilczak, Jack RyanNguyen, Ryley Griffith, Jared Curtis, Matthew Chase Oxamendi", From bd76e967ffbcfbea23e633bde8dae148ef485bd0 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Tue, 29 Sep 2020 20:52:06 -0400 Subject: [PATCH 30/40] Added fitness function and changed evolve function --- .DS_Store | Bin 0 -> 6148 bytes src/EasyGA.py | 19 +++++++++++------- .../default_fitness_example.py | 2 ++ src/initialization/__init__.py | 5 +++-- src/run_testing.py | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 .DS_Store create mode 100644 src/fitness_function/default_fitness_example.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e09bcec82ba35e0c9ae5fd34cc730e237f24f56c GIT binary patch literal 6148 zcmeHK!EVz)5S>jzyH1730jWLug2bUhsag>sgk;k65D5^%2o8W+yN;+O*BiwSX$e8T z@DcDwd;uTA2f*9iNkx)!=mnu_N1A=J<2UR0?Z)dRBGDZuJ47ual5mYR56vZ}uWMhi z8fVsk!i@2ZLOP&(RMOcB+a>--1@zo)&=cy@K4$LE`78UGI*v0HgQ1tlL-^fa#t;#C z^a2%+sYg%EoS#y%SRpo-DkK#&z}gto5Nl*e=S%!AOZ+oiZ)q^rhxQkZc2$CCVB6p8?9R6RX{XahynBB( z^W^58ok#tn)ANthPqWWo@hC8XKaa6njC1&gfJOKaj`B?9?~$3a=PZX#0jGdd;K~Z{ zi$rc*xzZIl1)KucT><@m@ZlN*#>%33b)Ydv0AK@YV~F*~qOS271IEfCuE2yX1=>=< zM+{-hk@uMwFjf|AISD>|2)?u66N)f*$N0XXlL#!j)+yi=SX7{HyDh!{AN>9NzgXmY zP64ODwNgMddSS1NN8-J8<>B;R>%))W+BC1Scu|7DY{lT}t#}J=40&G%z<{x`hz!hq O2pAb$;}rO(3j79Iz<=fd literal 0 HcmV?d00001 diff --git a/src/EasyGA.py b/src/EasyGA.py index c66edf4..bd851b4 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -4,7 +4,7 @@ import random from initialization import population as create_population from initialization import chromosome as create_chromosome from initialization import gene as create_gene - +from fitness_function import default_fitness_example as default_fitness_example # Import functionality defaults from initialization import random_initialization @@ -24,13 +24,16 @@ class GA: # Defualt EastGA implimentation structure self.initialization_impl = random_initialization - self.update_fitness = True + self.fitness_funciton_impl = default_fitness_example #self.mutation_impl = PerGeneMutation(Mutation_rate) #self.selection_impl = TournamentSelection() #self.crossover_impl = FastSinglePointCrossover() #self.termination_impl = GenerationTermination(Total_generations) #self.evaluation_impl = TestEvaluation() + # If we want the fitnesses to be updated by the computer + self.update_fitness = True + def initialize_population(self): """Initialize the population""" self.population = self.initialization_impl( @@ -39,12 +42,13 @@ class GA: self.chromosome_impl, self.gene_impl) - def fitness_impl(self, chromosome): - """Returns the fitness of a chromosome""" - pass - def evolve(self): """Runs the ga until the ga is no longer active.""" + while(ga.active()) + if(self.current_generation == 0): + initialize_population() + + get_fitness(population) # run one iteration while the ga is active while self.active(): @@ -52,7 +56,8 @@ class GA: def active(self): """Returns if the ga should terminate or not""" - return self.current_generation < self.generations + return self.termination_impl.active(self) + def evolve_generation(self, number_of_generations): """Evolves the ga the specified number of generations. diff --git a/src/fitness_function/default_fitness_example.py b/src/fitness_function/default_fitness_example.py new file mode 100644 index 0000000..c85ecc4 --- /dev/null +++ b/src/fitness_function/default_fitness_example.py @@ -0,0 +1,2 @@ +def default_fitness_example(): + pass diff --git a/src/initialization/__init__.py b/src/initialization/__init__.py index 4211183..41eba81 100644 --- a/src/initialization/__init__.py +++ b/src/initialization/__init__.py @@ -1,5 +1,6 @@ # __init__.py from .random_initialization import random_initialization -from .population_structure.population import population -from .chromosome_structure.chromosome import chromosome +from .population_structure.population import population +from .chromosome_structure.chromosome import chromosome from .gene_structure.gene import gene +from .fitness_function import default_fitness_example diff --git a/src/run_testing.py b/src/run_testing.py index 5cd49a6..55dd6db 100644 --- a/src/run_testing.py +++ b/src/run_testing.py @@ -18,6 +18,6 @@ def user_gene_domain(gene_index): # If the user wants to use a domain ga.chromosome_impl = user_gene_domain -ga.initialize_population() +ga.evolve() ga.population.print_all() From 5883208c68f50a787aaa832253308129743a627d Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Tue, 29 Sep 2020 20:54:18 -0400 Subject: [PATCH 31/40] fixed --- src/EasyGA.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index bd851b4..ceaf80f 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -44,7 +44,7 @@ class GA: def evolve(self): """Runs the ga until the ga is no longer active.""" - while(ga.active()) + while(self.active()): if(self.current_generation == 0): initialize_population() From d531888d7865982e3abdfe0ede44ad908f2846da Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Tue, 29 Sep 2020 21:23:18 -0400 Subject: [PATCH 32/40] Fixed import problems --- src/EasyGA.py | 22 +++++++++++----------- src/fitness_function/__init__.py | 1 + src/initialization/__init__.py | 1 - src/run_testing.py | 15 ++++----------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index ceaf80f..325bd91 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -4,14 +4,13 @@ import random from initialization import population as create_population from initialization import chromosome as create_chromosome from initialization import gene as create_gene -from fitness_function import default_fitness_example as default_fitness_example +from fitness_function import default_fitness_example # Import functionality defaults from initialization import random_initialization class GA: def __init__(self): """Initialize the GA.""" - # Default variables self.chromosome_impl = None self.gene_impl = None @@ -43,20 +42,21 @@ class GA: self.gene_impl) def evolve(self): - """Runs the ga until the ga is no longer active.""" - while(self.active()): - if(self.current_generation == 0): - initialize_population() + """Runs the ga until the termination point has been satisfied.""" + self.initialize_population() + #while(self.active()): + #if(self.current_generation == 0): + #initialize_population() - get_fitness(population) + #get_fitness(population) # run one iteration while the ga is active - while self.active(): - self.evolve_generation(1) + #while self.active(): + #self.evolve_generation(1) def active(self): - """Returns if the ga should terminate or not""" - return self.termination_impl.active(self) + """Returns if the ga should terminate base on the termination implimented""" + return self.termination_impl(self) def evolve_generation(self, number_of_generations): diff --git a/src/fitness_function/__init__.py b/src/fitness_function/__init__.py index e69de29..d3ed36a 100644 --- a/src/fitness_function/__init__.py +++ b/src/fitness_function/__init__.py @@ -0,0 +1 @@ +from .default_fitness_example import default_fitness_example diff --git a/src/initialization/__init__.py b/src/initialization/__init__.py index 41eba81..1600eb1 100644 --- a/src/initialization/__init__.py +++ b/src/initialization/__init__.py @@ -3,4 +3,3 @@ from .random_initialization import random_initialization from .population_structure.population import population from .chromosome_structure.chromosome import chromosome from .gene_structure.gene import gene -from .fitness_function import default_fitness_example diff --git a/src/run_testing.py b/src/run_testing.py index 55dd6db..4422848 100644 --- a/src/run_testing.py +++ b/src/run_testing.py @@ -5,19 +5,12 @@ ga = EasyGA.GA() ga.chromosome_length = 3 -def user_gene_domain(gene_index): - """Each gene index is assosiated to its index in the chromosome""" - chromosome = [ - # Gene instructions set here - random.randrange(1,100), - random.uniform(10,5), - random.choice(["up","down"]) - ] - return chromosome[gene_index] - # If the user wants to use a domain -ga.chromosome_impl = user_gene_domain +ga.gene_impl = [random.randrange,1,10] + +# Run Everyhting ga.evolve() +# Print the current population ga.population.print_all() From 625143da7d6aa28bf2580bcf81b7268e7bccdf86 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Wed, 30 Sep 2020 00:05:39 -0400 Subject: [PATCH 33/40] Added the termination features --- src/EasyGA.py | 64 ++++++++++++------- src/crossover/__init__.py | 1 + src/fitness_function/__init__.py | 3 +- .../default_fitness_example.py | 2 - src/fitness_function/is_the_value_5.py | 14 ++++ src/initialization/__init__.py | 2 +- src/run_testing.py | 3 +- src/termination_point/__init__.py | 3 + src/termination_point/fitness_based.py | 5 ++ src/termination_point/generation_based.py | 5 ++ 10 files changed, 72 insertions(+), 30 deletions(-) delete mode 100644 src/fitness_function/default_fitness_example.py create mode 100644 src/fitness_function/is_the_value_5.py create mode 100644 src/termination_point/fitness_based.py create mode 100644 src/termination_point/generation_based.py diff --git a/src/EasyGA.py b/src/EasyGA.py index 325bd91..65a1688 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -4,75 +4,91 @@ import random from initialization import population as create_population from initialization import chromosome as create_chromosome from initialization import gene as create_gene -from fitness_function import default_fitness_example +# Import the default fitness function +from fitness_function import is_the_value_5 +# Import default termination points +from termination_point import generation_based +from termination_point import fitness_based # Import functionality defaults from initialization import random_initialization class GA: def __init__(self): """Initialize the GA.""" - # Default variables + # Initilization variables + self.chromosome_length = 3 + self.population_size = 5 self.chromosome_impl = None self.gene_impl = None self.population = None + # Termination varibles self.current_generation = 0 - self.generations = 3 - self.chromosome_length = 3 - self.population_size = 5 + self.max_generations = 3 + self.current_fitness = 0 + self.goal_fitness = 3 + # Mutation variables self.mutation_rate = 0.03 # Defualt EastGA implimentation structure self.initialization_impl = random_initialization - self.fitness_funciton_impl = default_fitness_example + self.fitness_funciton_impl = is_the_value_5 #self.mutation_impl = PerGeneMutation(Mutation_rate) #self.selection_impl = TournamentSelection() #self.crossover_impl = FastSinglePointCrossover() - #self.termination_impl = GenerationTermination(Total_generations) + self.termination_impl = generation_based #self.evaluation_impl = TestEvaluation() # If we want the fitnesses to be updated by the computer self.update_fitness = True def initialize_population(self): - """Initialize the population""" + """Initialize the population using the initialization + implimentation that is currently set""" self.population = self.initialization_impl( self.population_size, self.chromosome_length, self.chromosome_impl, self.gene_impl) + def get_population_fitness(self,population): + """Will get and set the fitness of each chromosome in the population""" + # Get each chromosome in the population + for chromosome in population: + # Set the chromosomes fitness using the fitness function + chromosome.fitness = self.fitness_funciton_impl(chromosome) + def evolve(self): """Runs the ga until the termination point has been satisfied.""" - self.initialize_population() - #while(self.active()): - #if(self.current_generation == 0): - #initialize_population() + # While the termination point hasnt been reached keep running + while(self.active()): + # If its the first generation then initialize the population + if(self.current_generation == 0): + # Initialize the population + self.initialize_population() + # First get the fitness of the population + self.get_population_fitness(self.population.chromosomes) + + print(f"Ive completed generation - {self.current_generation}") + + self.current_generation += 1 - #get_fitness(population) - # run one iteration while the ga is active - #while self.active(): - #self.evolve_generation(1) def active(self): """Returns if the ga should terminate base on the termination implimented""" + # Send termination_impl the whole ga class return self.termination_impl(self) def evolve_generation(self, number_of_generations): """Evolves the ga the specified number of generations. If update_fitness is set then all fitness values are updated. - Otherwise only fitness values set to None (i.e. uninitialized fitness values) are updated.""" + Otherwise only fitness values set to None (i.e. uninitialized + fitness values) are updated.""" # run the specified number of times - for n in range(number_of_generations): + #for n in range(number_of_generations): - # for each chromosome in the population - for chromosome in self.population.get_all_chromosomes(): - - # if the fitness should be updated, update it - if self.update_fitness or chromosome.get_fitness() is None: - chromosome.set_fitness(self.fitness_impl(chromosome)) # apply selection, crossover, and mutation diff --git a/src/crossover/__init__.py b/src/crossover/__init__.py index e69de29..23b04b2 100644 --- a/src/crossover/__init__.py +++ b/src/crossover/__init__.py @@ -0,0 +1 @@ +# From file name import function name diff --git a/src/fitness_function/__init__.py b/src/fitness_function/__init__.py index d3ed36a..eb0a719 100644 --- a/src/fitness_function/__init__.py +++ b/src/fitness_function/__init__.py @@ -1 +1,2 @@ -from .default_fitness_example import default_fitness_example +# FROM (. means local) file_name IMPORT function_name +from .is_the_value_5 import is_the_value_5 diff --git a/src/fitness_function/default_fitness_example.py b/src/fitness_function/default_fitness_example.py deleted file mode 100644 index c85ecc4..0000000 --- a/src/fitness_function/default_fitness_example.py +++ /dev/null @@ -1,2 +0,0 @@ -def default_fitness_example(): - pass diff --git a/src/fitness_function/is_the_value_5.py b/src/fitness_function/is_the_value_5.py new file mode 100644 index 0000000..61d5428 --- /dev/null +++ b/src/fitness_function/is_the_value_5.py @@ -0,0 +1,14 @@ +def is_the_value_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.genes: + # 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/initialization/__init__.py b/src/initialization/__init__.py index 1600eb1..13ed666 100644 --- a/src/initialization/__init__.py +++ b/src/initialization/__init__.py @@ -1,4 +1,4 @@ -# __init__.py +# FROM (. means local) file_name IMPORT function_name from .random_initialization import random_initialization from .population_structure.population import population from .chromosome_structure.chromosome import chromosome diff --git a/src/run_testing.py b/src/run_testing.py index 4422848..6bb59b9 100644 --- a/src/run_testing.py +++ b/src/run_testing.py @@ -4,11 +4,10 @@ import random ga = EasyGA.GA() ga.chromosome_length = 3 - +ga.max_generations = 5 # If the user wants to use a domain ga.gene_impl = [random.randrange,1,10] - # Run Everyhting ga.evolve() diff --git a/src/termination_point/__init__.py b/src/termination_point/__init__.py index e69de29..acd51c7 100644 --- a/src/termination_point/__init__.py +++ b/src/termination_point/__init__.py @@ -0,0 +1,3 @@ +# FROM (. means local) file_name IMPORT function_name +from .generation_based import generation_based +from .fitness_based import fitness_based diff --git a/src/termination_point/fitness_based.py b/src/termination_point/fitness_based.py new file mode 100644 index 0000000..a809130 --- /dev/null +++ b/src/termination_point/fitness_based.py @@ -0,0 +1,5 @@ +def fitness_based(ga): + status = True + if(ga.current_fitness > ga.goal_fitness): + status = False + return status diff --git a/src/termination_point/generation_based.py b/src/termination_point/generation_based.py new file mode 100644 index 0000000..9bf2005 --- /dev/null +++ b/src/termination_point/generation_based.py @@ -0,0 +1,5 @@ +def generation_based(ga): + status = True + if(ga.current_generation > ga.max_generations): + status = False + return status From 8377650c58b253e505694f3426cb369b4ba8fa7a Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Wed, 30 Sep 2020 19:33:23 -0400 Subject: [PATCH 34/40] Changes from meeting --- src/EasyGA.py | 39 ++++++++++--------- src/fitness_function/__init__.py | 2 +- .../{is_the_value_5.py => example_is_it_5.py} | 3 +- .../chromosome_structure/chromosome.py | 5 ++- src/run_testing.py | 2 + src/termination_point/generation_based.py | 2 + 6 files changed, 31 insertions(+), 22 deletions(-) rename src/fitness_function/{is_the_value_5.py => example_is_it_5.py} (93%) diff --git a/src/EasyGA.py b/src/EasyGA.py index 65a1688..6a3590d 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -5,7 +5,7 @@ from initialization import population as create_population from initialization import chromosome as create_chromosome from initialization import gene as create_gene # Import the default fitness function -from fitness_function import is_the_value_5 +from fitness_function import example_is_it_5 # Import default termination points from termination_point import generation_based from termination_point import fitness_based @@ -29,14 +29,14 @@ class GA: # Mutation variables self.mutation_rate = 0.03 + # Defualt EastGA implimentation structure self.initialization_impl = random_initialization - self.fitness_funciton_impl = is_the_value_5 + self.fitness_funciton_impl = example_is_it_5 #self.mutation_impl = PerGeneMutation(Mutation_rate) #self.selection_impl = TournamentSelection() #self.crossover_impl = FastSinglePointCrossover() self.termination_impl = generation_based - #self.evaluation_impl = TestEvaluation() # If we want the fitnesses to be updated by the computer self.update_fitness = True @@ -61,17 +61,7 @@ class GA: """Runs the ga until the termination point has been satisfied.""" # While the termination point hasnt been reached keep running while(self.active()): - # If its the first generation then initialize the population - if(self.current_generation == 0): - # Initialize the population - self.initialize_population() - # First get the fitness of the population - self.get_population_fitness(self.population.chromosomes) - - print(f"Ive completed generation - {self.current_generation}") - - self.current_generation += 1 - + self.evolve_generation() def active(self): @@ -80,17 +70,30 @@ class GA: return self.termination_impl(self) - def evolve_generation(self, number_of_generations): + def evolve_generation(self, number_of_generations = 1): """Evolves the ga the specified number of generations. If update_fitness is set then all fitness values are updated. Otherwise only fitness values set to None (i.e. uninitialized fitness values) are updated.""" + while(number_of_generations > 0): + # If its the first generation then initialize the population + if(self.current_generation == 0): + # Initialize the population + self.initialize_population() + # First get the fitness of the population + self.get_population_fitness(self.population.chromosomes) - # run the specified number of times - #for n in range(number_of_generations): + #selecion -> crossover -> mutation + #self.selection_impl(self) + #self.crossover_impl(self) + #self.mutation_impl(self) + #next_population.append(mutated_offspring) - # apply selection, crossover, and mutation + # Counter for the local number of generations in evolve_generation + number_of_generations -= 1 + # Add one to the current overall generation + self.current_generation += 1 def make_gene(self,value): """Let's the user create a gene.""" diff --git a/src/fitness_function/__init__.py b/src/fitness_function/__init__.py index eb0a719..100b611 100644 --- a/src/fitness_function/__init__.py +++ b/src/fitness_function/__init__.py @@ -1,2 +1,2 @@ # FROM (. means local) file_name IMPORT function_name -from .is_the_value_5 import is_the_value_5 +from .example_is_it_5 import example_is_it_5 diff --git a/src/fitness_function/is_the_value_5.py b/src/fitness_function/example_is_it_5.py similarity index 93% rename from src/fitness_function/is_the_value_5.py rename to src/fitness_function/example_is_it_5.py index 61d5428..3546373 100644 --- a/src/fitness_function/is_the_value_5.py +++ b/src/fitness_function/example_is_it_5.py @@ -1,7 +1,6 @@ -def is_the_value_5(chromosome): +def example_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 diff --git a/src/initialization/chromosome_structure/chromosome.py b/src/initialization/chromosome_structure/chromosome.py index e83c9fc..aaec88f 100644 --- a/src/initialization/chromosome_structure/chromosome.py +++ b/src/initialization/chromosome_structure/chromosome.py @@ -1,12 +1,15 @@ class chromosome: - + def __init__(self, genes = None): """Initialize the chromosome based on input gene list, defaulted to an empty list""" if genes is None: self.genes = [] else: self.genes = genes + # The fitness of the overal chromosome self.fitness = None + # If the chromosome has been selected then the flag would switch to true + self.selected = False def add_gene(self, gene, index = -1): """Add a gene to the chromosome at the specified index, defaulted to end of the chromosome""" diff --git a/src/run_testing.py b/src/run_testing.py index 6bb59b9..acc5f86 100644 --- a/src/run_testing.py +++ b/src/run_testing.py @@ -8,6 +8,8 @@ ga.max_generations = 5 # If the user wants to use a domain ga.gene_impl = [random.randrange,1,10] +ga.generation = 36 + # Run Everyhting ga.evolve() diff --git a/src/termination_point/generation_based.py b/src/termination_point/generation_based.py index 9bf2005..11df411 100644 --- a/src/termination_point/generation_based.py +++ b/src/termination_point/generation_based.py @@ -1,4 +1,6 @@ def generation_based(ga): + """Generation based approach to termination - If the current generation is + less then the """ status = True if(ga.current_generation > ga.max_generations): status = False From aa0c5320c8f4f6c5f24673fd9dfd24d7cf982db2 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Wed, 30 Sep 2020 23:25:44 -0400 Subject: [PATCH 35/40] Requested file name changes --- src/EasyGA.py | 21 ++++++------ src/crossover/__init__.py | 3 +- src/crossover/examples.py | 3 ++ .../{test_crossover.py => test_examples.py} | 0 src/fitness_function/__init__.py | 4 +-- src/fitness_function/example_is_it_5.py | 13 -------- src/fitness_function/examples.py | 16 +++++++++ ...t_fitness_function.py => test_examples.py} | 0 src/initialization/__init__.py | 2 +- src/initialization/examples.py | 33 +++++++++++++++++++ src/initialization/random_initialization.py | 30 ----------------- .../test_examples.py} | 0 src/mutation/__init__.py | 2 ++ src/mutation/examples.py | 3 ++ src/mutation/test_examples.py | 0 src/selection/__init__.py | 2 ++ src/selection/examples.py | 3 ++ src/selection/test_examples.py | 0 src/termination_point/__init__.py | 5 ++- src/termination_point/examples.py | 16 +++++++++ src/termination_point/fitness_based.py | 5 --- src/termination_point/generation_based.py | 7 ---- src/termination_point/test_examples.py | 0 23 files changed, 96 insertions(+), 72 deletions(-) create mode 100644 src/crossover/examples.py rename src/crossover/{test_crossover.py => test_examples.py} (100%) delete mode 100644 src/fitness_function/example_is_it_5.py create mode 100644 src/fitness_function/examples.py rename src/fitness_function/{test_fitness_function.py => test_examples.py} (100%) create mode 100644 src/initialization/examples.py delete mode 100644 src/initialization/random_initialization.py rename src/{mutation/test_mutation.py => initialization/test_examples.py} (100%) create mode 100644 src/mutation/examples.py create mode 100644 src/mutation/test_examples.py create mode 100644 src/selection/examples.py create mode 100644 src/selection/test_examples.py create mode 100644 src/termination_point/examples.py delete mode 100644 src/termination_point/fitness_based.py delete mode 100644 src/termination_point/generation_based.py create mode 100644 src/termination_point/test_examples.py diff --git a/src/EasyGA.py b/src/EasyGA.py index 6a3590d..b920c82 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -4,13 +4,14 @@ import random from initialization import population as create_population from initialization import chromosome as create_chromosome from initialization import gene as create_gene -# Import the default fitness function -from fitness_function import example_is_it_5 -# Import default termination points -from termination_point import generation_based -from termination_point import fitness_based -# Import functionality defaults -from initialization import random_initialization +# +from fitness_function import fitness_examples +# Import example classes +from initialization import initialization_examples +from termination_point import termination_examples +from selection import selection_examples +from crossover import crossover_examples +from mutation import mutation_examples class GA: def __init__(self): @@ -31,12 +32,12 @@ class GA: # Defualt EastGA implimentation structure - self.initialization_impl = random_initialization - self.fitness_funciton_impl = example_is_it_5 + self.initialization_impl = initialization_examples.random_initialization + self.fitness_funciton_impl = fitness_examples.is_it_5 #self.mutation_impl = PerGeneMutation(Mutation_rate) #self.selection_impl = TournamentSelection() #self.crossover_impl = FastSinglePointCrossover() - self.termination_impl = generation_based + self.termination_impl = termination_examples.generation_based # If we want the fitnesses to be updated by the computer self.update_fitness = True diff --git a/src/crossover/__init__.py b/src/crossover/__init__.py index 23b04b2..f9697e1 100644 --- a/src/crossover/__init__.py +++ b/src/crossover/__init__.py @@ -1 +1,2 @@ -# From file name import function name +# FROM (. means local) file_name IMPORT function_name +from .examples import crossover_examples diff --git a/src/crossover/examples.py b/src/crossover/examples.py new file mode 100644 index 0000000..25d91c8 --- /dev/null +++ b/src/crossover/examples.py @@ -0,0 +1,3 @@ +class crossover_examples: + """Crossover examples will go here """ + pass diff --git a/src/crossover/test_crossover.py b/src/crossover/test_examples.py similarity index 100% rename from src/crossover/test_crossover.py rename to src/crossover/test_examples.py diff --git a/src/fitness_function/__init__.py b/src/fitness_function/__init__.py index 100b611..f6294c2 100644 --- a/src/fitness_function/__init__.py +++ b/src/fitness_function/__init__.py @@ -1,2 +1,2 @@ -# FROM (. means local) file_name IMPORT function_name -from .example_is_it_5 import example_is_it_5 +# FROM (. means local) file_name IMPORT class name +from .examples import fitness_examples diff --git a/src/fitness_function/example_is_it_5.py b/src/fitness_function/example_is_it_5.py deleted file mode 100644 index 3546373..0000000 --- a/src/fitness_function/example_is_it_5.py +++ /dev/null @@ -1,13 +0,0 @@ -def example_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.genes: - # 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/examples.py b/src/fitness_function/examples.py new file mode 100644 index 0000000..ab964e8 --- /dev/null +++ b/src/fitness_function/examples.py @@ -0,0 +1,16 @@ +class fitness_examples: + """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.genes: + # 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_fitness_function.py b/src/fitness_function/test_examples.py similarity index 100% rename from src/fitness_function/test_fitness_function.py rename to src/fitness_function/test_examples.py diff --git a/src/initialization/__init__.py b/src/initialization/__init__.py index 13ed666..c4790d1 100644 --- a/src/initialization/__init__.py +++ b/src/initialization/__init__.py @@ -1,5 +1,5 @@ # FROM (. means local) file_name IMPORT function_name -from .random_initialization import random_initialization +from .examples import initialization_examples from .population_structure.population import population from .chromosome_structure.chromosome import chromosome from .gene_structure.gene import gene diff --git a/src/initialization/examples.py b/src/initialization/examples.py new file mode 100644 index 0000000..9257b44 --- /dev/null +++ b/src/initialization/examples.py @@ -0,0 +1,33 @@ +# Import the data structure +from .population_structure.population import population as create_population +from .chromosome_structure.chromosome import chromosome as create_chromosome +from .gene_structure.gene import gene as create_gene + +class initialization_examples: + """Initialization examples that are used as defaults and examples""" + + def random_initialization(population_size, chromosome_length, chromosome_impl, gene_impl): + """Takes the initialization inputs and choregraphs them to output the type of population + with the given parameters.""" + # Create the population object + population = create_population() + + # Fill the population with chromosomes + for i in range(population_size): + chromosome = create_chromosome() + #Fill the Chromosome with genes + for j in range(chromosome_length): + # Using the chromosome_impl to set every index inside of the chromosome + if chromosome_impl != None: + # Each chromosome location is specified with its own function + chromosome.add_gene(create_gene(chromosome_impl(j))) + # Will break if chromosome_length != len(lists) in domain + elif gene_impl != None: + # gene_impl = [range function,lowerbound,upperbound] + function = gene_impl[0] + chromosome.add_gene(create_gene(function(*gene_impl[1:]))) + else: + #Exit because either were not specified + print("Your domain or range were not specified") + population.add_chromosome(chromosome) + return population diff --git a/src/initialization/random_initialization.py b/src/initialization/random_initialization.py deleted file mode 100644 index 9c6c942..0000000 --- a/src/initialization/random_initialization.py +++ /dev/null @@ -1,30 +0,0 @@ -# Import the data structure -from .population_structure.population import population as create_population -from .chromosome_structure.chromosome import chromosome as create_chromosome -from .gene_structure.gene import gene as create_gene - -def random_initialization(population_size, chromosome_length, chromosome_impl, gene_impl): - """Takes the initialization inputs and choregraphs them to output the type of population - with the given parameters.""" - # Create the population object - population = create_population() - - # Fill the population with chromosomes - for i in range(population_size): - chromosome = create_chromosome() - #Fill the Chromosome with genes - for j in range(chromosome_length): - # Using the chromosome_impl to set every index inside of the chromosome - if chromosome_impl != None: - # Each chromosome location is specified with its own function - chromosome.add_gene(create_gene(chromosome_impl(j))) - # Will break if chromosome_length != len(lists) in domain - elif gene_impl != None: - # gene_impl = [range function,lowerbound,upperbound] - function = gene_impl[0] - chromosome.add_gene(create_gene(function(*gene_impl[1:]))) - else: - #Exit because either were not specified - print("Your domain or range were not specified") - population.add_chromosome(chromosome) - return population diff --git a/src/mutation/test_mutation.py b/src/initialization/test_examples.py similarity index 100% rename from src/mutation/test_mutation.py rename to src/initialization/test_examples.py diff --git a/src/mutation/__init__.py b/src/mutation/__init__.py index e69de29..c7e2fa1 100644 --- a/src/mutation/__init__.py +++ b/src/mutation/__init__.py @@ -0,0 +1,2 @@ +# FROM (. means local) file_name IMPORT function_name +from .examples import mutation_examples diff --git a/src/mutation/examples.py b/src/mutation/examples.py new file mode 100644 index 0000000..e97b9ff --- /dev/null +++ b/src/mutation/examples.py @@ -0,0 +1,3 @@ +class mutation_examples: + """Selection examples will go here """ + pass diff --git a/src/mutation/test_examples.py b/src/mutation/test_examples.py new file mode 100644 index 0000000..e69de29 diff --git a/src/selection/__init__.py b/src/selection/__init__.py index e69de29..b5f82e4 100644 --- a/src/selection/__init__.py +++ b/src/selection/__init__.py @@ -0,0 +1,2 @@ +# FROM (. means local) file_name IMPORT function_name +from .examples import selection_examples diff --git a/src/selection/examples.py b/src/selection/examples.py new file mode 100644 index 0000000..8920f7d --- /dev/null +++ b/src/selection/examples.py @@ -0,0 +1,3 @@ +class selection_examples: + """Selection examples will go here """ + pass diff --git a/src/selection/test_examples.py b/src/selection/test_examples.py new file mode 100644 index 0000000..e69de29 diff --git a/src/termination_point/__init__.py b/src/termination_point/__init__.py index acd51c7..55fe7e1 100644 --- a/src/termination_point/__init__.py +++ b/src/termination_point/__init__.py @@ -1,3 +1,2 @@ -# FROM (. means local) file_name IMPORT function_name -from .generation_based import generation_based -from .fitness_based import fitness_based +# FROM (. means local) file_name IMPORT class name +from .examples import termination_examples diff --git a/src/termination_point/examples.py b/src/termination_point/examples.py new file mode 100644 index 0000000..81d31f1 --- /dev/null +++ b/src/termination_point/examples.py @@ -0,0 +1,16 @@ +class termination_examples: + """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.goal_fitness): + 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.max_generations): + status = False + return status diff --git a/src/termination_point/fitness_based.py b/src/termination_point/fitness_based.py deleted file mode 100644 index a809130..0000000 --- a/src/termination_point/fitness_based.py +++ /dev/null @@ -1,5 +0,0 @@ -def fitness_based(ga): - status = True - if(ga.current_fitness > ga.goal_fitness): - status = False - return status diff --git a/src/termination_point/generation_based.py b/src/termination_point/generation_based.py deleted file mode 100644 index 11df411..0000000 --- a/src/termination_point/generation_based.py +++ /dev/null @@ -1,7 +0,0 @@ -def generation_based(ga): - """Generation based approach to termination - If the current generation is - less then the """ - status = True - if(ga.current_generation > ga.max_generations): - status = False - return status diff --git a/src/termination_point/test_examples.py b/src/termination_point/test_examples.py new file mode 100644 index 0000000..e69de29 From 42f49c43ee44324f06daa43d36dc094588171cf3 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Wed, 30 Sep 2020 23:39:14 -0400 Subject: [PATCH 36/40] Fixed names --- src/EasyGA.py | 14 ++++---------- src/termination_point/examples.py | 4 ++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index b920c82..912b550 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -1,12 +1,10 @@ import random - -# Import all the data prebuilt modules +# Import all the data structure prebuilt modules from initialization import population as create_population from initialization import chromosome as create_chromosome from initialization import gene as create_gene -# -from fitness_function import fitness_examples # Import example classes +from fitness_function import fitness_examples from initialization import initialization_examples from termination_point import termination_examples from selection import selection_examples @@ -24,13 +22,12 @@ class GA: self.population = None # Termination varibles self.current_generation = 0 - self.max_generations = 3 self.current_fitness = 0 - self.goal_fitness = 3 + self.generation_goal = 3 + self.fitness_goal = 3 # Mutation variables self.mutation_rate = 0.03 - # Defualt EastGA implimentation structure self.initialization_impl = initialization_examples.random_initialization self.fitness_funciton_impl = fitness_examples.is_it_5 @@ -39,9 +36,6 @@ class GA: #self.crossover_impl = FastSinglePointCrossover() self.termination_impl = termination_examples.generation_based - # If we want the fitnesses to be updated by the computer - self.update_fitness = True - def initialize_population(self): """Initialize the population using the initialization implimentation that is currently set""" diff --git a/src/termination_point/examples.py b/src/termination_point/examples.py index 81d31f1..823757a 100644 --- a/src/termination_point/examples.py +++ b/src/termination_point/examples.py @@ -4,13 +4,13 @@ class termination_examples: def fitness_based(ga): """Fitness based approach to terminate when the goal fitness has been reached""" status = True - if(ga.current_fitness > ga.goal_fitness): + 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.max_generations): + if(ga.current_generation > ga.generation_goal): status = False return status From 7ed6e55e4c5a85e42c5725f38009a5d182d0f116 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Thu, 1 Oct 2020 00:43:43 -0400 Subject: [PATCH 37/40] Implemented the always get fitness = True / False feature --- src/EasyGA.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index 912b550..f506545 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -28,6 +28,9 @@ class GA: # Mutation variables self.mutation_rate = 0.03 + # Rerun already computed fitness + self.update_fitness = False + # Defualt EastGA implimentation structure self.initialization_impl = initialization_examples.random_initialization self.fitness_funciton_impl = fitness_examples.is_it_5 @@ -46,11 +49,18 @@ class GA: self.gene_impl) def get_population_fitness(self,population): - """Will get and set the fitness of each chromosome in the population""" + """Will get and set the fitness of each chromosome in the population. + If update_fitness is set then all fitness values are updated. + Otherwise only fitness values set to None (i.e. uninitialized + fitness values) are updated.""" # Get each chromosome in the population for chromosome in population: - # Set the chromosomes fitness using the fitness function - chromosome.fitness = self.fitness_funciton_impl(chromosome) + # If the fitness is not set then get its fitness or if allways getting + # fitness is turn on then always get the fitness of the chromosome. + if(chromosome.fitness == None or self.update_fitness == True): + # Set the chromosomes fitness using the fitness function + chromosome.fitness = self.fitness_funciton_impl(chromosome) + def evolve(self): """Runs the ga until the termination point has been satisfied.""" @@ -58,7 +68,6 @@ class GA: while(self.active()): self.evolve_generation() - def active(self): """Returns if the ga should terminate base on the termination implimented""" # Send termination_impl the whole ga class @@ -66,10 +75,7 @@ class GA: def evolve_generation(self, number_of_generations = 1): - """Evolves the ga the specified number of generations. - If update_fitness is set then all fitness values are updated. - Otherwise only fitness values set to None (i.e. uninitialized - fitness values) are updated.""" + """Evolves the ga the specified number of generations.""" while(number_of_generations > 0): # If its the first generation then initialize the population if(self.current_generation == 0): @@ -77,14 +83,16 @@ class GA: self.initialize_population() # First get the fitness of the population self.get_population_fitness(self.population.chromosomes) - - #selecion -> crossover -> mutation + # Selection - Triggers flags in the chromosome if its been selected #self.selection_impl(self) + # Crossover - Takes the flagged chromosomes and crosses there genetic + # makup to make new offsprings. #self.crossover_impl(self) + # Repopulate - Manipulates the population to some desired way + #self.repopulate_impl(self) + # Mutation - Manipulates the population very slightly #self.mutation_impl(self) - #next_population.append(mutated_offspring) - # Counter for the local number of generations in evolve_generation number_of_generations -= 1 # Add one to the current overall generation From 002772c71fccba6fb087a6e9180d537d80345d9e Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Thu, 1 Oct 2020 01:22:53 -0400 Subject: [PATCH 38/40] Updated comments on crossover and selection --- src/crossover/examples.py | 16 ++++++++++++++-- src/selection/examples.py | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/crossover/examples.py b/src/crossover/examples.py index 25d91c8..5b64d81 100644 --- a/src/crossover/examples.py +++ b/src/crossover/examples.py @@ -1,3 +1,15 @@ class crossover_examples: - """Crossover examples will go here """ - pass + """ Crossover explination goes here. + + Points - Defined as sections between the chromosomes genetic makeup + """ + + 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""" + pass + + 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.""" + pass diff --git a/src/selection/examples.py b/src/selection/examples.py index 8920f7d..102fc5a 100644 --- a/src/selection/examples.py +++ b/src/selection/examples.py @@ -1,3 +1,14 @@ class selection_examples: - """Selection examples will go here """ - pass + """Selection defintion here""" + + def tournament_selection(): + """ """ + pass + + def roulette_selection(): + """Roulette selection works based off of how strong the fitness is of the + chromosomes in the population. The stronger the fitness the higher the probability + that it will be selected. Using the example of a casino roulette wheel. + Where the chromosomes are the numbers to be selected and the board size for + those numbers are directly proportional to the chromosome's current fitness.""" + pass From a62cdd4ce0629cec0a707dd3c47771b743713774 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Thu, 1 Oct 2020 01:29:05 -0400 Subject: [PATCH 39/40] Comments --- src/selection/examples.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/selection/examples.py b/src/selection/examples.py index 102fc5a..2c149a7 100644 --- a/src/selection/examples.py +++ b/src/selection/examples.py @@ -10,5 +10,6 @@ class selection_examples: chromosomes in the population. The stronger the fitness the higher the probability that it will be selected. Using the example of a casino roulette wheel. Where the chromosomes are the numbers to be selected and the board size for - those numbers are directly proportional to the chromosome's current fitness.""" + those numbers are directly proportional to the chromosome's current fitness. Where + the ball falls is a randomly generated number between 0 and 1""" pass From 80ebe8ca0c9d627272e99e69c7facb039bc118db Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Thu, 1 Oct 2020 01:33:34 -0400 Subject: [PATCH 40/40] Comments --- src/EasyGA.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index f506545..1ae5d60 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -84,14 +84,14 @@ class GA: # First get the fitness of the population self.get_population_fitness(self.population.chromosomes) # Selection - Triggers flags in the chromosome if its been selected - #self.selection_impl(self) + # self.selection_impl(self) # Crossover - Takes the flagged chromosomes and crosses there genetic # makup to make new offsprings. - #self.crossover_impl(self) + # self.crossover_impl(self) # Repopulate - Manipulates the population to some desired way - #self.repopulate_impl(self) + # self.repopulate_impl(self) # Mutation - Manipulates the population very slightly - #self.mutation_impl(self) + # self.mutation_impl(self) # Counter for the local number of generations in evolve_generation number_of_generations -= 1