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