Skip to content

The genes are always integers even if the gene_space attribute has float values. #27

Closed
@ahmedfgad

Description

@ahmedfgad

In the next code, the initial_population parameter is used to feed an initial population that has 8 solutions with 2 genes each. The gene_space parameter is used which has the half values starting from 0.5 to 15.5.

When the mutation is applied, it is expected that some genes have floating-point values like 3.5, 6.5, 0.5, 2.5, etc. But all genes are integers.

import pygad
import numpy

init_pop = ((1, 1), (3, 3), (5, 5), (7, 7), (9, 9), (11, 11), (13, 13), (15, 15))

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

gene_space = numpy.arange(0.5, 15.5, 1)

ga_instance = pygad.GA(initial_population=init_pop,
                       num_generations=4,
                       num_parents_mating=8,
                       fitness_func=fitness_func,
                       gene_space=gene_space)

ga_instance.run()

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions