| 1 | package de.uka.ipd.sdq.dsexplore.opt4j.representation; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | import java.util.Map; |
| 5 | |
| 6 | import org.opt4j.core.Criterion; |
| 7 | import org.opt4j.core.Objective; |
| 8 | import org.opt4j.core.Constraint; |
| 9 | import org.opt4j.core.Objectives; |
| 10 | import org.opt4j.core.Value; |
| 11 | import org.opt4j.core.domination.DominationStrategy; |
| 12 | |
| 13 | import com.google.inject.Inject; |
| 14 | |
| 15 | import de.uka.ipd.sdq.context.aggregatedUsageContext.ComputedAggregatedUsage; |
| 16 | import de.uka.ipd.sdq.dsexplore.analysis.IAnalysisResult; |
| 17 | import de.uka.ipd.sdq.dsexplore.analysis.IPerformanceAnalysisResult; |
| 18 | import de.uka.ipd.sdq.dsexplore.analysis.IStatisticAnalysisResult; |
| 19 | import de.uka.ipd.sdq.pcm.resultdecorator.ResultDecoratorRepository; |
| 20 | import de.uka.ipd.sdq.statistics.estimation.ConfidenceInterval; |
| 21 | |
| 22 | public class DSEObjectives extends Objectives { |
| 23 | |
| 24 | private Map<Criterion, ConfidenceInterval> confidence = new HashMap<Criterion, ConfidenceInterval>(); |
| 25 | private Map<Criterion, ResultDecoratorRepository> resultDecorators = new HashMap<Criterion, ResultDecoratorRepository>(); |
| 26 | private Map<Criterion, ComputedAggregatedUsage> computedAggregatedResult = new HashMap<Criterion, ComputedAggregatedUsage>(); |
| 27 | |
| 28 | //private Map<Objective, IAnalysisResult> detailedResults = new TreeMap<Objective, IAnalysisResult>(); |
| 29 | |
| 30 | public void addResult(Objective o, IAnalysisResult result){ |
| 31 | //this.detailedResults.put(o, result); |
| 32 | ConfidenceInterval ci = this.getConfidenceIntervalFromResult(result); |
| 33 | if (ci != null){ |
| 34 | this.confidence.put(o, ci); |
| 35 | } |
| 36 | if (result instanceof IPerformanceAnalysisResult){ |
| 37 | this.resultDecorators.put(o, ((IPerformanceAnalysisResult) result).getResults()); |
| 38 | this.computedAggregatedResult .put(o, ((IPerformanceAnalysisResult) result).getComputedAggregatedUsage()); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | @Deprecated |
| 43 | public DSEObjectives(){super();} // Get objects from provider |
| 44 | |
| 45 | @Inject |
| 46 | public DSEObjectives(DominationStrategy strategy) { |
| 47 | super(strategy); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | |
| 52 | // public boolean hasDetailedResultsForObjective(Objective o){ |
| 53 | // return this.detailedResults.containsKey(o); |
| 54 | // } |
| 55 | // |
| 56 | // public IAnalysisResult getDetailedResultsFor(Objective o){ |
| 57 | // return this.detailedResults.get(o); |
| 58 | // } |
| 59 | |
| 60 | @Override |
| 61 | public Objective get(Value<?> value) { |
| 62 | // TODO Auto-generated method stub |
| 63 | return super.get(value); |
| 64 | } |
| 65 | |
| 66 | public Value<?> getValueForCriterion(Criterion c){ |
| 67 | if (c instanceof Objective){ |
| 68 | return this.get((Objective)c); |
| 69 | } else if (c instanceof Constraint){ |
| 70 | return this.getConstraints().get((Constraint)c); |
| 71 | } else { |
| 72 | throw new RuntimeException("A criterion that is neither Objective nor Constraints has been encountered, contact developers. Class: "+c.getClass()); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | |
| 77 | |
| 78 | public void addConfidence(Criterion o, ConfidenceInterval c){ |
| 79 | this.confidence.put(o, c); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * |
| 84 | * @return The Map of ConfidenceIntervals, which is not null, but may be empty. |
| 85 | */ |
| 86 | public Map<Criterion, ConfidenceInterval> getConfidenceIntervals(){ |
| 87 | return this.confidence; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Can be null |
| 92 | * @param o |
| 93 | * @return The confidence interval for the given Objective or null if it does not exist. |
| 94 | */ |
| 95 | public ConfidenceInterval getConfidenceIntervalForObjective(Criterion o){ |
| 96 | return this.confidence.get(o); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Can be null |
| 101 | * @param o |
| 102 | * @return The confidence interval for the given Objective or null if it does not exist. |
| 103 | */ |
| 104 | private ConfidenceInterval getConfidenceIntervalFromResult( |
| 105 | IAnalysisResult result) { |
| 106 | if (result instanceof IStatisticAnalysisResult){ |
| 107 | IStatisticAnalysisResult statisticResult = (IStatisticAnalysisResult) result; |
| 108 | ConfidenceInterval c = statisticResult.getConfidenceInterval(); |
| 109 | return c; |
| 110 | } else { |
| 111 | return null; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | public void addResultDecoratorFor(Criterion performance, ResultDecoratorRepository resultDecorator){ |
| 116 | this.resultDecorators.put(performance, resultDecorator); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | * May return null if no result decorator is available. |
| 122 | * @param o |
| 123 | * @return |
| 124 | */ |
| 125 | public ResultDecoratorRepository getResultDecoratorFor( |
| 126 | Criterion o) { |
| 127 | return this.resultDecorators.get(o); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Returns whether a non-null result decorator for this Objective o is available |
| 132 | * @param o |
| 133 | * @return |
| 134 | */ |
| 135 | public boolean hasResultDecoratorFor( |
| 136 | Criterion o) { |
| 137 | return this.resultDecorators.containsKey(o) && this.resultDecorators.get(o) != null; |
| 138 | } |
| 139 | |
| 140 | public void addComputedAggregatedUsage(Criterion o, ComputedAggregatedUsage computedAggregatedUsage){ |
| 141 | this.computedAggregatedResult.put(o, computedAggregatedUsage); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | /** |
| 146 | * May return null if no result decorator is available. |
| 147 | * @param o |
| 148 | * @return |
| 149 | */ |
| 150 | public ComputedAggregatedUsage getComputedAggregatedUsageFor(Criterion o) { |
| 151 | return this.computedAggregatedResult.get(o); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Returns whether a non-null result decorator for this Objective o is available |
| 156 | * @param o |
| 157 | * @return |
| 158 | */ |
| 159 | public boolean hasComputedAggregatedUsageFor( |
| 160 | Criterion o) { |
| 161 | return this.computedAggregatedResult.containsKey(o) && this.computedAggregatedResult.get(o) != null; |
| 162 | } |
| 163 | |
| 164 | public void addValueForCriterion(Criterion criterion, double d) { |
| 165 | if (criterion instanceof Objective){ |
| 166 | this.add((Objective)criterion,d); |
| 167 | } else if (criterion instanceof Constraint){ |
| 168 | this.getConstraints().add((Constraint)criterion, d); |
| 169 | } else { |
| 170 | throw new RuntimeException("A criterion that is neither Objective nor Constraints has been encountered, contact developers. Class: "+criterion.getClass()); |
| 171 | } |
| 172 | |
| 173 | } |
| 174 | |
| 175 | |
| 176 | } |