Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue ksp 1891 #2365

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/pgRouting/pgrouting/issues/1891>`__:
pgr_ksp doesn't give all correct shortest path

.. rubric:: New proposed functions

* With points
Expand Down
2 changes: 1 addition & 1 deletion include/yen/pgr_ksp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions pgtap/ksp/ksp/edge_cases/issue_1891.pg
Original file line number Diff line number Diff line change
@@ -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;