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

COVERAGE SUMMARY FOR SOURCE FILE [PopulationTracker.java]

nameclass, %method, %block, %line, %
PopulationTracker.java0%   (0/1)0%   (0/9)0%   (0/90)0%   (0/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PopulationTracker0%   (0/1)0%   (0/9)0%   (0/90)0%   (0/24)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/3)
PopulationTracker (Population): void 0%   (0/1)0%   (0/11)0%   (0/4)
addIndividualsManually (DSEIndividual): boolean 0%   (0/1)0%   (0/15)0%   (0/3)
getIndividualForPhenotype (PCMPhenotype): DSEIndividual 0%   (0/1)0%   (0/23)0%   (0/4)
getIndividuals (): List 0%   (0/1)0%   (0/3)0%   (0/1)
getParetoOptimalIndividuals (): List 0%   (0/1)0%   (0/15)0%   (0/3)
individualAdded (IndividualCollection, Individual): void 0%   (0/1)0%   (0/14)0%   (0/4)
individualRemoved (IndividualCollection, Individual): void 0%   (0/1)0%   (0/1)0%   (0/1)
size (): int 0%   (0/1)0%   (0/4)0%   (0/1)

1package de.uka.ipd.sdq.dsexplore.opt4j.archive;
2 
3import java.util.ArrayList;
4import java.util.LinkedList;
5import java.util.List;
6 
7import org.apache.log4j.Logger;
8import org.opt4j.config.Task;
9import org.opt4j.core.Individual;
10import org.opt4j.core.IndividualCollection;
11import org.opt4j.core.IndividualCollectionListener;
12import org.opt4j.core.Population;
13 
14import com.google.inject.Inject;
15 
16import de.uka.ipd.sdq.dsexplore.analysis.PCMPhenotype;
17import de.uka.ipd.sdq.dsexplore.helper.FilterParetoOptimalIndividuals;
18import de.uka.ipd.sdq.dsexplore.opt4j.representation.DSEIndividual;
19 
20 
21/**
22 * Stores all individuals ever added to the tracked population
23 * 
24 * This is an {@link IndividualCollectionListener} that listens on the 
25 * {@link Population} instance from the Opt4J {@link Task}.
26 * 
27 * Additionally, a set Pareto-optimal candidates is maintained that can be retrieved 
28 * by {@link PopulationTracker#getParetoOptimalIndividuals()}. 
29 * 
30 * @author Anne
31 *
32 */
33public class PopulationTracker implements
34                IndividualCollectionListener {
35        
36        private List<DSEIndividual> individuals = new LinkedList<DSEIndividual>();
37 
38        /** Logger for log4j. */
39        private static Logger logger = 
40                Logger.getLogger("de.uka.ipd.sdq.dsexplore.opt4j.archive.DSEListener");
41 
42        
43        @Inject
44        public PopulationTracker(Population population){
45                super();
46                population.addListener(this);
47        }
48 
49        @Override
50        public void individualAdded(IndividualCollection collection,
51                        Individual individual) {
52                
53                if (individual instanceof DSEIndividual){
54                        //This itselfs stores all
55                        this.individuals.add((DSEIndividual)individual);
56                } else {
57                        logger.error("It has been attempted to add an individual that is not a DSEIndividual to the archive. Fix your implementation.");
58                }
59        }
60 
61        public List<DSEIndividual> getIndividuals(){
62                return this.individuals;
63        }
64 
65        @Override
66        public void individualRemoved(IndividualCollection collection,
67                        Individual individual) {
68                // do nothing
69 
70        }
71        
72        /**
73         * Careful: This can 20 minutes to calculate if you have over 1000 candidates in the {@link PopulationTracker}.
74         * @return
75         */
76        public List<DSEIndividual> getParetoOptimalIndividuals(){
77                
78                List<DSEIndividual> optimalList = new ArrayList<DSEIndividual>(this.individuals.size());
79                
80                optimalList.addAll(this.individuals);
81                
82                return FilterParetoOptimalIndividuals.filterPareto(optimalList);
83        }
84        
85        /**
86         * Returns the individual for the given phenotype or null if none can be found.
87         * @param pheno
88         * @return the individual or null
89         */
90        public DSEIndividual getIndividualForPhenotype(PCMPhenotype pheno){
91                for (DSEIndividual i : this.individuals) {
92                        if (i.getPhenotype() != null && i.getPhenotype() == pheno){
93                                return i;
94                        }
95                }
96                return null;
97        }
98 
99        public int size() {
100                return this.individuals.size();
101        }
102        
103        /**
104         * Has to be an evaluated individual.
105         * @param individual
106         * @throws RuntimeException if the individual is null or not yet evaluated (i.e. individual.isEvaluated returns false). 
107         */
108        public boolean addIndividualsManually(DSEIndividual individual){
109                if (individual != null && individual.isEvaluated()){
110                        return this.individuals.add(individual);
111                } else {
112                        throw new RuntimeException("Only evaluated candidates may be added to PopulationTracker!");
113                }
114        }
115 
116}

[all classes][de.uka.ipd.sdq.dsexplore.opt4j.archive]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov