1 | package de.uka.ipd.sdq.reliability.solver.pcm2markov; |
2 | |
3 | /** |
4 | * This class represents an approximated Markov transformation result value. |
5 | * |
6 | * @author brosch |
7 | * |
8 | */ |
9 | public class MarkovResultApproximation { |
10 | |
11 | /** |
12 | * The maximal accuracy yielded by an approximation. |
13 | */ |
14 | private static final int MAXACCURACY = 10; |
15 | |
16 | /** |
17 | * The accuracy (i.e., number of exact decimal places) of this |
18 | * approximation. |
19 | */ |
20 | private int accuracy = 0; |
21 | |
22 | /** |
23 | * The lower approximation bound after adjustment. |
24 | */ |
25 | private double adjustedLowerBound = 0.0; |
26 | |
27 | /** |
28 | * The upper approximation bound after adjustment. |
29 | */ |
30 | private double adjustedUpperBound = 0.0; |
31 | |
32 | /** |
33 | * A lower approximation bound. |
34 | */ |
35 | private double lowerBound = 0.0; |
36 | |
37 | /** |
38 | * An upper approximation bound. |
39 | */ |
40 | private double upperBound = 0.0; |
41 | |
42 | /** |
43 | * Initializes a new Markov result value approximation. |
44 | * |
45 | * @param lowerBound |
46 | * the lower bound of the approximation |
47 | * @param upperBound |
48 | * the upper bound of the approximation |
49 | */ |
50 | public MarkovResultApproximation(final double lowerBound, |
51 | final double upperBound) { |
52 | this.lowerBound = lowerBound; |
53 | this.upperBound = upperBound; |
54 | calculateAccuracy(); |
55 | adjustBounds(); |
56 | } |
57 | |
58 | /** |
59 | * Replaces the approximation through a more coarse-grained one, in order to |
60 | * reduce the number of decimal places of the bounds to the value of |
61 | * accuracy. |
62 | */ |
63 | private void adjustBounds() { |
64 | adjustedLowerBound = Math |
65 | .floor(lowerBound * Math.pow(10, accuracy + 1)) |
66 | / Math.pow(10, accuracy + 1); |
67 | adjustedUpperBound = Math.ceil(upperBound * Math.pow(10, accuracy + 1)) |
68 | / Math.pow(10, accuracy + 1); |
69 | } |
70 | |
71 | /** |
72 | * Determines the accuracy of the approximation. |
73 | */ |
74 | private void calculateAccuracy() { |
75 | double delta = upperBound - lowerBound; |
76 | accuracy = 1; |
77 | while (delta < Math.pow(0.1, accuracy)) { |
78 | accuracy++; |
79 | if (accuracy > MAXACCURACY) { |
80 | break; |
81 | } |
82 | } |
83 | accuracy -= 1; |
84 | } |
85 | |
86 | /** |
87 | * Retrieves the accuracy (i.e., number of exact decimal values) of the |
88 | * approximation. |
89 | * |
90 | * @return the accuracy of the approximation |
91 | */ |
92 | public int getAccuracy() { |
93 | return accuracy; |
94 | } |
95 | |
96 | /** |
97 | * Retrieves the lower approximation bound after adjustment. |
98 | * |
99 | * @return the lower approximation bound |
100 | */ |
101 | public double getAdjustedLowerBound() { |
102 | return adjustedLowerBound; |
103 | } |
104 | |
105 | /** |
106 | * Retrieves the upper approximation bound after adjustment. |
107 | * |
108 | * @return the upper approximation bound |
109 | */ |
110 | public double getAdjustedUpperBound() { |
111 | return adjustedUpperBound; |
112 | } |
113 | |
114 | /** |
115 | * Retrieves the lower approximation bound. |
116 | * |
117 | * @return the lower approximation bound |
118 | */ |
119 | public double getLowerBound() { |
120 | return lowerBound; |
121 | } |
122 | |
123 | /** |
124 | * Retrieves the upper approximation bound. |
125 | * |
126 | * @return the upper approximation bound |
127 | */ |
128 | public double getUpperBound() { |
129 | return upperBound; |
130 | } |
131 | |
132 | /** |
133 | * Checks if the approximation fulfills a required accuracy (i.e., number of |
134 | * exact decimal places). |
135 | * |
136 | * @param requiredAccuracy |
137 | * the required accuracy |
138 | * @return true if the required accuracy is fulfilled |
139 | */ |
140 | public boolean hasRequiredAccuracy(final int requiredAccuracy) { |
141 | return (accuracy >= requiredAccuracy); |
142 | } |
143 | } |