time_value 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/solver.rb +7 -3
- data/lib/time_value/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8d062fe004503ddf10aa4868b97ae5de157d066
|
4
|
+
data.tar.gz: 1bb4988314cb5add83dc1961c433e69933b93bdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9af1844641632a746306d97b8739f08c51ac39fb32934c98c6037a546af7aab600da7cd51ee0806c6ea6dd2822f1a870c1009e36d1521fe9548852f3138e250
|
7
|
+
data.tar.gz: df779a51ed6d53b9192c33a0fd9f8fda36e5cdd7ddf65d6715d47a99497c95d01e9820e8d6bc8b74b669683154f79ea5652566942bba3d320593ff0a6f4954a4
|
data/lib/solver.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
class Solver
|
2
|
+
PRECISION = 3
|
3
|
+
INTERVAL = 10 ** (-1 * PRECISION)
|
4
|
+
MAX_ITERATIONS = 20
|
2
5
|
attr_reader :time_value, :goal
|
3
6
|
attr_accessor :guess, :lower_bound, :upper_bound, :upper_cap_met
|
4
7
|
|
@@ -14,7 +17,8 @@ class Solver
|
|
14
17
|
def solve!
|
15
18
|
iteration_count = 0
|
16
19
|
time_value.i = guess
|
17
|
-
while (upper_bound - lower_bound).round(
|
20
|
+
while (upper_bound - lower_bound).round(PRECISION) > INTERVAL &&
|
21
|
+
iteration_count < MAX_ITERATIONS
|
18
22
|
iteration_count += 1
|
19
23
|
begin
|
20
24
|
result = time_value.calc_fv
|
@@ -24,7 +28,7 @@ class Solver
|
|
24
28
|
adjust_bounds(result)
|
25
29
|
time_value.i = guess
|
26
30
|
end
|
27
|
-
guess if iteration_count <
|
31
|
+
guess.round(2) if iteration_count < MAX_ITERATIONS
|
28
32
|
end
|
29
33
|
|
30
34
|
def adjust_bounds(result)
|
@@ -37,6 +41,6 @@ class Solver
|
|
37
41
|
self.upper_bound *= 2 unless upper_cap_met
|
38
42
|
self.lower_bound = guess
|
39
43
|
end
|
40
|
-
self.guess = ((upper_bound + lower_bound) / 2).round(
|
44
|
+
self.guess = ((upper_bound + lower_bound) / 2).round(PRECISION)
|
41
45
|
end
|
42
46
|
end
|
data/lib/time_value/version.rb
CHANGED