Merge branch 'master' of https://github.com/danielwilczak101/EasyGA
This commit is contained in:
@ -10,11 +10,6 @@ from initialization.random_initialization import random_initialization
|
||||
|
||||
|
||||
class GA:
|
||||
|
||||
global population
|
||||
global chromosome
|
||||
global gene
|
||||
|
||||
def __init__(self):
|
||||
# Default variables
|
||||
self.population = None
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class population:
|
||||
|
||||
|
||||
# fitness = Empty; population = [chromosome, chromosome, etc.]
|
||||
def __init__(self, chromosomes = None):
|
||||
if chromosomes is None:
|
||||
@ -36,7 +36,8 @@ class population:
|
||||
self.fitness = fitness
|
||||
|
||||
def __repr__(self):
|
||||
pass
|
||||
for index in range(len(self.chromosomes)):
|
||||
return f'{self.chromosomes[index]}'
|
||||
|
||||
def print_all(self):
|
||||
# Ex .Current population
|
||||
|
||||
@ -1,19 +1,20 @@
|
||||
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()
|
||||
#Creating a gene with no fitness
|
||||
gene1 = ga.make_gene("Im a gene")
|
||||
gene2 = ga.make_gene("Im also a gene")
|
||||
#Creating a Chromosome with no genes
|
||||
chromosome = ga.make_chromosome()
|
||||
chromosome.add_gene(gene1)
|
||||
chromosome.add_gene(gene2)
|
||||
# Creating a populaiton
|
||||
populaiton = ga.make_population()
|
||||
populaiton.add_chromosome(chromosome)
|
||||
|
||||
# Creating population
|
||||
ga.initialize()
|
||||
|
||||
ga.population.print_all()
|
||||
print("")
|
||||
print(ga.population.chromosomes[0].__repr__())
|
||||
print(gene1)
|
||||
print(chromosome)
|
||||
print(populaiton)
|
||||
populaiton.print_all()
|
||||
|
||||
Reference in New Issue
Block a user