PyGAD - how to create solution which will return me list of 0 and 1

290 Views Asked by At

I'm experimenting with pygad. Have created initial population of lists of 0 and 1:

llist =  [[random.randint(0,1)  for _ in range(40)] for _ in range(10)]

my fitness functions does simple

sum(solution)

I'm trying to create model which will evolve list to contain only 1 i.e. [1,1,1,1.....1] as this is the best fitness for the population. However, results of the population are floats ranging from -2 to +15. Is there any way to restrict the solution values?

Is there any way to get solution to contain only list of 1 ?

1

There are 1 best solutions below

1
On

After looking into the documentation, it turns out that gen_type=int and gene_space=[0,1] does the trick!