1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.tcfmoop.terminationcriteria; |
5 | |
6 | import java.util.LinkedList; |
7 | import java.util.List; |
8 | |
9 | import org.opt4j.core.Archive; |
10 | import org.opt4j.core.Individual; |
11 | import org.opt4j.core.Population; |
12 | |
13 | import de.uka.ipd.sdq.tcfmoop.config.IConfiguration; |
14 | import de.uka.ipd.sdq.tcfmoop.config.NoNewParetoOptimalCandidatesFoundConfig; |
15 | import de.uka.ipd.sdq.tcfmoop.outputtree.Node; |
16 | import de.uka.ipd.sdq.tcfmoop.outputtree.Node.NodeType; |
17 | |
18 | /** |
19 | * @author Atanas Dimitrov |
20 | * |
21 | */ |
22 | public class NoNewParetoOptimalCandidatesFoundCriterion extends |
23 | AbstractTerminationCriterion { |
24 | |
25 | //Denotes whether new pareto optimal candidates were found in the last iteration. |
26 | private boolean newParetoCandidatesFound = false; |
27 | //Required and current number of iterations without a newly found pareto optimal candidate. |
28 | private int requiredIterationsWithoutNewParetoOptimalCandidate; |
29 | private int currentIterationsWithoutNewParetoOptimalCandidate = 0; |
30 | //Local Archive of the already found pareto optimal candidates. |
31 | private List<Individual> localArchive = new LinkedList<Individual>(); |
32 | |
33 | //OutputNodes |
34 | //dynamic |
35 | private Node generationsWithoutNewCandidate; |
36 | |
37 | public NoNewParetoOptimalCandidatesFoundCriterion(IConfiguration conf, Population population, |
38 | Archive archive) { |
39 | super(conf, population, archive); |
40 | if((conf instanceof NoNewParetoOptimalCandidatesFoundConfig) && conf.validateConfiguration()){ |
41 | this.requiredIterationsWithoutNewParetoOptimalCandidate = ((NoNewParetoOptimalCandidatesFoundConfig)(conf)).getIterationsWithoutNewCandidates(); |
42 | }else{ |
43 | throw new RuntimeException("NoNewParetoOptimalCandidatesFoundCriterion.initialize: " + |
44 | "wrong or invalid configuration object"); |
45 | } |
46 | initializeOutputTree(); |
47 | } |
48 | |
49 | private void initializeOutputTree(){ |
50 | this.outputInformation.updateValue("No New Pareto Optimal Candidates Found"); |
51 | this.outputInformation.getChildren().clear(); |
52 | |
53 | this.generationsWithoutNewCandidate = this.outputInformation.addChild("No new pareto optimal candidate for: " + this.currentIterationsWithoutNewParetoOptimalCandidate + |
54 | "/" + this.requiredIterationsWithoutNewParetoOptimalCandidate + " generations", NodeType.PARAMETER); |
55 | this.outputInformation.getChildren().add(this.suggestedStop); |
56 | } |
57 | |
58 | /** |
59 | * {@inheritDoc} |
60 | * Implements the No New Pareto Optimal Candidates Found Criterion: This criterion tests the pareto optimal set |
61 | * for new found pareto optimal candidates. If no new pareto optimal candidates are found within n iterations |
62 | * it suggests a termination of the optimization. |
63 | */ |
64 | @Override |
65 | public void evaluateImpl(int iteration, long currentTime) { |
66 | this.newParetoCandidatesFound = false; |
67 | |
68 | for(Individual indi : archive){ |
69 | if(!localArchive.contains(indi)){ |
70 | this.newParetoCandidatesFound = true; |
71 | localArchive.add(indi); |
72 | } |
73 | } |
74 | |
75 | //Clean the local archive |
76 | |
77 | List<Individual> individualsToRemove = new LinkedList<Individual>(); |
78 | |
79 | for(Individual indi: this.localArchive){ |
80 | if(!archive.contains(indi)){ |
81 | individualsToRemove.add(indi); |
82 | } |
83 | } |
84 | |
85 | this.localArchive.removeAll(individualsToRemove); |
86 | |
87 | if(!this.newParetoCandidatesFound){ |
88 | this.currentIterationsWithoutNewParetoOptimalCandidate++; |
89 | }else{ |
90 | this.currentIterationsWithoutNewParetoOptimalCandidate = 0; |
91 | } |
92 | |
93 | if(this.currentIterationsWithoutNewParetoOptimalCandidate == this.requiredIterationsWithoutNewParetoOptimalCandidate){ |
94 | this.evaluationResult = true; |
95 | }else{ |
96 | this.evaluationResult = false; |
97 | } |
98 | |
99 | } |
100 | |
101 | /** |
102 | * {@inheritDoc} |
103 | */ |
104 | @Override |
105 | public void updateOutputInformation() { |
106 | this.generationsWithoutNewCandidate.updateValue("No new pareto optimal candidate for: " + this.currentIterationsWithoutNewParetoOptimalCandidate + |
107 | "/" + this.requiredIterationsWithoutNewParetoOptimalCandidate + " generations"); |
108 | } |
109 | |
110 | } |