| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "romanova_v_jacobi_method/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <tuple> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "romanova_v_jacobi_method/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace romanova_v_jacobi_method { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
88 | RomanovaVJacobiMethodSEQ::RomanovaVJacobiMethodSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | GetOutput(); | ||
| 17 | 88 | } | |
| 18 | |||
| 19 | 88 | bool RomanovaVJacobiMethodSEQ::ValidationImpl() { | |
| 20 | bool status = true; | ||
| 21 | // матрица имеет корректные размеры | ||
| 22 | 88 | std::vector<std::vector<double>> a = std::get<1>(GetInput()); | |
| 23 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
88 | std::vector<double> x = std::get<0>(GetInput()); |
| 24 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
88 | std::vector<double> b = std::get<2>(GetInput()); |
| 25 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
|
88 | status = status && !a.empty(); |
| 26 |
2/2✓ Branch 0 taken 368 times.
✓ Branch 1 taken 88 times.
|
456 | for (size_t i = 0; i < a.size(); i++) { |
| 27 |
2/4✓ Branch 0 taken 368 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 368 times.
|
368 | status = status && (a.size() == a[i].size()); |
| 28 | } | ||
| 29 | |||
| 30 |
2/4✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
|
88 | status = status && IsDiagonallyDominant(a); |
| 31 | |||
| 32 |
1/2✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
|
88 | status = status && (a.size() == x.size()); |
| 33 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
|
88 | status = status && (a.size() == b.size()); |
| 34 | 88 | return status; | |
| 35 | 88 | } | |
| 36 | |||
| 37 | 88 | bool RomanovaVJacobiMethodSEQ::PreProcessingImpl() { | |
| 38 | 88 | std::tie(x_, A_, b_, eps_, maxIterations_) = GetInput(); | |
| 39 | // x_ = std::get<0>(GetInput()); | ||
| 40 | // A_ = std::get<1>(GetInput()); | ||
| 41 | // b_ = std::get<2>(GetInput()); | ||
| 42 | // eps_ = std::get<3>(GetInput()); | ||
| 43 | // maxIterations_ = std::get<4>(GetInput()); | ||
| 44 | 88 | size_ = x_.size(); | |
| 45 | 88 | return true; | |
| 46 | } | ||
| 47 | |||
| 48 | 88 | bool RomanovaVJacobiMethodSEQ::RunImpl() { | |
| 49 | size_t k = 0; | ||
| 50 | 88 | std::vector<double> prev(x_.size(), 0.0); | |
| 51 | 88 | double diff = eps_; | |
| 52 |
4/4✓ Branch 0 taken 2928 times.
✓ Branch 1 taken 80 times.
✓ Branch 2 taken 2920 times.
✓ Branch 3 taken 8 times.
|
3008 | while (diff >= eps_ && k < maxIterations_) { |
| 53 | 2920 | diff = 0.0; | |
| 54 |
1/2✓ Branch 1 taken 2920 times.
✗ Branch 2 not taken.
|
2920 | prev = x_; |
| 55 |
2/2✓ Branch 0 taken 11376 times.
✓ Branch 1 taken 2920 times.
|
14296 | for (size_t i = 0; i < size_; i++) { |
| 56 | double sum = 0.0; | ||
| 57 |
2/2✓ Branch 0 taken 54288 times.
✓ Branch 1 taken 11376 times.
|
65664 | for (size_t j = 0; j < size_; j++) { |
| 58 |
2/2✓ Branch 0 taken 42912 times.
✓ Branch 1 taken 11376 times.
|
54288 | if (i != j) { |
| 59 | 42912 | sum += A_[i][j] * prev[j]; | |
| 60 | } | ||
| 61 | } | ||
| 62 | 11376 | x_[i] = (b_[i] - sum) / A_[i][i]; | |
| 63 | 11376 | diff = std::max(diff, std::abs(x_[i] - prev[i])); | |
| 64 | } | ||
| 65 | 2920 | k++; | |
| 66 | } | ||
| 67 | |||
| 68 | 88 | return true; | |
| 69 | } | ||
| 70 | |||
| 71 | 88 | bool RomanovaVJacobiMethodSEQ::PostProcessingImpl() { | |
| 72 | 88 | GetOutput() = x_; | |
| 73 | 88 | return true; | |
| 74 | } | ||
| 75 | |||
| 76 | 88 | bool RomanovaVJacobiMethodSEQ::IsDiagonallyDominant(const std::vector<std::vector<double>> &matrix) { | |
| 77 |
2/2✓ Branch 0 taken 368 times.
✓ Branch 1 taken 88 times.
|
456 | for (size_t i = 0; i < matrix.size(); i++) { |
| 78 | double sum = 0.0; | ||
| 79 |
2/2✓ Branch 0 taken 1968 times.
✓ Branch 1 taken 368 times.
|
2336 | for (size_t j = 0; j < matrix[i].size(); j++) { |
| 80 |
2/2✓ Branch 0 taken 1600 times.
✓ Branch 1 taken 368 times.
|
1968 | if (i != j) { |
| 81 | 1600 | sum += matrix[i][j]; | |
| 82 | } | ||
| 83 | } | ||
| 84 |
1/2✓ Branch 0 taken 368 times.
✗ Branch 1 not taken.
|
368 | if (matrix[i][i] <= sum) { |
| 85 | return false; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | return true; | ||
| 89 | } | ||
| 90 | |||
| 91 | } // namespace romanova_v_jacobi_method | ||
| 92 |