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

nameclass, %method, %block, %line, %
QMLBoundDependentTacticOperatorsManager.java0%   (0/2)0%   (0/15)0%   (0/465)0%   (0/100)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class QMLBoundDependentTacticOperatorsManager0%   (0/1)0%   (0/6)0%   (0/403)0%   (0/83)
$SWITCH_TABLE$org$opt4j$core$Constraint$Direction (): int [] 0%   (0/1)0%   (0/48)0%   (0/1)
QMLBoundDependentTacticOperatorsManager (Copy, DSEIndividualBuilder): void 0%   (0/1)0%   (0/5)0%   (0/2)
analyzeConstraints (DSEIndividual): QMLBoundDependentTacticOperatorsManager$C... 0%   (0/1)0%   (0/59)0%   (0/11)
getAllCandidates (DSEIndividual): List 0%   (0/1)0%   (0/145)0%   (0/27)
isFulfilled (Map$Entry): boolean 0%   (0/1)0%   (0/73)0%   (0/21)
isViolated (Map$Entry): boolean 0%   (0/1)0%   (0/73)0%   (0/21)
     
class QMLBoundDependentTacticOperatorsManager$ConstraintViolationInformation0%   (0/1)0%   (0/9)0%   (0/62)0%   (0/17)
QMLBoundDependentTacticOperatorsManager$ConstraintViolationInformation (QMLBo... 0%   (0/1)0%   (0/26)0%   (0/5)
addFulfilledInfeasibilityConstraint (InfeasibilityConstraint): void 0%   (0/1)0%   (0/6)0%   (0/2)
addFulfilledSatisfactionConstraint (SatisfactionConstraint): void 0%   (0/1)0%   (0/6)0%   (0/2)
addViolatedInfeasibilityConstraint (InfeasibilityConstraint): void 0%   (0/1)0%   (0/6)0%   (0/2)
addViolatedSatisfactionConstraint (SatisfactionConstraint): void 0%   (0/1)0%   (0/6)0%   (0/2)
getFulfilledInfeasibilityConstraints (): List 0%   (0/1)0%   (0/3)0%   (0/1)
getFulfilledSatisfactionConstraints (): List 0%   (0/1)0%   (0/3)0%   (0/1)
getViolatedInfeasibilityConstraints (): List 0%   (0/1)0%   (0/3)0%   (0/1)
getViolatedSatisfactionConstraints (): List 0%   (0/1)0%   (0/3)0%   (0/1)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.dsexplore.opt4j.optimizer.heuristic.operators;
5 
6import java.util.ArrayList;
7import java.util.Collection;
8import java.util.HashSet;
9import java.util.List;
10import java.util.Set;
11import java.util.Map.Entry;
12 
13import org.opt4j.core.Constraint;
14import org.opt4j.core.InfeasibilityConstraint;
15import org.opt4j.core.SatisfactionConstraint;
16import org.opt4j.core.Value;
17import org.opt4j.core.problem.Genotype;
18import org.opt4j.operator.copy.Copy;
19 
20import com.google.inject.Inject;
21 
22import de.uka.ipd.sdq.dsexplore.opt4j.representation.DSEIndividual;
23import de.uka.ipd.sdq.dsexplore.opt4j.representation.DSEIndividualBuilder;
24import de.uka.ipd.sdq.dsexplore.qml.pcm.datastructures.EvaluationAspectWithContext;
25import de.uka.ipd.sdq.dsexplore.qml.pcm.reader.PCMDeclarationsReader;
26 
27/**
28 * Applies activated heuristics based on the constraint violation of an 
29 * individual in the following order:
30 * 1) Try to get individual feasible if it is infeasible. 
31 * 2) Try to reach all defined goals if not reached yet. 
32 * 3) Apply any heuristic applicable if no previous case applies.   
33 * 
34 * @author noorshams
35 *
36 */
37public class QMLBoundDependentTacticOperatorsManager extends TacticOperatorsManager {
38 
39        @Inject
40        public QMLBoundDependentTacticOperatorsManager(Copy<Genotype> copy,
41                        DSEIndividualBuilder individualBuilder) {
42                super(copy, individualBuilder);
43        }
44        
45        /**
46         * Applies heuristics based on all constraint violations of an individual: 
47         * Try to make individual feasible. If feasible, try to reach all goals. If all goals
48         * reached, apply any heuristic. 
49         */
50        @Override
51        public List<TacticsResultCandidate> getAllCandidates(
52                        DSEIndividual individual) {
53                //results cache for the current candidate. 
54                UtilisationResultCacheAndHelper resultsCache = new UtilisationResultCacheAndHelper(); 
55                
56                
57                List<TacticsResultCandidate> result = new ArrayList<TacticsResultCandidate>();
58                Collection<TacticsResultCandidate> candidatesFromCurrentHeuristic;
59                Set<ITactic> applicableHeuristics = new HashSet<ITactic>();
60                
61                //get all constraint violations and fulfillments
62                ConstraintViolationInformation cvi = analyzeConstraints(individual);
63                
64                if(cvi.getViolatedInfeasibilityConstraints().size() > 0) {
65                        //individual is infeasible try to make it feasible
66                        
67                        for(InfeasibilityConstraint c : cvi.getViolatedInfeasibilityConstraints()) {
68                                EvaluationAspectWithContext pivotAspectContext = 
69                                        PCMDeclarationsReader.retranslateCriterionToEvaluationAspect(c);                                
70                                
71                                //pick applicable heuristic that improves aspect                                        
72                                for(ITactic h: heuristics) {
73                                        if(h.improves(pivotAspectContext.getDimension(), pivotAspectContext.getEvaluationAspect())){
74                                                applicableHeuristics.add(h);
75                                        }
76                                }
77                        }
78                } else {
79                        //individual is feasible try to reach all goals (-> fulfill all SatisfactionConstraints)
80                        
81                        if(cvi.getViolatedSatisfactionConstraints().size() > 0) {
82                                //not all goals reached
83                                
84                                for (SatisfactionConstraint c : cvi.getViolatedSatisfactionConstraints()) {
85                                        EvaluationAspectWithContext pivotAspectContext = 
86                                                PCMDeclarationsReader.retranslateCriterionToEvaluationAspect(c);                                
87                                        
88                                        //pick applicable heuristic that improves aspect                                        
89                                        for(ITactic h: heuristics) {
90                                                if(h.improves(pivotAspectContext.getDimension(), pivotAspectContext.getEvaluationAspect())){
91                                                        applicableHeuristics.add(h);
92                                                }
93                                        }
94                                }
95                        } else {
96                                //all goals reached, apply any possible heuristic 
97                                applicableHeuristics.addAll(heuristics);
98                        }
99                }
100                
101                if (applicableHeuristics.size() == 0){
102                        //no tactic is applicable in this case, so again add all
103                        applicableHeuristics.addAll(heuristics);
104                }
105                                
106                //apply heuristic
107                for(ITactic heuristic : applicableHeuristics){
108                        candidatesFromCurrentHeuristic = heuristic.getHeuristicCandidates(individual, resultsCache);
109                        if (candidatesFromCurrentHeuristic.size() > 0) {
110                                this.writer.writeTacticCandidateInfo(heuristic, candidatesFromCurrentHeuristic);
111                        }
112                        result.addAll(candidatesFromCurrentHeuristic);
113                }
114                //XXX Try again to add all other tactics if the appropriate ones did not help? Or rather do not apply tactics in this case?
115                
116                return result;
117        }
118        
119        protected boolean isViolated(Entry<Constraint, Value<?>> constraintAndValue) {
120                boolean violated = false;
121                Constraint c = constraintAndValue.getKey();
122                Value<?> v = constraintAndValue.getValue();
123                
124                switch (c.getDirection()) {
125                        case less:
126                                if(!(v.getDouble() < c.getLimit())){
127                                        violated = true;
128                                }
129                                break;
130                        case lessOrEqual:
131                                if(!(v.getDouble() <= c.getLimit())){
132                                        violated = true;
133                                }                        
134                                break;
135                        case equal:
136                                if(!(v.getDouble() == c.getLimit())){
137                                        violated = true;
138                                }
139                                break;
140                        case greater:
141                                if(!(v.getDouble() > c.getLimit())){
142                                        violated = true;
143                                }
144                                break;
145                        case greaterOrEqual:
146                                if(!(v.getDouble() >= c.getLimit())){
147                                        violated = true;
148                                }
149                                break;
150                        default:
151                                throw new RuntimeException("Unexpected case in switch statement!");                                
152                }
153                return violated;
154        }
155        
156        protected boolean isFulfilled(Entry<Constraint, Value<?>> constraintAndValue) {
157                boolean fulfilled = false;
158                Constraint c = constraintAndValue.getKey();
159                Value<?> v = constraintAndValue.getValue();
160                
161                switch (c.getDirection()) {
162                        case less:
163                                if(v.getDouble() < c.getLimit()){
164                                        fulfilled = true;
165                                }
166                                break;
167                        case lessOrEqual:
168                                if(v.getDouble() <= c.getLimit()){
169                                        fulfilled = true;
170                                }                        
171                                break;
172                        case equal:
173                                if(v.getDouble() == c.getLimit()){
174                                        fulfilled = true;
175                                }
176                                break;
177                        case greater:
178                                if(v.getDouble() > c.getLimit()){
179                                        fulfilled = true;
180                                }
181                                break;
182                        case greaterOrEqual:
183                                if(v.getDouble() >= c.getLimit()){
184                                        fulfilled = true;
185                                }
186                                break;
187                        default:
188                                throw new RuntimeException("Unexpected case in switch statement!");                                
189                }
190                return fulfilled;
191        }
192        
193        protected ConstraintViolationInformation analyzeConstraints(DSEIndividual individual){
194                ConstraintViolationInformation cvi = new ConstraintViolationInformation();
195                for(Entry<Constraint, Value<?>> constraintAndValue : individual.getObjectives().getConstraints()) {
196                        if (isViolated(constraintAndValue)) {
197                                if (constraintAndValue.getKey() instanceof InfeasibilityConstraint) {
198                                        cvi.addViolatedInfeasibilityConstraint((InfeasibilityConstraint)constraintAndValue.getKey());
199                                } else {
200                                        //SatisfactionConstraint
201                                        cvi.addViolatedSatisfactionConstraint((SatisfactionConstraint)constraintAndValue.getKey());
202                                }
203                        } else if (isFulfilled(constraintAndValue)) { // To ignore constraints where the value is NaN, check constraints explicitly
204                                if (constraintAndValue.getKey() instanceof InfeasibilityConstraint) {
205                                        cvi.addFulfilledInfeasibilityConstraint((InfeasibilityConstraint)constraintAndValue.getKey());
206                                } else {
207                                        //SatisfactionConstraint
208                                        cvi.addFulfilledSatisfactionConstraint((SatisfactionConstraint)constraintAndValue.getKey());
209                                }
210                        }
211                                
212                }
213                        
214                return cvi;
215        }
216        
217        protected class ConstraintViolationInformation {
218                protected List<InfeasibilityConstraint> violatedInfeasibilityConstraints = new ArrayList<InfeasibilityConstraint>();
219                protected List<InfeasibilityConstraint> fulfilledInfeasibilityConstraints = new ArrayList<InfeasibilityConstraint>();
220                protected List<SatisfactionConstraint> violatedSatisfactionConstraints = new ArrayList<SatisfactionConstraint>();
221                protected List<SatisfactionConstraint> fulfilledSatisfactionConstraints = new ArrayList<SatisfactionConstraint>();
222                
223                public List<InfeasibilityConstraint> getViolatedInfeasibilityConstraints() {
224                        return violatedInfeasibilityConstraints;
225                }
226 
227                public void addViolatedInfeasibilityConstraint(
228                                InfeasibilityConstraint violoatedInfeasibilityConstraint) {
229                        this.violatedInfeasibilityConstraints.add(violoatedInfeasibilityConstraint);
230                }
231 
232                public List<InfeasibilityConstraint> getFulfilledInfeasibilityConstraints() {
233                        return fulfilledInfeasibilityConstraints;
234                }
235 
236                public void addFulfilledInfeasibilityConstraint(
237                                InfeasibilityConstraint fulfilledInfeasibilityConstraint) {
238                        this.fulfilledInfeasibilityConstraints.add(fulfilledInfeasibilityConstraint);
239                }
240 
241                public List<SatisfactionConstraint> getViolatedSatisfactionConstraints() {
242                        return violatedSatisfactionConstraints;
243                }
244 
245                public void addViolatedSatisfactionConstraint(
246                                SatisfactionConstraint violoatedSatisfactionConstraint) {
247                        this.violatedSatisfactionConstraints.add(violoatedSatisfactionConstraint);
248                }
249                
250                public List<SatisfactionConstraint> getFulfilledSatisfactionConstraints() {
251                        return fulfilledSatisfactionConstraints;
252                }
253 
254                public void addFulfilledSatisfactionConstraint(
255                                SatisfactionConstraint fulfilledSatisfactionConstraint) {
256                        this.fulfilledSatisfactionConstraints.add(fulfilledSatisfactionConstraint);
257                }                
258        }
259        
260        //Don't override, same picking method as superclass
261//        @Override
262//        public DSEIndividual getCandidate(DSEIndividual individual)
263 
264        
265}

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