Testing
This commit is contained in:
16
src/initialization/focused_initialization.py
Normal file
16
src/initialization/focused_initialization.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# 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
|
||||||
@ -1,20 +1,16 @@
|
|||||||
import EasyGA
|
import EasyGA
|
||||||
|
import random
|
||||||
|
|
||||||
# Create the Genetic algorithm
|
# Create the Genetic algorithm
|
||||||
ga = EasyGA.GA()
|
ga = EasyGA.GA()
|
||||||
|
|
||||||
#Creating a gene with no fitness
|
def user_defined_gene():
|
||||||
gene1 = ga.make_gene("Im a gene")
|
return random.choice(["left","right","up","down"])
|
||||||
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)
|
|
||||||
|
|
||||||
print(gene1)
|
ga.gene_function_impl = user_defined_gene
|
||||||
print(chromosome)
|
|
||||||
print(populaiton)
|
# Creating population
|
||||||
populaiton.print_all()
|
ga.initialize()
|
||||||
|
|
||||||
|
# Print the current population
|
||||||
|
ga.population.print_all()
|
||||||
|
|||||||
Reference in New Issue
Block a user