Added more structure methods and some quality of life changes
Overall cleaned up a lot of comments. EasyGA: - Code cleanup. Population: - Added sort_by_best_fitness - Added parent/mating pool methods. - Renamed some methods for consistency. Chromosome: - Added get_gene(index). Parent Selection: - Improved selection methods to use the ga.selection_probability so that the roulette selection actually works well. - Added stochastic selection. Survivor Selection: - Added fill_in_random and fill_in_parents_then_random. Crossover/Mutation: - Cleaned up code.
This commit is contained in:
@ -3,8 +3,15 @@ import EasyGA
|
||||
|
||||
# Create the Genetic algorithm
|
||||
ga = EasyGA.GA()
|
||||
ga.population_size = 100
|
||||
ga.generation_goal = 200
|
||||
ga.parent_selection_impl = EasyGA.Parent_Selection.Roulette.stochastic_selection
|
||||
ga.crossover_population_impl = EasyGA.Crossover_Methods.Population.sequential_selection
|
||||
ga.survivor_selection_impl = EasyGA.Survivor_Selection.fill_in_parents_then_random
|
||||
|
||||
ga.evolve()
|
||||
ga.set_all_fitness()
|
||||
ga.population.set_all_chromosomes(ga.sort_by_best_fitness(ga.population.get_all_chromosomes()))
|
||||
|
||||
print(f"Current Generation: {ga.current_generation}")
|
||||
ga.population.print_all()
|
||||
|
||||
Reference in New Issue
Block a user