| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "vinyaikina_e_multidimensional_integrals_simpson_method/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstdlib> | ||
| 5 | #include <cstring> | ||
| 6 | #include <functional> | ||
| 7 | #include <stack> | ||
| 8 | #include <utility> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "vinyaikina_e_multidimensional_integrals_simpson_method/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace vinyaikina_e_multidimensional_integrals_simpson_method { | ||
| 14 | namespace { | ||
| 15 | |||
| 16 | 128 | double OuntNtIntegral(double simpson_factor, const std::vector<std::pair<double, double>> &limits, | |
| 17 | std::vector<double> &actual_step, | ||
| 18 | const std::function<double(const std::vector<double> &)> &function) { | ||
| 19 | std::stack<std::pair<std::vector<double>, double>> stack; | ||
| 20 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
128 | stack.emplace(std::vector<double>(), 1.0); |
| 21 | |||
| 22 | double res = 0.0; | ||
| 23 | |||
| 24 |
2/2✓ Branch 0 taken 4757552 times.
✓ Branch 1 taken 128 times.
|
4757680 | while (!stack.empty()) { |
| 25 |
1/2✓ Branch 1 taken 4757552 times.
✗ Branch 2 not taken.
|
4757552 | std::vector<double> point = stack.top().first; |
| 26 | 4757552 | double weight = stack.top().second; | |
| 27 | stack.pop(); | ||
| 28 | |||
| 29 |
2/2✓ Branch 0 taken 4681296 times.
✓ Branch 1 taken 76256 times.
|
4757552 | if (point.size() == limits.size()) { |
| 30 |
1/2✓ Branch 0 taken 4681296 times.
✗ Branch 1 not taken.
|
4681296 | res += function(point) * weight * simpson_factor; |
| 31 | continue; | ||
| 32 | } | ||
| 33 | |||
| 34 | size_t dim = point.size(); | ||
| 35 | 76256 | double step = actual_step[dim] / 1.0; | |
| 36 | |||
| 37 | 76256 | int steps_count = static_cast<int>(lround((limits[dim].second - limits[dim].first) / step)); | |
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 4757424 times.
✓ Branch 1 taken 76256 times.
|
4833680 | for (int i = 0; i <= steps_count; ++i) { |
| 40 | 4757424 | double x = limits[dim].first + (i * step); | |
| 41 | |||
| 42 | double dim_weight = 2.0; | ||
| 43 |
2/2✓ Branch 0 taken 4604912 times.
✓ Branch 1 taken 152512 times.
|
4757424 | if (i == 0 || i == steps_count) { |
| 44 | dim_weight = 1.0; | ||
| 45 |
2/2✓ Branch 0 taken 2340584 times.
✓ Branch 1 taken 2264328 times.
|
4604912 | } else if (i % 2 != 0) { |
| 46 | dim_weight = 4.0; | ||
| 47 | } | ||
| 48 | |||
| 49 | point.push_back(x); | ||
| 50 |
1/4✓ Branch 1 taken 4757424 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
4757424 | stack.emplace(point, weight * dim_weight); |
| 51 | point.pop_back(); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | 128 | return res; | |
| 56 | } | ||
| 57 | }; // namespace | ||
| 58 | |||
| 59 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
128 | VinyaikinaEMultidimIntegrSimpsonSEQ::VinyaikinaEMultidimIntegrSimpsonSEQ(const InType &in) { |
| 60 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 61 | GetInput() = in; | ||
| 62 | 128 | } | |
| 63 | |||
| 64 | 128 | bool VinyaikinaEMultidimIntegrSimpsonSEQ::PreProcessingImpl() { | |
| 65 | 128 | return true; | |
| 66 | } | ||
| 67 | |||
| 68 |
1/2✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
|
128 | bool VinyaikinaEMultidimIntegrSimpsonSEQ::ValidationImpl() { |
| 69 | const auto &[h, limits, function] = GetInput(); | ||
| 70 |
3/6✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 128 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 128 times.
|
128 | return !limits.empty() && function && h <= 0.01; |
| 71 | } | ||
| 72 | |||
| 73 | 128 | bool VinyaikinaEMultidimIntegrSimpsonSEQ::RunImpl() { | |
| 74 | const auto &[h, limits, function] = GetInput(); | ||
| 75 | |||
| 76 | 128 | std::vector<double> actual_step(limits.size()); | |
| 77 | double simpson_factor = 1.0; | ||
| 78 | |||
| 79 |
2/2✓ Branch 0 taken 224 times.
✓ Branch 1 taken 128 times.
|
352 | for (size_t i = 0; i < limits.size(); i++) { |
| 80 | 224 | int quan_steps = static_cast<int>(lround((limits[i].second - limits[i].first) / h)); | |
| 81 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 192 times.
|
224 | if (quan_steps % 2 != 0) { |
| 82 | 32 | quan_steps++; | |
| 83 | } | ||
| 84 | 224 | actual_step[i] = (limits[i].second - limits[i].first) / quan_steps; | |
| 85 | 224 | simpson_factor *= actual_step[i] / 3.0; | |
| 86 | } | ||
| 87 | |||
| 88 |
2/4✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 128 times.
✗ Branch 4 not taken.
|
128 | I_res_ = OuntNtIntegral(simpson_factor, limits, actual_step, function); |
| 89 | |||
| 90 | 128 | return true; | |
| 91 | } | ||
| 92 | |||
| 93 | 128 | bool VinyaikinaEMultidimIntegrSimpsonSEQ::PostProcessingImpl() { | |
| 94 | 128 | GetOutput() = I_res_; | |
| 95 | 128 | return true; | |
| 96 | } | ||
| 97 | } // namespace vinyaikina_e_multidimensional_integrals_simpson_method | ||
| 98 |