2

Here is my question.
I'm dealing with one optimization problem using DEAP.

For now, I use toolbox.register("select", tools.selNSGA2) to select some fittest indivual to survive.

But I want to add some threshold by user-defined function.

Can the algorithm achieve two step of selection?

  1. Select several individuals by the tournament or selNSGA2 method

  2. Eliminate several individuals by pre-defined thresholds.

Community
  • 1
  • 1
Han Zhengzu
  • 3,694
  • 7
  • 44
  • 94

1 Answers1

1

This should work.

def myselect(pop, k, check):
    return [ind for in in tools.selNSGA2(pop, k) if check(ind)]

def mycheck(ind):
    return True

toolbox.register("select", myselect, check=mycheck)

However, you will end up selecting <= k offspring.

Ohjeah
  • 1,269
  • 18
  • 24