Last change
on this file since 1147 was
1147,
checked in by Maciej Komosinski, 3 years ago
|
Multi-criteria optimization, can optionally include diversity is one criterion
|
File size:
829 bytes
|
Rev | Line | |
---|
[1147] | 1 | from evolalg.selection.selection import Selection |
---|
| 2 | from deap import tools |
---|
| 3 | import copy |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | class 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)) |
---|
| 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.