Implemented basic functionality for using different target fitness types

This commit is contained in:
SimpleArt
2020-10-21 14:11:43 -04:00
parent 9101072f26
commit 8e2698fc0d
5 changed files with 45 additions and 17 deletions

View File

@ -3,10 +3,22 @@ import EasyGA
# Create the Genetic algorithm
ga = EasyGA.GA()
ga.target_fitness_type = 'min'
ga.chromosome_length = 10
ga.population_size = 25
ga.generation_goal = 50
ga.gene_impl = lambda: random.randint(0, 10)
ga.chromosome_length = 100
def fitness_function(chromosome):
return sum(
gene.get_value()
for gene in chromosome.get_gene_list())
ga.fitness_function_impl = fitness_function
ga.evolve()
ga.set_all_fitness()
ga.population.sort_by_best_fitness(ga)
print(f"Current Generation: {ga.current_generation}")
ga.population.print_all()