-
Notifications
You must be signed in to change notification settings - Fork 404
/
NSGAII.java
116 lines (102 loc) · 3.96 KB
/
NSGAII.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package org.uma.jmetal.algorithm.multiobjective.nsgaii;
import org.uma.jmetal.algorithm.ComponentBasedEvolutionaryAlgorithm;
import org.uma.jmetal.component.densityestimator.DensityEstimator;
import org.uma.jmetal.component.densityestimator.impl.CrowdingDistanceDensityEstimator;
import org.uma.jmetal.component.evaluation.Evaluation;
import org.uma.jmetal.component.evaluation.impl.SequentialEvaluation;
import org.uma.jmetal.component.initialsolutioncreation.InitialSolutionsCreation;
import org.uma.jmetal.component.initialsolutioncreation.impl.RandomSolutionsCreation;
import org.uma.jmetal.component.ranking.Ranking;
import org.uma.jmetal.component.ranking.impl.FastNonDominatedSortRanking;
import org.uma.jmetal.component.replacement.Replacement;
import org.uma.jmetal.component.replacement.impl.RankingAndDensityEstimatorReplacement;
import org.uma.jmetal.component.selection.MatingPoolSelection;
import org.uma.jmetal.component.selection.impl.NaryTournamentMatingPoolSelection;
import org.uma.jmetal.component.termination.Termination;
import org.uma.jmetal.component.variation.impl.CrossoverAndMutationVariation;
import org.uma.jmetal.operator.crossover.CrossoverOperator;
import org.uma.jmetal.operator.mutation.MutationOperator;
import org.uma.jmetal.problem.Problem;
import org.uma.jmetal.solution.Solution;
import org.uma.jmetal.util.comparator.MultiComparator;
import org.uma.jmetal.util.observable.impl.DefaultObservable;
import java.util.Arrays;
import java.util.HashMap;
/** @author Antonio J. Nebro <antonio@lcc.uma.es> */
public class NSGAII<S extends Solution<?>> extends ComponentBasedEvolutionaryAlgorithm<S> {
/**
* Constructor
*
* @param evaluation
* @param initialPopulationCreation
* @param termination
* @param selection
* @param variation
* @param replacement
*/
public NSGAII(
Evaluation<S> evaluation,
InitialSolutionsCreation<S> initialPopulationCreation,
Termination termination,
MatingPoolSelection<S> selection,
CrossoverAndMutationVariation<S> variation,
RankingAndDensityEstimatorReplacement<S> replacement) {
super(
"NSGA-II",
evaluation,
initialPopulationCreation,
termination,
selection,
variation,
replacement);
}
/** Constructor */
public NSGAII(
Problem<S> problem,
int populationSize,
int offspringPopulationSize,
CrossoverOperator<S> crossoverOperator,
MutationOperator<S> mutationOperator,
Termination termination,
Ranking<S> ranking) {
this.name = "NSGA-II";
this.problem = problem;
this.observable = new DefaultObservable<>(name);
this.attributes = new HashMap<>();
DensityEstimator<S> densityEstimator = new CrowdingDistanceDensityEstimator<>();
this.createInitialPopulation = new RandomSolutionsCreation<>(problem, populationSize);
this.replacement =
new RankingAndDensityEstimatorReplacement<>(
ranking, densityEstimator, Replacement.RemovalPolicy.oneShot);
this.variation =
new CrossoverAndMutationVariation<>(
offspringPopulationSize, crossoverOperator, mutationOperator);
this.selection =
new NaryTournamentMatingPoolSelection<>(
2,
variation.getMatingPoolSize(),
new MultiComparator<>(
Arrays.asList(
ranking.getSolutionComparator(), densityEstimator.getSolutionComparator())));
this.termination = termination;
this.evaluation = new SequentialEvaluation<>(problem);
this.archive = null;
}
/** Constructor */
public NSGAII(
Problem<S> problem,
int populationSize,
int offspringPopulationSize,
CrossoverOperator<S> crossoverOperator,
MutationOperator<S> mutationOperator,
Termination termination) {
this(
problem,
populationSize,
offspringPopulationSize,
crossoverOperator,
mutationOperator,
termination,
new FastNonDominatedSortRanking<>());
}
}