GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

How to create a custom population?

Open pritam-dey3 opened this issue 3 years ago • 1 comments

I want to create a custom population with each chromosome/solution will be a pandas DataFrame. How should I create initial_population values and what should be assigned to gene_type attribute?

pritam-dey3 avatar May 12 '22 11:05 pritam-dey3

This is an example.

import pygad
import numpy

def fitness_func(ga_instanse, solution, solution_idx):
    return numpy.sum(solution)

ga_instance = pygad.GA(num_generations=5,
                       num_parents_mating=2,
                       initial_population=[[1,2], 
                                           [5,7]],
                       gene_type=[int, float],
                       fitness_func=fitness_func)

ga_instance.run()

ahmedfgad avatar Feb 26 '23 18:02 ahmedfgad