Skip to content

pgr_withPoints does not pick optimal route #2966

@FrankyBoy

Description

@FrankyBoy

Problem
pgr_withPoints does not pick the optimal route if the percentage of the (in my case target) point is 1. A percentage value of 0.99 or similar yields the appropriate results.

To Reproduce

Minimal test case:

  • Three links: 100 = start, 101 and 102 are parallel with different costs (102 having the much higher cost)
  • We want to go to from the middle of our start link to the end of 101 (i.e. node 1003).
SELECT * FROM pgr_withPoints(
  'SELECT * FROM (VALUES 
    (100, 1001, 1002, 10, 10),
    (101, 1002, 1003, 12, 12),
    (102, 1002, 1003, 100, 100))
  AS t(id, source, target, cost, reverse_cost)',
  'SELECT * FROM (VALUES
    (1, 100, 0.5),
    (2, 101, 1))
  AS t(pid, edge_id, fraction)',
  -1,
  -2
)

Expectation
Routing via 100 and 101

1	1	-1	100	5	0
2	2	1002	101	12	5
3	3	-2	-1	0	17

Actual
Routing goes via link 102, which is much more expensive.

1	1	-1	100	5	0
2	2	1002	102	100	5
3	3	1003	101	0	105
4	4	-2	-1	0	105

Platform/versions

SELECT version();
> "PostgreSQL 14.13 (Debian 14.13-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit"
SELECT postgis_full_version();
> "POSTGIS=""3.5.2 dea6d0a"" [EXTENSION] PGSQL=""140"" GEOS=""3.9.0-CAPI-1.16.2"" PROJ=""7.2.1 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org USER_WRITABLE_DIRECTORY=/var/lib/postgresql/.local/share/proj DATABASE_PATH=/usr/share/proj/proj.db"" (compiled against PROJ 7.2.1) LIBXML=""2.9.10"" LIBJSON=""0.15"" LIBPROTOBUF=""1.3.3"" WAGYU=""0.5.0 (Internal)"""
SELECT pgr_version();
> "3.8.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions