EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.tcfmoop.terminationcriteria]

COVERAGE SUMMARY FOR SOURCE FILE [InsignificantParetoFrontChangeCriterion.java]

nameclass, %method, %block, %line, %
InsignificantParetoFrontChangeCriterion.java0%   (0/1)0%   (0/7)0%   (0/231)0%   (0/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InsignificantParetoFrontChangeCriterion0%   (0/1)0%   (0/7)0%   (0/231)0%   (0/46)
InsignificantParetoFrontChangeCriterion (IConfiguration, Population, Archive)... 0%   (0/1)0%   (0/35)0%   (0/8)
calcuteDifference (Collection, Collection): double 0%   (0/1)0%   (0/48)0%   (0/12)
clearOutDatedParetoFronts (): void 0%   (0/1)0%   (0/14)0%   (0/3)
evaluateImpl (int, long): void 0%   (0/1)0%   (0/40)0%   (0/10)
initializeOutputTree (): void 0%   (0/1)0%   (0/51)0%   (0/6)
memorizeCurrentParetoFront (): void 0%   (0/1)0%   (0/26)0%   (0/5)
updateOutputInformation (): void 0%   (0/1)0%   (0/17)0%   (0/2)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.tcfmoop.terminationcriteria;
5 
6import java.util.Collection;
7import java.util.LinkedList;
8 
9import org.opt4j.core.Archive;
10import org.opt4j.core.Individual;
11import org.opt4j.core.Objectives;
12import org.opt4j.core.Population;
13 
14import de.uka.ipd.sdq.tcfmoop.config.IConfiguration;
15import de.uka.ipd.sdq.tcfmoop.config.InsignificantParetoFrontChangeConfig;
16import de.uka.ipd.sdq.tcfmoop.outputtree.Node;
17import de.uka.ipd.sdq.tcfmoop.outputtree.Node.NodeType;
18 
19/**
20 * @author Atanas Dimitrov
21 *
22 */
23public class InsignificantParetoFrontChangeCriterion extends
24                AbstractTerminationCriterion {
25 
26        //The minimum significant difference. Everything below this is considered insignificant
27        private double requiredPercentageDifference;
28        //The current difference between the two fronts
29        private double currentPercentageDifference;
30        //The x in the n-x. iteration. Gives information about the generation of the second front
31        private int pastInterationNumber;
32        //An archive of the last x pareto fronts
33        private LinkedList<LinkedList<Objectives>> paretoFrontMemory = new LinkedList<LinkedList<Objectives>>();
34        
35        //OutputNodes
36        //static
37        @SuppressWarnings("unused")
38        private Node generationToCompareWithNode;
39        //dynamic
40        private Node currentDifferenceNode;
41        
42        public InsignificantParetoFrontChangeCriterion(IConfiguration conf, Population population,
43                        Archive archive) {
44                super(conf, population, archive);
45                if((conf instanceof InsignificantParetoFrontChangeConfig) && conf.validateConfiguration()){
46                        this.requiredPercentageDifference = ((InsignificantParetoFrontChangeConfig)(conf)).getMinimumAllowedDifference();
47                        this.pastInterationNumber = ((InsignificantParetoFrontChangeConfig)(conf)).getPastIterationNumber();
48                        
49                }else{
50                        throw new RuntimeException("InsignificantParetoFrontChangeCriterion.initialize: " +
51                        "wrong or invalid configuration object");
52                }
53                initializeOutputTree();
54        }
55        
56        private void initializeOutputTree(){
57                this.outputInformation.updateValue("Insignificant Pareto Front Change");
58                this.outputInformation.getChildren().clear();
59                
60                this.generationToCompareWithNode = this.outputInformation.addChild("Current Generation is compared with: " + this.pastInterationNumber + " generation ago", NodeType.PARAMETER);
61                this.currentDifferenceNode = this.outputInformation.addChild("Current Difference: " + this.currentPercentageDifference + "/" + this.requiredPercentageDifference, NodeType.PARAMETER);
62                this.outputInformation.getChildren().add(this.suggestedStop);
63        }
64        
65        /**
66         * {@inheritDoc}
67         * Implements the Insignificant Pareto Front Change Criterion: This criterion compares the pareto front from the 
68         * n. iteration with the pareto front from the n-x. iteration and calculates the difference between the two.
69         * If this difference is below the supplied minimum, it is reported that the optimization should stop.
70         */
71        @Override
72        public void evaluateImpl(int iteration, long currentTime) {
73                
74                this.memorizeCurrentParetoFront();
75                this.clearOutDatedParetoFronts();
76                
77                if(this.paretoFrontMemory.size() <= this.pastInterationNumber){
78                        this.evaluationResult = false;
79                        return;
80                }
81                
82                this.currentPercentageDifference = this.calcuteDifference(this.paretoFrontMemory.getFirst(), this.paretoFrontMemory.getLast());
83                
84                if(this.currentPercentageDifference < this.requiredPercentageDifference){
85                        this.evaluationResult = true;
86                }else{
87                        this.evaluationResult = false;
88                }
89                
90        }
91        
92        /**
93         * Copies the current pareto front to a local archive.
94         */
95        private void memorizeCurrentParetoFront(){
96                LinkedList<Objectives> newFront = new LinkedList<Objectives>();
97                for(Individual indi : this.archive){
98                        newFront.add(indi.getObjectives());
99                }
100                this.paretoFrontMemory.addFirst(newFront);
101        }
102        
103        /**
104         * Clear every pareto front that lies beyond the n-x. one.
105         */
106        private void clearOutDatedParetoFronts(){
107                while(this.paretoFrontMemory.size() > this.pastInterationNumber + 1){
108                        this.paretoFrontMemory.removeLast();
109                }
110        }
111        
112        /**
113         * Calculate the difference between the two pareto fronts by measuring the the coverage between them
114         * @param newFront pareto front of a latest iteration
115         * @param oldFront pareto front of an earlier iteration
116         * @return the calculated pareto front difference. A percentage value in the interval [0, 1].
117         */
118        private double calcuteDifference(Collection<Objectives> newFront, Collection<Objectives> oldFront){
119                int numberOfDominatedIndividualsInCoveredFront = 0;
120                int numberOfIndividualsInCoveredFront = oldFront.size();
121                
122                for(Objectives indiToBeDominated : oldFront){
123                        for(Objectives coveringIndi : newFront){
124                                if(coveringIndi.dominates(indiToBeDominated)){
125                                        numberOfDominatedIndividualsInCoveredFront++;
126                                        break;
127                                }
128                        }
129                }
130                
131                if(numberOfIndividualsInCoveredFront == 0){
132                        if(newFront.size() == 0){
133                                return 0;
134                        }else{
135                                return 1;
136                        }
137                }else{
138                        return (double)numberOfDominatedIndividualsInCoveredFront/numberOfIndividualsInCoveredFront;
139                }
140        }
141        
142        /**
143         * {@inheritDoc}
144         */
145        @Override
146        public void updateOutputInformation() {
147                this.currentDifferenceNode.updateValue("Current Difference: " + this.currentPercentageDifference + "/" + this.requiredPercentageDifference);
148        }
149 
150}

[all classes][de.uka.ipd.sdq.tcfmoop.terminationcriteria]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov