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 [MinimalQualityCriteriaValueCriterion.java]

nameclass, %method, %block, %line, %
MinimalQualityCriteriaValueCriterion.java0%   (0/1)0%   (0/5)0%   (0/199)0%   (0/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MinimalQualityCriteriaValueCriterion0%   (0/1)0%   (0/5)0%   (0/199)0%   (0/34)
MinimalQualityCriteriaValueCriterion (IConfiguration, Population, Archive): void 0%   (0/1)0%   (0/35)0%   (0/8)
doesConformToMinimalValues (Individual): boolean 0%   (0/1)0%   (0/74)0%   (0/11)
evaluateImpl (int, long): void 0%   (0/1)0%   (0/38)0%   (0/8)
initializeOutputTree (): void 0%   (0/1)0%   (0/35)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.HashMap;
7import java.util.Map;
8 
9import org.opt4j.core.Archive;
10import org.opt4j.core.Individual;
11import org.opt4j.core.Objective;
12import org.opt4j.core.Objectives;
13import org.opt4j.core.Population;
14import org.opt4j.core.Value;
15import org.opt4j.core.Objective.Sign;
16 
17import de.uka.ipd.sdq.tcfmoop.config.IConfiguration;
18import de.uka.ipd.sdq.tcfmoop.config.MinimalQualityCriteriaValueConfig;
19import de.uka.ipd.sdq.tcfmoop.outputtree.Node;
20import de.uka.ipd.sdq.tcfmoop.outputtree.Node.NodeType;
21 
22/**
23 * @author Atanas Dimitrov
24 *
25 */
26public class MinimalQualityCriteriaValueCriterion extends
27                AbstractTerminationCriterion {
28        
29        //Already configured Objectives with their minimum required values.
30        private Map<Objective, Value<?>> configuredObjectives = new HashMap<Objective, Value<?>>();
31        //The required number of candidates to have quality criteria higher then the one supplied.
32        private int numberOfCandidatesToConform;
33        //The current number of candidates to have quality criteria higher then the one supplied.
34        private int currentlyConformingCandidates;
35        
36        //OutputNodes
37        //dynamic
38        private Node conformingCandidatesNode;
39 
40        public MinimalQualityCriteriaValueCriterion(IConfiguration conf, Population population,
41                        Archive archive) {
42                super(conf, population, archive);
43                if((conf instanceof MinimalQualityCriteriaValueConfig) && conf.validateConfiguration()){
44                        this.numberOfCandidatesToConform = ((MinimalQualityCriteriaValueConfig)(conf)).getNumberOfCandidatesToConform();
45                        this.configuredObjectives = ((MinimalQualityCriteriaValueConfig)(conf)).getObjectiveMinimalValues();
46                        
47                }else{
48                        throw new RuntimeException("MinimalQualityCriteriaValueCriterion.initialize: " +
49                        "wrong or invalid configuration object");
50                }
51                
52                this.initializeOutputTree();
53        }
54        
55        private void initializeOutputTree(){
56                this.outputInformation.updateValue("Minimal Quality Criteria Value");
57                this.outputInformation.getChildren().clear();
58                
59                this.conformingCandidatesNode = this.outputInformation.addChild("Conforming Candidates: " + this.currentlyConformingCandidates + "/" + this.numberOfCandidatesToConform, NodeType.PARAMETER);
60                this.outputInformation.getChildren().add(this.suggestedStop);
61        }
62        
63        /**
64         * {@inheritDoc}
65         * Implements the Minimal Quality Criteria Value Criterion: This criterion ensures that a subset of x pareto optimal
66         * candidates have quality criteria values higher than the previously supplied ones, before suggesting termination.
67         */
68        @Override
69        public void evaluateImpl(int iteration, long currentTime) {
70                
71                this.currentlyConformingCandidates = 0;
72                
73                for(Individual indi : this.archive){
74                        if(this.doesConformToMinimalValues(indi)){
75                                currentlyConformingCandidates++;
76                        }
77                }
78                
79                if(this.currentlyConformingCandidates >= this.numberOfCandidatesToConform){
80                        this.evaluationResult = true;
81                }else{
82                        this.evaluationResult = false;
83                }
84                
85        }
86        
87        /**
88         * Checks whether a specific individual conforms to the minimum quality criteria values set before.
89         * @param indi the Individual to be checked.
90         * @return true - if the candidate conforms, else - false.
91         */
92        private boolean doesConformToMinimalValues(Individual indi){
93                Objectives currentCandidatesObjectives = indi.getObjectives();
94                
95                if(!currentCandidatesObjectives.getKeys().containsAll(this.configuredObjectives.keySet())){
96                        throw new RuntimeException("MinimalQualityCriteriaValueCriterion.doesConformToMinimalValues: Individual does not contain all configured Objectives");
97                }
98                
99                for(Map.Entry<Objective, Value<?>> keyValuePair : this.configuredObjectives.entrySet()){
100                        if(keyValuePair.getKey().getSign() == Sign.MAX){
101                                if(!(currentCandidatesObjectives.get(keyValuePair.getKey()).getDouble() >= keyValuePair.getValue().getDouble())){
102                                        return false;
103                                }
104                        }else if(keyValuePair.getKey().getSign() == Sign.MIN){
105                                if(!(currentCandidatesObjectives.get(keyValuePair.getKey()).getDouble() <= keyValuePair.getValue().getDouble())){
106                                        return false;
107                                }
108                        }
109                }
110                return true;
111        }
112        
113        /**
114         * {@inheritDoc}
115         */
116        @Override
117        public void updateOutputInformation() {
118                this.conformingCandidatesNode.updateValue("Conforming Candidates: " + this.currentlyConformingCandidates + "/" + this.numberOfCandidatesToConform);
119        }
120 
121}

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