| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "klimenko_v_multistep_2d_parallel_sad/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <limits> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "klimenko_v_multistep_2d_parallel_sad/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace klimenko_v_multistep_2d_parallel_sad { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | KlimenkoV2DParallelSadSEQ::KlimenkoV2DParallelSadSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 24 | GetOutput() = OutType{}; | |
| 17 | 24 | } | |
| 18 | |||
| 19 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | bool KlimenkoV2DParallelSadSEQ::ValidationImpl() { |
| 20 | const auto &in = GetInput(); | ||
| 21 | |||
| 22 |
5/10✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 24 times.
✗ Branch 9 not taken.
|
24 | return in.func != nullptr && in.x_min < in.x_max && in.y_min < in.y_max && in.epsilon > 0.0 && in.r_param > 1.0 && |
| 23 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | in.max_iterations > 0; |
| 24 | } | ||
| 25 | |||
| 26 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | bool KlimenkoV2DParallelSadSEQ::PreProcessingImpl() { |
| 27 | regions_.clear(); | ||
| 28 | |||
| 29 | const auto &in = GetInput(); | ||
| 30 | |||
| 31 | 24 | Region init{}; | |
| 32 | 24 | init.x_min = in.x_min; | |
| 33 | 24 | init.x_max = in.x_max; | |
| 34 | 24 | init.y_min = in.y_min; | |
| 35 | 24 | init.y_max = in.y_max; | |
| 36 | |||
| 37 | 24 | double xc = 0.5 * (init.x_min + init.x_max); | |
| 38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | double yc = 0.5 * (init.y_min + init.y_max); |
| 39 | 24 | init.f_center = in.func(xc, yc); | |
| 40 | init.characteristic = 0.0; | ||
| 41 | |||
| 42 | 24 | regions_.push_back(init); | |
| 43 | 24 | return true; | |
| 44 | } | ||
| 45 | |||
| 46 | 24 | bool KlimenkoV2DParallelSadSEQ::RunImpl() { | |
| 47 | const auto &in = GetInput(); | ||
| 48 | auto &out = GetOutput(); | ||
| 49 | |||
| 50 |
2/2✓ Branch 0 taken 360 times.
✓ Branch 1 taken 24 times.
|
384 | for (int iter = 0; iter < in.max_iterations; ++iter) { |
| 51 |
2/2✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 360 times.
|
3240 | for (auto &r : regions_) { |
| 52 | 2880 | r.characteristic = ComputeCharacteristic(r); | |
| 53 | } | ||
| 54 | |||
| 55 | auto best_it = std::ranges::max_element( | ||
| 56 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 2368 times.
|
2520 | regions_, [](const Region &a, const Region &b) { return a.characteristic < b.characteristic; }); |
| 57 | |||
| 58 | 360 | Region best = *best_it; | |
| 59 | |||
| 60 | 360 | double dx = best.x_max - best.x_min; | |
| 61 | 360 | double dy = best.y_max - best.y_min; | |
| 62 | |||
| 63 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 360 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
360 | if (dx < in.epsilon && dy < in.epsilon) { |
| 64 | ✗ | out.converged = true; | |
| 65 | ✗ | out.iterations = iter + 1; | |
| 66 | ✗ | break; | |
| 67 | } | ||
| 68 | |||
| 69 | regions_.erase(best_it); | ||
| 70 | |||
| 71 | auto [r1, r2] = SplitRegion(best); | ||
| 72 | |||
| 73 | 720 | auto eval = [&](Region &r) { | |
| 74 | 720 | double xc = 0.5 * (r.x_min + r.x_max); | |
| 75 | 720 | double yc = 0.5 * (r.y_min + r.y_max); | |
| 76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 720 times.
|
720 | r.f_center = in.func(xc, yc); |
| 77 | 1080 | }; | |
| 78 | |||
| 79 | 360 | eval(r1); | |
| 80 | 360 | eval(r2); | |
| 81 | |||
| 82 | 360 | regions_.push_back(r1); | |
| 83 | 360 | regions_.push_back(r2); | |
| 84 | |||
| 85 | 360 | out.iterations = iter + 1; | |
| 86 | } | ||
| 87 | |||
| 88 | 24 | return true; | |
| 89 | } | ||
| 90 | |||
| 91 | 24 | bool KlimenkoV2DParallelSadSEQ::PostProcessingImpl() { | |
| 92 | auto &out = GetOutput(); | ||
| 93 | |||
| 94 | double best_val = std::numeric_limits<double>::max(); | ||
| 95 | |||
| 96 |
2/2✓ Branch 0 taken 384 times.
✓ Branch 1 taken 24 times.
|
408 | for (const auto &r : regions_) { |
| 97 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 296 times.
|
384 | if (r.f_center < best_val) { |
| 98 | best_val = r.f_center; | ||
| 99 | 88 | out.func_min = r.f_center; | |
| 100 | 88 | out.x_opt = 0.5 * (r.x_min + r.x_max); | |
| 101 | 88 | out.y_opt = 0.5 * (r.y_min + r.y_max); | |
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | 24 | return true; | |
| 106 | } | ||
| 107 | |||
| 108 | 2880 | double KlimenkoV2DParallelSadSEQ::ComputeCharacteristic(const Region &r) { | |
| 109 | const auto &in = GetInput(); | ||
| 110 | |||
| 111 | 2880 | double dx = r.x_max - r.x_min; | |
| 112 | 2880 | double dy = r.y_max - r.y_min; | |
| 113 | |||
| 114 | 2880 | return -r.f_center + (in.r_param * std::sqrt((dx * dx) + (dy * dy))); | |
| 115 | } | ||
| 116 | |||
| 117 | ✗ | std::pair<Region, Region> KlimenkoV2DParallelSadSEQ::SplitRegion(const Region &r) { | |
| 118 | ✗ | Region r1 = r; | |
| 119 | Region r2 = r; | ||
| 120 | |||
| 121 |
2/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✓ Branch 3 taken 192 times.
|
360 | if ((r.x_max - r.x_min) >= (r.y_max - r.y_min)) { |
| 122 | 168 | double xm = 0.5 * (r.x_min + r.x_max); | |
| 123 | r1.x_max = xm; | ||
| 124 | r2.x_min = xm; | ||
| 125 | } else { | ||
| 126 | 192 | double ym = 0.5 * (r.y_min + r.y_max); | |
| 127 | r1.y_max = ym; | ||
| 128 | r2.y_min = ym; | ||
| 129 | } | ||
| 130 | |||
| 131 | ✗ | return {r1, r2}; | |
| 132 | } | ||
| 133 | |||
| 134 | } // namespace klimenko_v_multistep_2d_parallel_sad | ||
| 135 |