| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "baranov_a_dijkstra_crs/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <functional> | ||
| 5 | #include <limits> | ||
| 6 | #include <queue> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "baranov_a_dijkstra_crs/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace baranov_a_dijkstra_crs { | ||
| 13 | |||
| 14 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | BaranovADijkstraCRSSEQ::BaranovADijkstraCRSSEQ(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | GetInput() = in; |
| 17 | 112 | GetOutput() = std::vector<double>(); | |
| 18 | 112 | } | |
| 19 | |||
| 20 | 112 | bool BaranovADijkstraCRSSEQ::ValidationImpl() { | |
| 21 | const auto &input = GetInput(); | ||
| 22 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | if (input.num_vertices <= 0) { |
| 23 | return false; | ||
| 24 | } | ||
| 25 |
2/4✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112 times.
✗ Branch 3 not taken.
|
112 | if (input.source_vertex < 0 || input.source_vertex >= input.num_vertices) { |
| 26 | return false; | ||
| 27 | } | ||
| 28 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
|
112 | if (input.offsets.size() != static_cast<std::size_t>(input.num_vertices) + 1) { |
| 29 | ✗ | return false; | |
| 30 | } | ||
| 31 | return true; | ||
| 32 | } | ||
| 33 | |||
| 34 | 112 | bool BaranovADijkstraCRSSEQ::PreProcessingImpl() { | |
| 35 | 112 | return true; | |
| 36 | } | ||
| 37 | |||
| 38 | 112 | bool BaranovADijkstraCRSSEQ::RunImpl() { | |
| 39 | const auto &graph = GetInput(); | ||
| 40 | 112 | const int n = graph.num_vertices; | |
| 41 | 112 | const int source = graph.source_vertex; | |
| 42 | 112 | std::vector<double> dist(n, std::numeric_limits<double>::infinity()); | |
| 43 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | dist[source] = 0.0; |
| 44 | |||
| 45 | std::priority_queue<std::pair<double, int>, std::vector<std::pair<double, int>>, std::greater<>> pq; | ||
| 46 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | pq.emplace(0.0, source); |
| 47 | |||
| 48 |
1/4✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
112 | std::vector<bool> visited(n, false); |
| 49 | |||
| 50 |
2/2✓ Branch 0 taken 432 times.
✓ Branch 1 taken 112 times.
|
544 | while (!pq.empty()) { |
| 51 | 432 | auto [current_dist, u] = pq.top(); | |
| 52 | 432 | pq.pop(); | |
| 53 | |||
| 54 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 384 times.
|
432 | if (visited[u]) { |
| 55 | continue; | ||
| 56 | } | ||
| 57 | visited[u] = true; | ||
| 58 | |||
| 59 | 384 | int start = graph.offsets[u]; | |
| 60 | 384 | int end = graph.offsets[u + 1]; | |
| 61 | |||
| 62 |
2/2✓ Branch 0 taken 448 times.
✓ Branch 1 taken 384 times.
|
832 | for (int idx = start; idx < end; ++idx) { |
| 63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 448 times.
|
448 | int v = graph.columns[idx]; |
| 64 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 448 times.
|
448 | double weight = graph.values[idx]; |
| 65 | |||
| 66 |
2/2✓ Branch 0 taken 336 times.
✓ Branch 1 taken 112 times.
|
448 | if (!visited[v]) { |
| 67 | 336 | double new_dist = current_dist + weight; | |
| 68 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 16 times.
|
336 | if (new_dist < dist[v]) { |
| 69 | 320 | dist[v] = new_dist; | |
| 70 |
1/2✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
|
320 | pq.emplace(new_dist, v); |
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | GetOutput() = dist; |
| 77 | 112 | return true; | |
| 78 | } | ||
| 79 | |||
| 80 | 112 | bool BaranovADijkstraCRSSEQ::PostProcessingImpl() { | |
| 81 | 112 | return true; | |
| 82 | } | ||
| 83 | |||
| 84 | } // namespace baranov_a_dijkstra_crs | ||
| 85 |