| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "popova_e_integr_monte_carlo/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | |||
| 5 | #include "popova_e_integr_monte_carlo/common/include/common.hpp" | ||
| 6 | |||
| 7 | namespace popova_e_integr_monte_carlo { | ||
| 8 | |||
| 9 | 80 | PopovaEIntegrMonteCarloSEQ::PopovaEIntegrMonteCarloSEQ(const InType &in) { | |
| 10 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 11 | GetInput() = in; | ||
| 12 | GetOutput() = 0; | ||
| 13 | 80 | } | |
| 14 | |||
| 15 | 80 | bool PopovaEIntegrMonteCarloSEQ::ValidationImpl() { | |
| 16 | const auto &[a, b, n, func_id] = GetInput(); | ||
| 17 |
3/6✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 80 times.
|
80 | return (a < b) && (n > 0) && (func_id >= FuncType::kLinearFunc) && (func_id <= FuncType::kExpFunc); |
| 18 | } | ||
| 19 | |||
| 20 | 80 | bool PopovaEIntegrMonteCarloSEQ::PreProcessingImpl() { | |
| 21 | const auto &[a, b, n, func_id] = GetInput(); | ||
| 22 | 80 | a_ = a; | |
| 23 | 80 | b_ = b; | |
| 24 | 80 | point_count_ = n; | |
| 25 | 80 | func_id_ = func_id; | |
| 26 | |||
| 27 | 80 | return true; | |
| 28 | } | ||
| 29 | |||
| 30 | 80 | bool PopovaEIntegrMonteCarloSEQ::RunImpl() { | |
| 31 | const double magic_constant = 0.75487766624669276; | ||
| 32 | double current = 0.5; | ||
| 33 | |||
| 34 | double sum = 0.0; | ||
| 35 |
2/2✓ Branch 0 taken 1748800 times.
✓ Branch 1 taken 80 times.
|
1748880 | for (int i = 0; i < point_count_; ++i) { |
| 36 | 1748800 | current += magic_constant; | |
| 37 |
2/2✓ Branch 0 taken 1320120 times.
✓ Branch 1 taken 428680 times.
|
1748800 | if (current >= 1.0) { |
| 38 | 1320120 | current -= 1.0; | |
| 39 | } | ||
| 40 | |||
| 41 | 1748800 | double x = a_ + ((b_ - a_) * current); | |
| 42 | |||
| 43 | double fx = 0.0; | ||
| 44 | 1748800 | fx = FunctionPair::Function(func_id_, x); | |
| 45 | 1748800 | sum += fx; | |
| 46 | } | ||
| 47 | |||
| 48 | 80 | double sredn = sum / static_cast<double>(point_count_); | |
| 49 | 80 | double integral = (b_ - a_) * sredn; | |
| 50 | 80 | GetOutput() = integral; | |
| 51 | |||
| 52 | 80 | return true; | |
| 53 | } | ||
| 54 | |||
| 55 | 80 | bool PopovaEIntegrMonteCarloSEQ::PostProcessingImpl() { | |
| 56 | 80 | return true; | |
| 57 | } | ||
| 58 | |||
| 59 | } // namespace popova_e_integr_monte_carlo | ||
| 60 |