source: framspy/evolalg/selection/ @ 1147

Last change on this file since 1147 was 1147, checked in by Maciej Komosinski, 14 months ago

Multi-criteria optimization, can optionally include diversity is one criterion

File size: 829 bytes
1from evolalg.selection.selection import Selection
2from deap import tools
3import copy
6class NSGA2Selection(Selection):
7    def __init__(self, copy=False, *args, **kwargs):
8        super(NSGA2Selection, self).__init__(*args, **kwargs, copy=copy)
10    def call(self, population, count=None):
11        super(NSGA2Selection, self).call(population)
12        pop = tools.selNSGA2(population, len(population))
13        # TODO make count divisible by 4, is this the best way to do it/is it absolutely required? if this is applied, why popsize must still be a multiple of 4?
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.