| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "olesnitskiy_v_dijkstra_crs/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <functional> | ||
| 4 | #include <limits> | ||
| 5 | #include <queue> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "olesnitskiy_v_dijkstra_crs/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace olesnitskiy_v_dijkstra_crs { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | OlesnitskiyVDijkstraCrsSEQ::OlesnitskiyVDijkstraCrsSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 112 | GetOutput() = std::vector<int>(); | |
| 17 | 112 | } | |
| 18 | |||
| 19 | 112 | bool OlesnitskiyVDijkstraCrsSEQ::ValidationImpl() { | |
| 20 | const auto &input = GetInput(); | ||
| 21 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | int source = std::get<0>(input); |
| 22 | const auto &offsets = std::get<1>(input); | ||
| 23 | const auto &edges = std::get<2>(input); | ||
| 24 | const auto &weights = std::get<3>(input); | ||
| 25 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | if (offsets.empty()) { |
| 26 | return false; | ||
| 27 | } | ||
| 28 | 112 | int vertices = static_cast<int>(offsets.size()) - 1; | |
| 29 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | if (vertices <= 0) { |
| 30 | return false; | ||
| 31 | } | ||
| 32 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | if (source < 0 || source >= vertices) { |
| 33 | return false; | ||
| 34 | } | ||
| 35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
|
112 | if (edges.size() != weights.size()) { |
| 36 | ✗ | return false; | |
| 37 | } | ||
| 38 | return true; | ||
| 39 | } | ||
| 40 | |||
| 41 | 112 | bool OlesnitskiyVDijkstraCrsSEQ::PreProcessingImpl() { | |
| 42 | 112 | return true; | |
| 43 | } | ||
| 44 | |||
| 45 | 112 | bool OlesnitskiyVDijkstraCrsSEQ::RunImpl() { | |
| 46 | const auto &input = GetInput(); | ||
| 47 | 112 | int source = std::get<0>(input); | |
| 48 | const auto &offsets = std::get<1>(input); | ||
| 49 | const auto &edges = std::get<2>(input); | ||
| 50 | const auto &weights = std::get<3>(input); | ||
| 51 | 112 | int vertices = static_cast<int>(offsets.size()) - 1; | |
| 52 | |||
| 53 | 112 | std::vector<int> distances(vertices, std::numeric_limits<int>::max()); | |
| 54 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | distances[source] = 0; |
| 55 | |||
| 56 | using DistVertex = std::pair<int, int>; | ||
| 57 | std::priority_queue<DistVertex, std::vector<DistVertex>, std::greater<>> pq; | ||
| 58 |
1/4✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
112 | pq.emplace(0, source); |
| 59 | |||
| 60 |
2/2✓ Branch 0 taken 672 times.
✓ Branch 1 taken 112 times.
|
784 | while (!pq.empty()) { |
| 61 | 672 | auto [current_dist, u] = pq.top(); | |
| 62 | 672 | pq.pop(); | |
| 63 | |||
| 64 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 648 times.
|
672 | if (current_dist > distances[u]) { |
| 65 | continue; | ||
| 66 | } | ||
| 67 | |||
| 68 | 648 | int start = offsets[u]; | |
| 69 | 648 | int end = offsets[u + 1]; | |
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 648 times.
|
2136 | for (int i = start; i < end; ++i) { |
| 72 |
2/2✓ Branch 0 taken 560 times.
✓ Branch 1 taken 928 times.
|
1488 | int v = edges[i]; |
| 73 | 1488 | int weight = weights[i]; | |
| 74 | 1488 | int new_dist = current_dist + weight; | |
| 75 | |||
| 76 |
2/2✓ Branch 0 taken 560 times.
✓ Branch 1 taken 928 times.
|
1488 | if (new_dist < distances[v]) { |
| 77 | 560 | distances[v] = new_dist; | |
| 78 |
1/2✓ Branch 1 taken 560 times.
✗ Branch 2 not taken.
|
560 | pq.emplace(new_dist, v); |
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | GetOutput() = distances; |
| 84 | 112 | return true; | |
| 85 | } | ||
| 86 | |||
| 87 | 112 | bool OlesnitskiyVDijkstraCrsSEQ::PostProcessingImpl() { | |
| 88 | 112 | return true; | |
| 89 | } | ||
| 90 | } // namespace olesnitskiy_v_dijkstra_crs | ||
| 91 |