Skip to content

Astar bdastar using new process and driver for astar like functions#3066

Merged
cvvergara merged 10 commits intopgRouting:developfrom
cvvergara:astar-bdastar-using-new-process-and-driver-for-astar-like-functions
Feb 19, 2026
Merged

Astar bdastar using new process and driver for astar like functions#3066
cvvergara merged 10 commits intopgRouting:developfrom
cvvergara:astar-bdastar-using-new-process-and-driver-for-astar-like-functions

Conversation

@cvvergara
Copy link
Member

@cvvergara cvvergara commented Feb 10, 2026

Fixes #3064

Changes proposed in this pull request:

  • Creates a new process-driver pair for astar like functions
  • Makes astar and bdastar to use the shortest_path driver/process
  • Removes unused code of astar and bdastar because of the change
  • Updates news and release notes about the change

@pgRouting/admins

Summary by CodeRabbit

  • New Features

    • Added A* and bidirectional A* routing modes with a new process/driver integration for A* workflows.
  • Bug Fixes

    • Improved input validation and clearer error/notice/log messaging for empty-edge, parameter, and heuristic cases.
  • Tests

    • Added and expanded tests covering empty-edge scenarios and matrix/combinations behavior.
  • Documentation

    • Updated release notes, translations, and user-facing docs to reference the A* additions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Refactors A* into a process/driver pattern: adds ASTAR and BDASTAR enum values, introduces pgr_process_astar (C API) and pgrouting::drivers::do_astar (C++), moves algorithm logic into driver/process pair, updates utilities, tests, build files, and removes the legacy bdAstar driver source.

Changes

Cohort / File(s) Summary
Release Notes
NEWS.md, doc/src/release_notes.rst
Added release-note entry documenting Astar process & driver (issue #3064).
Enums & Utilities
include/c_common/enums.h, include/cpp_common/utilities.hpp, src/cpp_common/utilities.cpp
Added ASTAR and BDASTAR to enum Which; added get_name(Which,bool,bool) overload and adjusted name/driving-side logic.
Combinations Logic
src/cpp_common/combinations.cpp
Changed get_combinations signature to add bool &is_matrix; initialize starts/ends only when present and refine matrix detection/normalization.
Driver Headers
include/drivers/astar_driver.hpp
New C++ header declaring pgrouting::drivers::do_astar with std::string inputs, reference/ostringstream outputs, and forward declarations for Path_rt/ArrayType.
Process Header
include/process/astar_process.h
New process header declaring pgr_process_astar and C/C++ aliases for Path_rt/ArrayType; updated guards/includes.
Driver Implementations
src/astar/astar_driver.cpp, src/bdAstar/bdAstar_driver.cpp (deleted)
Implemented C++ driver do_astar (namespaced, refactored inputs/outputs); removed legacy bdAstar_driver.cpp.
Process Implementation
src/astar/astar_process.cpp
New extern "C" implementation pgr_process_astar that manages SPI, timing, calls the C++ driver, and reports messages.
SRF Entrypoints
src/astar/astar.c, src/bdAstar/bdAstar.c
Replaced inlined/static process logic with calls to pgr_process_astar, remapping arguments for many-to-many and combinations modes.
Build Files
src/astar/CMakeLists.txt, src/bdAstar/CMakeLists.txt
Added astar_process.cpp to astar target; removed bdAstar_driver.cpp from bdAstar target.
SQL Updates
sql/astar/astarCostMatrix.sql, sql/bdAstar/bdAstarCostMatrix.sql
Adjusted internal calls to pass explicit BIGINT[] or an empty BIGINT[] for end_vids.
Tests
pgtap/astar/*/no_crash_test.pg
Added tests for empty-edge scenarios (throw_on_empty_edges_sql), updated plan counts and minor test renames.
Tooling & Localization
tools/scripts/code_checker.sh, locale/*
Added include-order entry for new source; added translation/pot entries for issue #3064.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested labels

Enhancement, C/C++

Suggested reviewers

  • robe2
  • iosefa
  • krashish8

Poem

🐰 I hopped through enums and drivers bright,
Split the process, named the paths just right,
Streams of logs and tuples in tow,
A* and BD-A* now ready to go,
A rabbit cheers: onward, hop and write!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: creating a new process and driver for astar-like functions and making both astar and bdastar use them.
Linked Issues check ✅ Passed The PR fulfills all coding objectives from issue #3064: creates shared process/driver for A*-like functions, integrates them into astar and bdastar, and removes redundant code.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the PR objectives and issue #3064 requirements; no unrelated or out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

@cvvergara cvvergara force-pushed the astar-bdastar-using-new-process-and-driver-for-astar-like-functions branch from 9ea5a88 to 5d6e503 Compare February 10, 2026 16:07
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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".

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

@cvvergara cvvergara requested a review from robe2 February 12, 2026 03:00
@cvvergara cvvergara force-pushed the astar-bdastar-using-new-process-and-driver-for-astar-like-functions branch 2 times, most recently from 6db7f1d to 3d2e90a Compare February 19, 2026 13:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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".

Comment on lines +103 to +106
case ASTAR :
base = "pgr_astar";
suffix = std::string(is_only_cost? "Cost" : "") + (is_only_cost && is_matrix? "Matrix" : "");
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

"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".

@cvvergara cvvergara force-pushed the astar-bdastar-using-new-process-and-driver-for-astar-like-functions branch from 86634e6 to 5dda786 Compare February 19, 2026 13:51
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🤖 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...".

@cvvergara cvvergara marked this pull request as draft February 19, 2026 14:00
@cvvergara cvvergara force-pushed the astar-bdastar-using-new-process-and-driver-for-astar-like-functions branch from efdab8f to b2e8052 Compare February 19, 2026 14:08
@cvvergara cvvergara marked this pull request as ready for review February 19, 2026 16:07
@cvvergara cvvergara merged commit 56417bd into pgRouting:develop Feb 19, 2026
64 checks passed
@cvvergara cvvergara deleted the astar-bdastar-using-new-process-and-driver-for-astar-like-functions branch February 19, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Astar: create an use a process & driver

2 participants