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

COVERAGE SUMMARY FOR SOURCE FILE [TacticOperatorsManager.java]

nameclass, %method, %block, %line, %
TacticOperatorsManager.java0%   (0/1)0%   (0/4)0%   (0/147)0%   (0/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TacticOperatorsManager0%   (0/1)0%   (0/4)0%   (0/147)0%   (0/31)
TacticOperatorsManager (Copy, DSEIndividualBuilder): void 0%   (0/1)0%   (0/39)0%   (0/8)
getAllCandidates (DSEIndividual): List 0%   (0/1)0%   (0/39)0%   (0/8)
getCandidate (DSEIndividual): DSEIndividual 0%   (0/1)0%   (0/66)0%   (0/14)
getHeuristics (): Collection 0%   (0/1)0%   (0/3)0%   (0/1)

1package de.uka.ipd.sdq.dsexplore.opt4j.optimizer.heuristic.operators;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.List;
6import java.util.Random;
7 
8import org.opt4j.core.problem.Genotype;
9import org.opt4j.operator.copy.Copy;
10 
11import de.uka.ipd.sdq.dsexplore.helper.ResultsWriter;
12import de.uka.ipd.sdq.dsexplore.launch.DSEWorkflowConfiguration;
13import de.uka.ipd.sdq.dsexplore.opt4j.representation.DSEIndividual;
14import de.uka.ipd.sdq.dsexplore.opt4j.representation.DSEIndividualBuilder;
15import de.uka.ipd.sdq.dsexplore.opt4j.start.Opt4JStarter;
16 
17/**
18 * 
19 * @author martens, beyer
20 *
21 */
22public class TacticOperatorsManager {
23 
24        
25        /**
26         * Heuristics to be used to generate candidates
27         */
28        protected Collection<ITactic> heuristics = new ArrayList<ITactic>();
29        protected ResultsWriter writer;
30        protected Random generator = new Random();
31        
32        /**
33         * @param copy Creates copy of genotypes
34         * @param individualBuilder Builds individual
35         */
36        public TacticOperatorsManager(Copy<Genotype> copy, DSEIndividualBuilder individualBuilder) {
37                DSEWorkflowConfiguration configuration = Opt4JStarter.getDSEWorkflowConfig();
38                heuristics = TacticOperatorsFactory.getActivatedInstances(copy, individualBuilder, configuration);
39                this.writer = new ResultsWriter(Opt4JStarter.getDSEWorkflowConfig().getResultFolder()+"heuristicsInfo");
40                writer.writeToLogFile("Tactic;Candidate numeric id;Parent numeric id;Candidate genome (several cols);Parent genome (several cols);Utilization value and whether returned\n");
41        }
42        
43        /**
44         * Applies registered heuristics to individual and returns candidates
45         * @param individual
46         * @return
47         */
48        public List<TacticsResultCandidate> getAllCandidates(DSEIndividual individual) {
49                
50                //results cache for the current candidate. 
51                UtilisationResultCacheAndHelper resultsCache = new UtilisationResultCacheAndHelper(); 
52                
53                
54                List<TacticsResultCandidate> result = new ArrayList<TacticsResultCandidate>();
55                Collection<TacticsResultCandidate> candidatesFromCurrentHeuristic;
56                for (ITactic heuristic : heuristics) {
57                        candidatesFromCurrentHeuristic = heuristic.getHeuristicCandidates(individual, resultsCache);
58                        if (candidatesFromCurrentHeuristic.size() > 0) {
59                                this.writer.writeTacticCandidateInfo(heuristic, candidatesFromCurrentHeuristic);
60                                result.addAll(candidatesFromCurrentHeuristic);
61                        }
62                }
63                return result;
64        }
65        
66        
67 
68        /**
69         * Applies registered heuristics to individual and returns random candidate
70         * based on candidate weight and heuristic weight. Returns null if no heuristic
71         * can be be applied.
72         * @param individual
73         * @return Random candidate from registered heuristic or null if no heuristic can be applied
74         */
75        public DSEIndividual getCandidate(DSEIndividual individual) {
76                Collection <TacticsResultCandidate> candidates = getAllCandidates(individual);
77                double sumOfAllWeights = 0;
78                for (TacticsResultCandidate c : candidates) {
79                        sumOfAllWeights += c.getFinalWeight();
80                }
81                
82                double threshold = generator.nextDouble()*sumOfAllWeights;
83                double currentLevel = 0;
84                for (TacticsResultCandidate c : candidates) {
85                        currentLevel += c.getFinalWeight();
86                        // use spectrum of candidate weights to select candidate. The larger the
87                        // weight of the candidate the higher the probability of being selected
88                        if (currentLevel >= threshold) {
89                                this.writer.writeTacticManagerChoice(c);
90                                return c;
91                        }
92                }
93                if (candidates.size() > 0) {
94                        throw new RuntimeException("Random selection failed.");
95                } 
96                // won't be executed unless candidates list is empty
97                else {
98                        return null;
99                }
100        }
101        
102        public Collection<ITactic> getHeuristics() {
103                return heuristics;
104        }
105        
106        
107}

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