-
Notifications
You must be signed in to change notification settings - Fork 404
/
NSGAIIWithArchive.java
87 lines (76 loc) · 2.32 KB
/
NSGAIIWithArchive.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
package org.uma.jmetal.algorithm.multiobjective.nsgaii;
import org.uma.jmetal.component.ranking.Ranking;
import org.uma.jmetal.component.ranking.impl.MergeNonDominatedSortRanking;
import org.uma.jmetal.component.termination.Termination;
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.archive.Archive;
import java.util.List;
/**
* Variant of NSGA-II using an external archive. The archive is updated with the evaluated solutions
* and a subset of the solution list it contains is returned as algorithm result.
*
* @author Antonio J. Nebro <antonio@lcc.uma.es>
*/
public class NSGAIIWithArchive<S extends Solution<?>> extends NSGAII<S> {
private Archive<S> archive;
/** Constructor */
public NSGAIIWithArchive(
Problem<S> problem,
int populationSize,
int offspringPopulationSize,
CrossoverOperator<S> crossoverOperator,
MutationOperator<S> mutationOperator,
Termination termination,
Ranking<S> ranking,
Archive<S> archive) {
super(
problem,
populationSize,
offspringPopulationSize,
crossoverOperator,
mutationOperator,
termination,
ranking);
this.archive = archive;
}
/** Constructor */
public NSGAIIWithArchive(
Problem<S> problem,
int populationSize,
int offspringPopulationSize,
CrossoverOperator<S> crossoverOperator,
MutationOperator<S> mutationOperator,
Termination termination,
Archive<S> archive) {
this(
problem,
populationSize,
offspringPopulationSize,
crossoverOperator,
mutationOperator,
termination,
new MergeNonDominatedSortRanking<>(),
archive);
}
@Override
protected List<S> evaluatePopulation(List<S> solutionList) {
List<S> evaluatedSolutionList = super.evaluatePopulation(solutionList);
for (S solution : evaluatedSolutionList) {
archive.add(solution);
}
return evaluatedSolutionList;
}
@Override
public List<S> getResult() {
return archive.getSolutionList() ;
}
public Archive<S> getArchive() {
return archive;
}
public List<S> getPopulation() {
return population ;
}
}