Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/k_shortest_paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ std::vector<std::pair<std::vector<Cost>, PredDAG>> k_shortest_paths(
for (std::size_t v = 1; v < dag.parent_offsets.size(); ++v) dag.parent_offsets[v] += dag.parent_offsets[v-1];
dag.parents.resize(static_cast<std::size_t>(dag.parent_offsets.back()));
dag.via_edges.resize(static_cast<std::size_t>(dag.parent_offsets.back()));
std::size_t idx = 0;
for (std::size_t i = 1; i < P.nodes.size(); ++i) {
dag.parents[idx] = P.nodes[i-1]; dag.via_edges[idx] = P.edges[i-1]; ++idx;
auto v = P.nodes[i];
auto base = static_cast<std::size_t>(dag.parent_offsets[static_cast<std::size_t>(v)]);
dag.parents[base] = P.nodes[i-1]; dag.via_edges[base] = P.edges[i-1];
}
Comment on lines 206 to 210
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a regression test that validates the returned PredDAG encodes the concrete path in true CSR form (parents/via_edges stored in the range parent_offsets[v]:parent_offsets[v+1] for each node v). The previous sequential fill could pass basic size/monotonicity checks but still produce incorrect parent lookups; a test that reconstructs the path from the DAG (e.g., via resolve_to_paths or by directly checking parents[parent_offsets[v]]) on a path whose node IDs are not in increasing order would catch this.

Copilot uses AI. Check for mistakes.
}
items.emplace_back(std::move(dist), std::move(dag));
Expand Down Expand Up @@ -249,7 +250,7 @@ std::vector<std::pair<std::vector<Cost>, PredDAG>> k_shortest_paths(
std::vector<std::uint8_t> edge_mask_local;
edge_mask_local.assign(static_cast<std::size_t>(g.num_edges()), static_cast<std::uint8_t>(1));
for (auto const& P : paths) {
if (P.nodes.size() > j && std::equal(P.nodes.begin(), P.nodes.begin() + j, last.nodes.begin())) {
if (P.nodes.size() > j && std::equal(P.nodes.begin(), P.nodes.begin() + static_cast<std::ptrdiff_t>(j + 1), last.nodes.begin())) {
// Exclude edge at position j for this path
if (P.edges.size() > j) {
edge_mask_local[static_cast<std::size_t>(P.edges[j])] = 0;
Expand Down Expand Up @@ -337,9 +338,10 @@ std::vector<std::pair<std::vector<Cost>, PredDAG>> k_shortest_paths(
for (std::size_t v = 1; v < dag.parent_offsets.size(); ++v) dag.parent_offsets[v] += dag.parent_offsets[v-1];
dag.parents.resize(static_cast<std::size_t>(dag.parent_offsets.back()));
dag.via_edges.resize(static_cast<std::size_t>(dag.parent_offsets.back()));
std::size_t idx = 0;
for (std::size_t i = 1; i < P.nodes.size(); ++i) {
dag.parents[idx] = P.nodes[i-1]; dag.via_edges[idx] = P.edges[i-1]; ++idx;
auto v = P.nodes[i];
auto base = static_cast<std::size_t>(dag.parent_offsets[static_cast<std::size_t>(v)]);
dag.parents[base] = P.nodes[i-1]; dag.via_edges[base] = P.edges[i-1];
}
}
items.emplace_back(std::move(dist), std::move(dag));
Expand Down