source: framspy/evolalg/selection/nsga2.py @ 1148

Last change on this file since 1148 was 1148, checked in by Maciej Komosinski, 3 years ago

Added exception when popsize is not a multiple of 4 (required by deap.tools.selTournamentDCD())

File size: 746 bytes
RevLine 
[1147]1from evolalg.selection.selection import Selection
2from deap import tools
3import copy
4
5
6class NSGA2Selection(Selection):
7    def __init__(self, copy=False, *args, **kwargs):
8        super(NSGA2Selection, self).__init__(*args, **kwargs, copy=copy)
9
10    def call(self, population, count=None):
11        super(NSGA2Selection, self).call(population)
12        pop = tools.selNSGA2(population, len(population))
[1148]13        # make count divisible by 4, required by deap.tools.selTournamentDCD()
[1147]14        remainder=count % 4
15        if remainder > 0:
16            count += 4-remainder   
17        return copy.deepcopy(tools.selTournamentDCD(pop, count)) # "The individuals sequence length has to be a multiple of 4 only if k is equal to the length of individuals"
Note: See TracBrowser for help on using the repository browser.