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:
|
class GA:
|
||||||
|
|
||||||
global population
|
|
||||||
global chromosome
|
|
||||||
global gene
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Default variables
|
# Default variables
|
||||||
self.population = None
|
self.population = None
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
class population:
|
class population:
|
||||||
|
|
||||||
# fitness = Empty; population = [chromosome, chromosome, etc.]
|
# fitness = Empty; population = [chromosome, chromosome, etc.]
|
||||||
def __init__(self, chromosomes = None):
|
def __init__(self, chromosomes = None):
|
||||||
if chromosomes is None:
|
if chromosomes is None:
|
||||||
@ -36,7 +36,8 @@ class population:
|
|||||||
self.fitness = fitness
|
self.fitness = fitness
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
pass
|
for index in range(len(self.chromosomes)):
|
||||||
|
return f'{self.chromosomes[index]}'
|
||||||
|
|
||||||
def print_all(self):
|
def print_all(self):
|
||||||
# Ex .Current population
|
# Ex .Current population
|
||||||
|
|||||||
@ -1,19 +1,20 @@
|
|||||||
import random
|
|
||||||
import EasyGA
|
import EasyGA
|
||||||
|
|
||||||
# Create the Genetic algorithm
|
# Create the Genetic algorithm
|
||||||
ga = EasyGA.GA()
|
ga = EasyGA.GA()
|
||||||
|
|
||||||
# Makes a new gene
|
#Creating a gene with no fitness
|
||||||
new_gene = ga.make_gene("HelloWorld")
|
gene1 = ga.make_gene("Im a gene")
|
||||||
# Makes a chromosome to store genes in
|
gene2 = ga.make_gene("Im also a gene")
|
||||||
new_chromosome = ga.make_chromosome()
|
#Creating a Chromosome with no genes
|
||||||
# Makes a Population to store chromosomes in
|
chromosome = ga.make_chromosome()
|
||||||
new_population = ga.make_population()
|
chromosome.add_gene(gene1)
|
||||||
|
chromosome.add_gene(gene2)
|
||||||
|
# Creating a populaiton
|
||||||
|
populaiton = ga.make_population()
|
||||||
|
populaiton.add_chromosome(chromosome)
|
||||||
|
|
||||||
# Creating population
|
print(gene1)
|
||||||
ga.initialize()
|
print(chromosome)
|
||||||
|
print(populaiton)
|
||||||
ga.population.print_all()
|
populaiton.print_all()
|
||||||
print("")
|
|
||||||
print(ga.population.chromosomes[0].__repr__())
|
|
||||||
|
|||||||
Reference in New Issue
Block a user