pythonoptimizationgenetic-algorithmdeap

Solving a multi-objective optimization problem using python DEAP library with NSGA2


I want to solve a multi-objective optimization problem using DEAP library. Since i am new in DEAP, i used this example of NSGA-II as a template for my own problem. In the example, in line 59, tools.selNSGA2 function is registered to toolbox object, after that, is used as toolbox.select :

toolbox.register("select", tools.selNSGA2)

Then in the main function, in line 96, tools.selTournamentDCD function, is used to select offspring, however i couldn't figure out what does it do. Also i couldn't find anything about it in the paper which NSGA-II is proposed.

Following code is the main function of the example:

def main(seed=None):
    random.seed(seed)

    NGEN = 250
    MU = 100
    CXPB = 0.9

    pop = toolbox.population(n=MU)

    # Evaluate the individuals with an invalid fitness
    invalid_ind = [ind for ind in pop if not ind.fitness.valid]
    fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
    for ind, fit in zip(invalid_ind, fitnesses):
        ind.fitness.values = fit

    # This is just to assign the crowding distance to the individuals
    # no actual selection is done
    pop = toolbox.select(pop, len(pop))

    # Begin the generational process
    for gen in range(1, NGEN):
        # Vary the population
        offspring = tools.selTournamentDCD(pop, len(pop))
        offspring = [toolbox.clone(ind) for ind in offspring]

        for ind1, ind2 in zip(offspring[::2], offspring[1::2]):
            if random.random() <= CXPB:
                toolbox.mate(ind1, ind2)

            toolbox.mutate(ind1)
            toolbox.mutate(ind2)
            del ind1.fitness.values, ind2.fitness.values

        # Evaluate the individuals with an invalid fitness
        invalid_ind = [ind for ind in offspring if not ind.fitness.valid]
        fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
        for ind, fit in zip(invalid_ind, fitnesses):
            ind.fitness.values = fit

        # Select the next generation population
        pop = toolbox.select(pop + offspring, MU)

    return pop, logbook

MY QUESTIONS: Is tools.selTournamentDCD function a part of NSGA-II algorithm? Is it obligatory to use tools.selTournamentDCD to create offspring in DEAP? Can you please tell me when should i use this function and what does it do?

Thanks in advance


Solution

  • This is the paper where you can check details about NSGA-II (it's the one cited by DEAP) https://link.springer.com/chapter/10.1007/3-540-45356-3_83

    I am still new using this library, but I think you are not forced to use tools.selTournamentDCD

    I think you are able to use other selection or pre-selection operators like selRandom or selRoulette