diff --git a/NEWS b/NEWS index f94184e453b..95332b5d440 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,11 @@ pgRouting 3.4.0 Release Notes ------------------------------------------------------------------------------- +**Issue fixes** + +* [#1891](https://github.com/pgRouting/pgrouting/issues/1891): + pgr_ksp doesn't give all correct shortest path + **New proposed functions** * With points diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index eeef8a30f73..f1478c928ea 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -38,6 +38,11 @@ To see the full list of changes check the list of `Git commits pgRouting 3.4.0 Release Notes ------------------------------------------------------------------------------- +.. rubric:: Issue fixes + +* `#1891 `__: + pgr_ksp doesn't give all correct shortest path + .. rubric:: New proposed functions * With points diff --git a/include/yen/pgr_ksp.hpp b/include/yen/pgr_ksp.hpp index 5fd970dda1c..7903abee3f1 100644 --- a/include/yen/pgr_ksp.hpp +++ b/include/yen/pgr_ksp.hpp @@ -169,7 +169,7 @@ class Pgr_ksp : public Pgr_messages { auto rootPath = curr_result_path.getSubpath(i); for (const auto &path : m_ResultSet) { - if (path.isEqual(rootPath)) { + if (path.isEqual(rootPath) && spurNodeId == path[i].node) { if (path.size() > i + 1) { graph.disconnect_edge(path[i].node, // from path[i + 1].node); // to diff --git a/pgtap/ksp/ksp/edge_cases/issue_1891.pg b/pgtap/ksp/ksp/edge_cases/issue_1891.pg new file mode 100644 index 00000000000..e271ea55750 --- /dev/null +++ b/pgtap/ksp/ksp/edge_cases/issue_1891.pg @@ -0,0 +1,63 @@ +BEGIN; + +SELECT CASE WHEN min_version('3.4.0') THEN plan(2) ELSE plan(1) END; + +CREATE TABLE fiber(id SERIAL, source INT, target INT, cost FLOAT); + +INSERT INTO FIBER (source, target, cost) VALUES +(1,2,10),(2,4,10),(1,3,10),(3,4,10),(2,3,10),(1,4,10); + + +CREATE OR REPLACE FUNCTION issue_1891() RETURNS SETOF TEXT AS +$BODY$ +DECLARE + have INTEGER; +BEGIN + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'Issue fixed on 3.4.0'); + RETURN; + END IF; + +SELECT count(DISTINCT path_id) FROM +pgr_ksp('SELECT * FROM fiber', 1, 4, 10, directed => false, heap_paths => true) INTO have; + +RETURN QUERY +SELECT is(have, 5); + +prepare q2 AS +SELECT * FROM +pgr_ksp('SELECT * FROM fiber', 1, 4, 10, directed => false, heap_paths => true); + +PREPARE r2 AS +SELECT * +FROM (VALUES + (1, 1, 1, 1, 6, 10, 0), + (2, 1, 2, 4, -1, 0, 10), + (3, 2, 1, 1, 1, 10, 0), + (4, 2, 2, 2, 2, 10, 10), + (5, 2, 3, 4, -1, 0, 20), + (6, 3, 1, 1, 3, 10, 0), + (7, 3, 2, 3, 4, 10, 10), + (8, 3, 3, 4, -1, 0, 20), + (9, 4, 1, 1, 1, 10, 0), + (10,4, 2, 2, 5, 10, 10), + (11, 4, 3, 3, 4, 10, 20), + (12, 4, 4, 4, -1, 0, 30), + (13, 5, 1, 1, 3, 10, 0), + (14, 5, 2, 3, 5, 10, 10), + (15, 5, 3, 2, 2, 10, 20), + (16, 5, 4, 4, -1, 0, 30)) +AS t(seq, path_id, path_seq, node, edge, cost, agg_cost); + +RETURN QUERY +SELECT bag_eq('q2','r2','q2 should have r2 result'); + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + + +SELECT issue_1891(); + +SELECT finish(); +ROLLBACK;