Astar bdastar using new process and driver for astar like functions#3066
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughRefactors A* into a process/driver pattern: adds Changes
Sequence Diagram(s)sequenceDiagram
participant SQL as Client SQL (_pgr_astar/_pgr_bdAstar)
participant Proc as pgr_process_astar (C extern "C")
participant SPI as PostgreSQL SPI
participant Driver as pgrouting::drivers::do_astar (C++)
participant Algo as A*/BD-A* algorithm
SQL->>Proc: invoke pgr_process_astar(edges_sql, combinations_sql, starts, ends, flags...)
Proc->>SPI: SPI_connect() and execute combination/edge SQL
Proc->>Driver: do_astar(..., &return_tuples, &return_count, log, notice, err)
Driver->>Algo: dispatch & run A* or BD-A* based on Which/directedness
Algo-->>Driver: return path results
Driver-->>Proc: populate return_tuples/return_count and message streams
Proc->>SPI: SPI_finish()
Proc-->>SQL: return SRF tuples or propagate errors/notices
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 7
🤖 Fix all issues with AI agents
In `@doc/src/release_notes.rst`:
- Line 47: Fix the typographical errors in the release note entry for
:issue:`3064`: replace "create an use a process & driverAstar" with "create and
use a process & driver Astar" so "an" -> "and" and insert a space between
"driver" and "Astar" (preserve the surrounding punctuation and capitalization
for the Astar reference).
In `@include/c_common/enums.h`:
- Around line 39-42: Fix the comment spacing next to the enum declarations by
adding a space before the closing comment delimiter so the inline comment reads
"with edges that have x y */" properly; update the comment adjacent to the ASTAR
and BDASTAR enum entries (ASTAR, BDASTAR) to include the missing space before
"*/".
In `@src/astar/astar_driver.cpp`:
- Around line 32-36: The file is missing the <utility> header required for
std::pair used in the catch block (e.g., the pair referenced around the catch
using std::pair at line ~167); add `#include` <utility> to the top include list in
astar_driver.cpp (alongside <vector>, <string>, etc.) so the build/ci stops
failing due to the missing declaration.
In `@src/astar/astar_process.cpp`:
- Around line 94-98: The outer condition already ensures (*result_tuples) is
non-null, so remove the redundant inner check and always free the buffer when
entering that branch: inside the existing if (!err.str().empty() &&
(*result_tuples)) branch call pfree(*result_tuples) directly, then set
(*result_tuples) = nullptr and (*result_count) = 0; reference the variables err,
result_tuples, result_count and the pfree call in astar_process.cpp when making
this simplification.
- Around line 36-37: The C++ headers <string> and <sstream> are currently placed
after the extern "C" block of project headers which violates the project's
include order; fix by moving the C++ system headers (<string>, <sstream>) so
they appear after the matching header and any C system headers but before the
project headers inside/after the extern "C" block in astar_process.cpp; ensure
the extern "C" block contains only C or project headers and that <string> and
<sstream> are outside/above that block to satisfy cpplint ordering.
In `@src/cpp_common/combinations.cpp`:
- Around line 161-162: Replace the asymmetric ternary null-checks for starts and
ends with the same symmetric guard used earlier: check both startsArr and
endsArr together before assigning; e.g., if (startsArr && endsArr) { starts =
normal ? get_intSet(startsArr) : get_intSet(endsArr); ends = normal ?
get_intSet(endsArr) : get_intSet(startsArr); } else leave starts/ends as empty
std::set<int64_t>(); — this ensures safe use of get_intSet with
startsArr/endsArr (variables: startsArr, endsArr, normal, get_intSet, starts,
ends).
In `@src/cpp_common/utilities.cpp`:
- Around line 97-115: The BDASTAR branch in get_name builds suffix using
(is_matrix? "Matrix" : "") which can produce invalid "pgr_bdAstarMatrix" when
is_only_cost is false; change the BDASTAR suffix construction to mirror ASTAR
and DIJKSTRA (only append "Matrix" when is_only_cost && is_matrix). Update the
BDASTAR case in get_name to use std::string(is_only_cost? "Cost" : "") +
(is_only_cost && is_matrix? "Matrix" : ""), and apply the same guard to the
BDDIJKSTRA/BD* overloads that currently use is_matrix alone so all mirrored
pairs use is_only_cost && is_matrix for the "Matrix" suffix.
9ea5a88 to
5d6e503
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/astar/astar_driver.cpp`:
- Line 107: The debug log in astar_driver.cpp uses the stream expression log <<
"is matrix" << is_matrix which concatenates the literal and boolean without
spacing; update the log expression that writes the "is matrix" message (the log
stream usage near the is_matrix variable) to include a separator (e.g., a
trailing space or colon) between the string and the is_matrix value so output
becomes "is matrix 1" or "is matrix: 1".
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@locale/en/LC_MESSAGES/pgrouting_doc_strings.po`:
- Around line 3954-3957: The release-note msgid in
locale/en/LC_MESSAGES/pgrouting_doc_strings.po contains a typo ("create an use a
process & driverAstar"); fix the wording in the original release notes/NEWS
source (not the .po) so the corrected English string replaces that msgid (e.g.,
change to something like "create and use a process & driverAstar" or clearer
wording) and then regenerate the locale files (run the project's gettext/locale
extraction and compile steps or use the Weblate workflow) so the .po/.mo are
updated from the source rather than editing pgrouting_doc_strings.po directly.
6db7f1d to
3d2e90a
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@sql/bdAstar/bdAstarCostMatrix.sql`:
- Line 49: The test suite is missing a pgtap test for the edge case where
end_vids is empty while is_cost_matrix=true; add a pgtap test file named
no_crash_test.pg to the bdAstarCostMatrix tests that calls pgr_bdAstarCostMatrix
(which invokes _pgr_bdAstar and get_combinations()) with empty end_vids to
verify it falls back to using start_vids and does not return zero rows or crash;
ensure the test covers null/empty parameter handling and uses the same
assertions pattern as astarCostMatrix's no_crash_test.pg.
In `@src/astar/astar_process.cpp`:
- Around line 94-96: On the error path where err.str() is non-empty, free the
allocated result buffer pointed to by *result_tuples, set *result_tuples to
nullptr and then set *result_count = 0; locate the block referencing err.str(),
(*result_tuples) and (*result_count) in astar_process.cpp and mirror the cleanup
used by other process files (use the same deallocator used elsewhere in the
codebase, e.g., pfree or the project's result buffer free helper) so the pointer
is freed and nulled before resetting the count.
In `@src/cpp_common/combinations.cpp`:
- Around line 161-165: The code declares std::set<int64_t> end but later uses
ends; change the declaration to std::set<int64_t> ends so it matches usage, and
ensure the assignments that use startsArr, endsArr, normal and get_intSet remain
consistent (starts = normal ? get_intSet(startsArr) : get_intSet(endsArr); ends
= normal ? get_intSet(endsArr) : get_intSet(startsArr);) to avoid the undeclared
identifier compilation error.
In `@src/cpp_common/utilities.cpp`:
- Around line 103-106: The ASTAR case sets base to "pgr_astar" which mismatches
the actual function name; update the ASTAR branch so base is "pgr_aStar"
(matching pgr_bdAstar's camelCase style) — locate the ASTAR case in
utilities.cpp where base is assigned and replace "pgr_astar" with "pgr_aStar" so
generated names like suffix combos (e.g., in the variables base and suffix)
produce correct diagnostics such as "pgr_aStarCost".
| case ASTAR : | ||
| base = "pgr_astar"; | ||
| suffix = std::string(is_only_cost? "Cost" : "") + (is_only_cost && is_matrix? "Matrix" : ""); | ||
| break; |
There was a problem hiding this comment.
"pgr_astar" should be "pgr_aStar" to match the actual function name.
pgr_bdAstar (line 108) correctly uses camelCase, but ASTAR uses all-lowercase pgr_astar. This would produce misleading names in timing/diagnostic messages (e.g., "pgr_astarCost" instead of "pgr_aStarCost").
🔧 Proposed fix
case ASTAR :
- base = "pgr_astar";
+ base = "pgr_aStar";
suffix = std::string(is_only_cost? "Cost" : "") + (is_only_cost && is_matrix? "Matrix" : "");
break;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/cpp_common/utilities.cpp` around lines 103 - 106, The ASTAR case sets
base to "pgr_astar" which mismatches the actual function name; update the ASTAR
branch so base is "pgr_aStar" (matching pgr_bdAstar's camelCase style) — locate
the ASTAR case in utilities.cpp where base is assigned and replace "pgr_astar"
with "pgr_aStar" so generated names like suffix combos (e.g., in the variables
base and suffix) produce correct diagnostics such as "pgr_aStarCost".
86634e6 to
5dda786
Compare
There was a problem hiding this comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/astar/astar_process.cpp`:
- Around line 94-96: In the error branch where you check if (!err.str().empty()
&& (*result_tuples)) in astar_process.cpp, free the allocated tuple buffer and
null it out before setting *result_count to 0 to match the other process files;
specifically call the same deallocation used elsewhere (e.g., free or the
project’s tuple-free routine) on *result_tuples, set *result_tuples = nullptr,
then set *result_count = 0 so the buffer is not leaked or double-freed later.
In `@src/cpp_common/combinations.cpp`:
- Around line 161-165: The variable was misnamed: the code declares
std::set<int64_t> end but the rest of the function uses ends; rename the
declaration to std::set<int64_t> ends (or consistently use end everywhere) so
that starts/ends are used symmetrically in the assignments that call
get_intSet(startsArr)/get_intSet(endsArr) and in subsequent references; update
the declaration near startsArr/endsArr and ensure all later usages (lines
referencing ends) match the corrected variable name.
In `@src/cpp_common/utilities.cpp`:
- Around line 103-105: The diagnostic string for ASTAR uses the wrong casing; in
the switch case for ASTAR update the base assignment (currently setting base =
"pgr_astar") to use the correct camelCase function name "pgr_aStar" so that
composed names like suffix and the final messages (from variables base and
suffix in utilities.cpp) produce "pgr_aStar..." instead of "pgr_astar...".
efdab8f to
b2e8052
Compare
Fixes #3064
Changes proposed in this pull request:
@pgRouting/admins
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation