Skip to content

How to get multiple best solutions in a generation? #304

Open
@JimmyChine

Description

@JimmyChine

Hi All,

I am a new on in PyGAD, and now I am using PyGAD to implement my multiple objective optimization problem. In your example, I learned how to the funcion on_generation() to get one best fitness of each generation:

def on_generation(ga_instance):
global last_fitness
print("Generation = {generation}".format(generation=ga_instance.generations_completed))
print("Fitness = {fitness}".format(fitness=ga_instance.best_solution(pop_fitness=ga_instance.last_generation_fitness)[1]))
print("Change = {change}".format(change=ga_instance.best_solution(pop_fitness=ga_instance.last_generation_fitness)[1] - last_fitness))
solution, solution_fitness, solution_idx = ga_instance.best_solution(pop_fitness=ga_instance.last_generation_fitness)

My question is that: can I get multiple best solutions (for example, I want to get best three solutions) in PyGAD?

Any suggestions would be greatly appreciated. Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions