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

COVERAGE SUMMARY FOR SOURCE FILE [DSECreator.java]

nameclass, %method, %block, %line, %
DSECreator.java0%   (0/1)0%   (0/9)0%   (0/283)0%   (0/63)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DSECreator0%   (0/1)0%   (0/9)0%   (0/283)0%   (0/63)
DSECreator (): void 0%   (0/1)0%   (0/17)0%   (0/5)
create (): DesignDecisionGenotype 0%   (0/1)0%   (0/51)0%   (0/9)
createDoubleValue (ContinuousRangeDegree): double 0%   (0/1)0%   (0/35)0%   (0/8)
createIntegerValue (DiscreteDegree): int 0%   (0/1)0%   (0/65)0%   (0/12)
createRandomChoice (DegreeOfFreedomInstance): Choice 0%   (0/1)0%   (0/80)0%   (0/20)
createRandomEntity (ClassDegree): EObject 0%   (0/1)0%   (0/14)0%   (0/3)
createRandomSchedulingPolicy (SchedulingPolicyDegree): SchedulingPolicy 0%   (0/1)0%   (0/14)0%   (0/3)
getNumberOfNotEvaluatedPredefinedOnes (): int 0%   (0/1)0%   (0/3)0%   (0/1)
setNumberOfNotEvaluatedPredefinedOnes (int): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package de.uka.ipd.sdq.dsexplore.opt4j.representation;
2 
3import java.util.List;
4import java.util.Random;
5 
6import org.eclipse.emf.ecore.EObject;
7import org.opt4j.core.problem.Creator;
8 
9import com.google.inject.Inject;
10 
11import de.uka.ipd.sdq.dsexplore.opt4j.genotype.DesignDecisionGenotype;
12import de.uka.ipd.sdq.dsexplore.opt4j.start.Opt4JStarter;
13import de.uka.ipd.sdq.pcm.core.entity.Entity;
14import de.uka.ipd.sdq.pcm.designdecision.Choice;
15import de.uka.ipd.sdq.pcm.designdecision.ContinousRangeChoice;
16import de.uka.ipd.sdq.pcm.designdecision.ContinuousRangeDegree;
17import de.uka.ipd.sdq.pcm.designdecision.DegreeOfFreedomInstance;
18import de.uka.ipd.sdq.pcm.designdecision.DiscreteDegree;
19import de.uka.ipd.sdq.pcm.designdecision.DiscreteRangeChoice;
20import de.uka.ipd.sdq.pcm.designdecision.DiscreteRangeDegree;
21import de.uka.ipd.sdq.pcm.designdecision.ClassChoice;
22import de.uka.ipd.sdq.pcm.designdecision.ClassDegree;
23import de.uka.ipd.sdq.pcm.designdecision.OrderedIntegerDegree;
24import de.uka.ipd.sdq.pcm.designdecision.SchedulingPolicyChoice;
25import de.uka.ipd.sdq.pcm.designdecision.SchedulingPolicyDegree;
26import de.uka.ipd.sdq.pcm.designdecision.designdecisionFactory;
27import de.uka.ipd.sdq.pcm.designdecision.impl.designdecisionFactoryImpl;
28import de.uka.ipd.sdq.pcm.resourceenvironment.SchedulingPolicy;
29 
30/**
31 * The {@link DSECreator} is responsible for randomly creating genotypes 
32 * in the solution space. It can query the {@link DSEProblem} for the 
33 * available design space.
34 *  
35 * @author Anne
36 *
37 */
38public class DSECreator implements Creator<DesignDecisionGenotype> {
39 
40        private DSEProblem problem;
41        private Random random;
42        
43        private int numberOfNotEvaluatedPredefinedOnes;
44 
45        @Inject
46        public DSECreator(){
47                //XXX like this you can only set the problem once. Maybe dont save the reference. 
48                this.problem = Opt4JStarter.getProblem();
49                this.random = new Random();
50                this.numberOfNotEvaluatedPredefinedOnes = this.problem.getInitialGenotypeList().size();
51        }
52        
53 
54        @Override
55        public DesignDecisionGenotype create() {
56                
57                if (this.numberOfNotEvaluatedPredefinedOnes > 0){
58                        DesignDecisionGenotype genome = this.problem.getInitialGenotypeList().get(this.problem.getInitialGenotypeList().size()-this.numberOfNotEvaluatedPredefinedOnes);
59                        numberOfNotEvaluatedPredefinedOnes --;
60                        return genome;
61 
62                }
63                
64                DesignDecisionGenotype genotype = new DesignDecisionGenotype();
65                
66                List<DegreeOfFreedomInstance> degrees = problem.getDesignDecisions();
67                for (DegreeOfFreedomInstance DegreeOfFreedomInstance : degrees) {
68                        genotype.add(createRandomChoice(DegreeOfFreedomInstance));
69                }
70                
71                return genotype;
72        }
73 
74 
75        private int createIntegerValue(DiscreteDegree discDegree) {
76 
77                if (discDegree instanceof DiscreteRangeDegree){
78                        DiscreteRangeDegree dicRangeDegree = (DiscreteRangeDegree)discDegree;
79                        int range = dicRangeDegree.getTo() - dicRangeDegree.getFrom();
80                        if (!dicRangeDegree.isLowerBoundIncluded()) range--;
81                        if (!dicRangeDegree.isUpperBoundIncluded()) range--;
82                        //random.nextInt creates a random value between 0 <= x < param. I want one 0 <= x <= range. Thus, I add  1  
83                        int value = dicRangeDegree.getFrom() + this.random.nextInt(range+1);
84                        return value;
85                } else if (discDegree instanceof OrderedIntegerDegree){
86                        OrderedIntegerDegree orderedIntegerDegree = (OrderedIntegerDegree) discDegree;
87                        int randomIndex = this.random.nextInt(orderedIntegerDegree.getListOfIntegers().size());
88                        return orderedIntegerDegree.getListOfIntegers().get(randomIndex);
89                } else throw new RuntimeException("Unknown degree "+discDegree.getClass().getName());
90 
91        }
92 
93 
94        private double createDoubleValue(ContinuousRangeDegree contDegree) {
95                double lowerMargin = 0;
96                if (contDegree.isLowerBoundIncluded()){
97                        lowerMargin = Double.MIN_VALUE;
98                }
99                double upperMargin = 0;
100                if (contDegree.isUpperBoundIncluded()){
101                        upperMargin = Double.MIN_VALUE;
102                }
103                double factor = contDegree.getTo() - upperMargin - contDegree.getFrom() - lowerMargin;
104 
105 
106                return contDegree.getFrom() + lowerMargin + this.random.nextDouble()*factor;
107 
108        }
109 
110 
111 
112        public Choice createRandomChoice(DegreeOfFreedomInstance degree) {
113                designdecisionFactory factory = designdecisionFactoryImpl.init();
114                Choice choice;
115                if (degree instanceof DiscreteDegree){
116                        DiscreteRangeChoice discChoice = factory.createDiscreteRangeChoice() ;
117                        discChoice.setChosenValue(createIntegerValue((DiscreteDegree)degree));
118                        choice = discChoice;
119                } else if (degree instanceof ContinuousRangeDegree){
120                        ContinousRangeChoice contChoice = factory.createContinousRangeChoice();
121                        contChoice.setChosenValue(createDoubleValue((ContinuousRangeDegree)degree));
122                        choice = contChoice;
123                } else if (degree instanceof ClassDegree){
124                        ClassChoice enumChoice = factory.createClassChoice();
125                        enumChoice.setChosenValue(createRandomEntity((ClassDegree)degree));
126                        choice = enumChoice;
127                } else if (degree instanceof SchedulingPolicyDegree){
128                        SchedulingPolicyChoice schedChoice = factory.createSchedulingPolicyChoice();
129                        schedChoice.setChosenValue(createRandomSchedulingPolicy((SchedulingPolicyDegree)degree));        
130                        choice = schedChoice;
131                } else throw new RuntimeException("Unknown degree "+degree.getClass().getName());
132                choice.setDegreeOfFreedomInstance(degree);
133                return choice;
134        }
135 
136 
137 
138        private SchedulingPolicy createRandomSchedulingPolicy(
139                        SchedulingPolicyDegree degree) {
140                List<SchedulingPolicy> domain = degree.getDomainOfAllowedSchedulingPolicies();
141                int index = this.random.nextInt(domain.size()); 
142                return domain.get(index);
143        }
144 
145 
146        private EObject createRandomEntity(ClassDegree enumDegree) {
147                List<EObject> domain = enumDegree.getClassDesignOptions();
148                int index = this.random.nextInt(domain.size()); 
149                return domain.get(index);
150 
151        }
152        
153        public void setNumberOfNotEvaluatedPredefinedOnes(
154                        int numberOfNotEvaluatedPredefinedOnes) {
155                this.numberOfNotEvaluatedPredefinedOnes = numberOfNotEvaluatedPredefinedOnes;
156        }
157        
158        public int getNumberOfNotEvaluatedPredefinedOnes(){
159                return this.numberOfNotEvaluatedPredefinedOnes;
160        }
161}

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