1 | package de.uka.ipd.sdq.pcmsolver.transformations; |
2 | |
3 | import java.util.HashMap; |
4 | |
5 | import de.uka.ipd.sdq.pcm.seff.seff_performance.ParametricResourceDemand; |
6 | import de.uka.ipd.sdq.probfunction.ProbabilityDensityFunction; |
7 | import de.uka.ipd.sdq.probfunction.math.ManagedPDF; |
8 | |
9 | /** |
10 | * Cache for the solved resource demands. Stores both pdfs and constant demands. |
11 | * Offers methods to retrieve the actual demand for a ParametricResourceDemand |
12 | * as aa double (i.e. mean value or constant) or PDF. |
13 | * |
14 | * @author martens |
15 | * |
16 | */ |
17 | class ResourceDemandCache { |
18 | private HashMap<ParametricResourceDemand, ExpressionToPDFWrapper> resDemandDistributions = new HashMap<ParametricResourceDemand, ExpressionToPDFWrapper>(); |
19 | |
20 | /** |
21 | * Returns the resource demand for the passed |
22 | * {@link ParametricResourceDemand} as a {@link Double}. May return null if |
23 | * there was no matching resource demand found internally. If the resource |
24 | * demand was only given as a pdf before, it also puts the Double in the |
25 | * cache for future use. |
26 | * |
27 | * @param prd |
28 | * @return |
29 | */ |
30 | public Double getDouble(ParametricResourceDemand prd) { |
31 | if (this.resDemandDistributions.containsKey(prd)) { |
32 | return this.resDemandDistributions.get(prd).getMeanValue(); |
33 | } |
34 | return null; |
35 | } |
36 | |
37 | /** |
38 | * Returns the resource demand for the passed |
39 | * {@link ParametricResourceDemand} as a {@link ManagedPDF}. May return null |
40 | * if there was no matching resource demand found internally. If the |
41 | * resource demand was only given as a double before, it also puts the new |
42 | * pdf in the cache for future use. |
43 | * |
44 | * @param prd |
45 | * @return |
46 | */ |
47 | public ManagedPDF getPDF(ParametricResourceDemand prd) { |
48 | if (this.resDemandDistributions.containsKey(prd)) { |
49 | return new ManagedPDF(resDemandDistributions.get(prd).getPDF()); |
50 | } |
51 | return null; |
52 | } |
53 | |
54 | /** |
55 | * Returns whether this resource demand is a derived pdf (i.e. it has been |
56 | * created using a mean value) or whether it is an original pdf (i.e. the |
57 | * mean value is derived). |
58 | * |
59 | * @return true if it has been created using |
60 | * {@link #put(ParametricResourceDemand, ProbabilityDensityFunction)} |
61 | * , false if this has been created using |
62 | * {@link #put(ParametricResourceDemand, Double)}. |
63 | */ |
64 | public boolean isOriginalPDF(ParametricResourceDemand prd) { |
65 | if (this.resDemandDistributions.containsKey(prd)) { |
66 | return this.resDemandDistributions.get(prd).isOriginalPDF(); |
67 | } else { |
68 | return false; |
69 | } |
70 | } |
71 | |
72 | /** |
73 | * |
74 | * @param parametricResourceDemand |
75 | * @param rdWrapper |
76 | */ |
77 | public void put(ParametricResourceDemand parametricResourceDemand, |
78 | ExpressionToPDFWrapper rdWrapper) { |
79 | this.resDemandDistributions.put(parametricResourceDemand, rdWrapper); |
80 | |
81 | } |
82 | } |