Skip to content

(pickDeliver) end_node_id ignored when end_service is omitted - #3178

Closed
Sankalp-2711 wants to merge 3 commits into
pgRouting:developfrom
Sankalp-2711:fix/pickdeliver-end-node-id
Closed

Sankalp-2711 wants to merge 3 commits into
pgRouting:developfrom
Sankalp-2711:fix/pickdeliver-end-node-id

Conversation

@Sankalp-2711

@Sankalp-2711 Sankalp-2711 commented Oct 28, 2026 •

Copy link
Copy Markdown

Changes proposed in this pull request:

  • pgr_pickDeliver: end_node_id was ignored when the vehicles query did not
    also include end_service. In fetch_vehicle, the check was
    column_found(info[12]) (end_service) but the value read was info[15]
    (end_node_id). The check now uses info[15].
  • Adds a pgTAP regression test in pgtap/pickDeliver/pickDeliver/inner_query.pg.

Reproduce (before the fix)

Line graph 1-2-3-4, one order (pickup 2, delivery 3), one vehicle with
start_node_id = 1, end_node_id = 4, end_open, end_close, and no
end_service. The route ends at node 1, so end_node_id is ignored:

 stop_seq | stop_type | stop_id | travel_time
        6 |         6 |       1 |           2

Adding 0 AS end_service to the vehicles query makes the route end at node 4:

 stop_seq | stop_type | stop_id | travel_time
        6 |         6 |       4 |           1

After this change both queries end at node 4.

SQL used
CREATE TEMP TABLE edges (id BIGINT, source BIGINT, target BIGINT, cost FLOAT, reverse_cost FLOAT);
INSERT INTO edges VALUES (1,1,2,1,1), (2,2,3,1,1), (3,3,4,1,1);

CREATE TEMP TABLE orders (id BIGINT, demand FLOAT,
  p_node_id BIGINT, p_open FLOAT, p_close FLOAT, p_service FLOAT,
  d_node_id BIGINT, d_open FLOAT, d_close FLOAT, d_service FLOAT);
INSERT INTO orders VALUES (1, 10, 2, 0, 100, 1, 3, 0, 100, 1);

CREATE TEMP TABLE vehicles (id BIGINT, capacity FLOAT,
  start_node_id BIGINT, start_open FLOAT, start_close FLOAT,
  end_node_id BIGINT, end_open FLOAT, end_close FLOAT);
INSERT INTO vehicles VALUES (1, 100, 1, 0, 100, 4, 0, 100);

SELECT seq, vehicle_id, stop_seq, stop_type, stop_id, travel_time, departure_time
FROM pgr_pickDeliver(
  $$SELECT id, demand, p_node_id, p_open, p_close, p_service,
           d_node_id, d_open, d_close, d_service FROM orders$$,
  $$SELECT id, capacity, start_node_id, start_open, start_close,
           end_node_id, end_open, end_close FROM vehicles$$,
  $$SELECT * FROM pgr_dijkstraCostMatrix(
      'SELECT id, source, target, cost, reverse_cost FROM edges',
      ARRAY[1,2,3,4])$$);

Behavior change

Anyone who passed end_node_id without end_service was silently getting the
start node as the end node. They now get the specified end node.

The test checks that every route ends at the requested node when end_service
is omitted. It fails without the fix and passes with it.

@pgRouting/admins

Summary by CodeRabbit

  • Bug Fixes
    • Corrected vehicle end-node handling when no end service is specified. Delivery plans now respect the vehicle’s configured destination instead of defaulting to its start node, keeping the final route stops aligned with the requested endpoint. This makes route results more consistent for vehicles that have a designated end node but no end-service time configured.

fetch_vehicle checked column_found(info[12]) (end_service) before reading
info[15] (end_node_id), so end_node_id was only honored when end_service
was also given. Check the end_node_id column instead.

Adds a pgTAP regression test.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

fetch_vehicle now checks the correct column for the optional end-node ID. A pgTAP test checks pgr_pickDeliver when end_service is omitted.

Changes

End-node handling

Layer / File(s) Summary
Correct end-node lookup and regression test
src/cpp_common/pgdata_fetchers.cpp, pgtap/pickDeliver/pickDeliver/inner_query.pg
fetch_vehicle checks column 15 for the end-node ID. The new test checks that, when end_service is omitted, stops with stop_type = 6 include the first order’s pickup node.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: cvvergara

Merge Risk: Minimal · up to 02948

pgr_pickDeliver now ends routes at the requested end node when end_service is omitted, instead of silently ending them at the start node. The change is small and has a regression test, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "(pickDeliver) end_node_id ignored when end_service is omitted" matches the main change. The PR changes fetch_vehicle to check for end_node_id at column 15 instead of checking end_service at…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "(pickDeliver) end_node_id ignored when end_service is omitted" matches the main change. The PR changes fetch_vehicle to check for end_node_id at column 15 instead of checking end_service at column 12. Before the fix, routes with end_node_id but no end_service ended at the start node. The title names the affected function area and the specific bug. The added pgTAP test covers this same case.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the node in place,
Then tests the stops along the trace.
With service left unstated,
The pickup node is validated.
The burrow’s plans now pass the test. <fixed_issue_severity>Low</fixed_issue_severity>

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5c6f1b39-20c9-4c5f-9361-9e9e28e5f730
Commits

Reviewing files that changed from the base of the PR and between 537c538 and 02948e1.

Files selected for processing: 1

  • pgtap/pickDeliver/pickDeliver/inner_query.pg

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@cvvergara

Copy link
Copy Markdown
Member

I dont understand the purpose of your PR that only adds a tap test.
Maybe the problem was fixed while we were doing the upgrade of the function on #3189

Regards.

@cvvergara cvvergara closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants