1 | /* |
---|
2 | Copyright 2010 by Sean Luke and George Mason University |
---|
3 | Licensed under the Academic Free License version 3.0 |
---|
4 | See the file "LICENSE" for more information |
---|
5 | */ |
---|
6 | |
---|
7 | package ec.multiobjective.nsga2; |
---|
8 | |
---|
9 | import ec.*; |
---|
10 | import ec.util.*; |
---|
11 | import ec.simple.*; |
---|
12 | |
---|
13 | /* |
---|
14 | * NSGA2Breeder.java |
---|
15 | * |
---|
16 | * Created: Thu Feb 04 2010 |
---|
17 | * By: Faisal Abidi and Sean Luke |
---|
18 | */ |
---|
19 | |
---|
20 | /** |
---|
21 | * This SimpleBreeder subclass breeds a set of children from the Population, then |
---|
22 | * joins the original Population with the children in a (mu+mu) fashion. An NSGA2Breeder |
---|
23 | * may have multiple threads for breeding. |
---|
24 | * |
---|
25 | * <p>NSGA-II has fixed archive size (the population size), and so ignores the 'elites' |
---|
26 | * declaration. However it will adhere to the 'reevaluate-elites' parameter in SimpleBreeder |
---|
27 | * to determine whether to force fitness reevaluation. |
---|
28 | |
---|
29 | */ |
---|
30 | |
---|
31 | public class NSGA2Breeder extends SimpleBreeder |
---|
32 | { |
---|
33 | public void setup(final EvolutionState state, final Parameter base) |
---|
34 | { |
---|
35 | super.setup(state, base); |
---|
36 | // make sure SimpleBreeder's elites facility isn't being used |
---|
37 | for (int i = 0; i < elite.length; i++) |
---|
38 | if (elite[i] != 0) |
---|
39 | state.output.warning("Elites may not be used with NSGA2Breeder, and will be ignored."); |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * Override breedPopulation(). We take the result from the super method in |
---|
44 | * SimpleBreeder and append it to the old population. Hence, after |
---|
45 | * generation 0, every subsequent call to |
---|
46 | * <code>NSGA2Evaluator.evaluatePopulation()</code> will be passed a |
---|
47 | * population of 2x<code>originalPopSize</code> individuals. |
---|
48 | */ |
---|
49 | public Population breedPopulation(EvolutionState state) |
---|
50 | { |
---|
51 | Population oldPop = (Population) state.population; |
---|
52 | Population newPop = super.breedPopulation(state); |
---|
53 | Individual[] combinedInds; |
---|
54 | Subpopulation[] subpops = oldPop.subpops; |
---|
55 | Subpopulation oldSubpop; |
---|
56 | Subpopulation newSubpop; |
---|
57 | int subpopsLength = subpops.length; |
---|
58 | |
---|
59 | for (int i = 0; i < subpopsLength; i++) |
---|
60 | { |
---|
61 | oldSubpop = oldPop.subpops[i]; |
---|
62 | newSubpop = newPop.subpops[i]; |
---|
63 | combinedInds = new Individual[oldSubpop.individuals.length + newSubpop.individuals.length]; |
---|
64 | System.arraycopy(newSubpop.individuals, i, combinedInds, i, newSubpop.individuals.length); |
---|
65 | System.arraycopy(oldSubpop.individuals, i, combinedInds, newSubpop.individuals.length, oldSubpop.individuals.length); |
---|
66 | newSubpop.individuals = combinedInds; |
---|
67 | } |
---|
68 | return newPop; |
---|
69 | } |
---|
70 | } |
---|