From 64f8fc26bd9ca00b4c055052b8749ee74f72a379 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Fri, 18 Feb 2022 13:36:24 -0600 Subject: [PATCH 01/10] [pgtap] organizing tests for via functions --- tools/developer/taptest.sh | 1 + tools/testers/setup_db.sh | 1 + tools/testers/trsp_tests.sql | 73 ----------------- tools/testers/types_check.sql | 4 +- tools/testers/via_compare.sql | 144 ++++++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+), 75 deletions(-) create mode 100644 tools/testers/via_compare.sql diff --git a/tools/developer/taptest.sh b/tools/developer/taptest.sh index 674f46f73d7..14c498437cf 100755 --- a/tools/developer/taptest.sh +++ b/tools/developer/taptest.sh @@ -58,6 +58,7 @@ do -f trsp_tests.sql \ -f spanningtree.sql \ -f types_check.sql \ + -f via_compare.sql \ -f tsp_pgtap_tests.sql diff --git a/tools/testers/setup_db.sh b/tools/testers/setup_db.sh index 3d58d060f70..93a1e534643 100644 --- a/tools/testers/setup_db.sh +++ b/tools/testers/setup_db.sh @@ -31,4 +31,5 @@ psql -p "$1" -U "$3" -d "$2" -X -q --set client_min_messages=WARNING --set ON_E -f tsp_pgtap_tests.sql \ -f astar_pgtap_tests.sql \ -f types_check.sql \ + -f via_compare.sql \ -f spanningtree.sql diff --git a/tools/testers/trsp_tests.sql b/tools/testers/trsp_tests.sql index b233828923d..3a22c7bbb5a 100644 --- a/tools/testers/trsp_tests.sql +++ b/tools/testers/trsp_tests.sql @@ -191,76 +191,3 @@ BEGIN END $BODY$ language plpgsql; - -CREATE OR REPLACE FUNCTION trspVia_VS_dijstraVia(cant INTEGER default 18, flag boolean default true ) -RETURNS SETOF TEXT AS -$BODY$ -DECLARE -dijkstraVia_sql TEXT; -trsp_sql TEXT; -with_reverse_cost TEXT; -no_reverse_cost TEXT; -empty_restrictions TEXT; -k INTEGER; -directed TEXT; -msg TEXT; -msg_end TEXT; -all_found BOOLEAN; -allow_u BOOLEAN; -BEGIN - IF NOT min_version('3.4.0') THEN - RETURN QUERY SELECT skip(1, 'Signature added on 3.4.0'); - RETURN; - END IF; - - directed = 'Undirected'; - IF flag THEN directed = 'Directed'; END IF; - - k := 1; - with_reverse_cost = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost from edge_table ORDER BY id'); - no_reverse_cost = quote_literal('SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost from edge_table ORDER BY id'); - empty_restrictions = quote_literal('SELECT * FROM restrictions WHERE id > 7'); - --msg_end = E'\n' || trsp_sql || E'\n' || dijkstraVia_sql; - msg_end = ' '; - - FOR i IN 1 .. cant LOOP - FOR j IN 1 .. cant LOOP - FOR l IN 0 .. 1 LOOP - FOR m IN 0 .. 1 LOOP - all_found := (l=1); - allow_u := (m=1); - - dijkstraVia_sql := 'SELECT * FROM pgr_dijkstraVia( ' - || with_reverse_cost - || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; - - trsp_sql := 'SELECT * FROM pgr_trspVia(' - || with_reverse_cost || ',' - || empty_restrictions - || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; - - msg := '-1- ' || directed || ', with reverse_cost: from 1 to ' || i || ' to ' || j || msg_end; - RETURN query SELECT set_eq(trsp_sql, dijkstraVia_sql, msg); - - dijkstraVia_sql := 'SELECT * FROM pgr_dijkstraVia( ' - || no_reverse_cost - || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; - - trsp_sql := 'SELECT * FROM pgr_trspVia(' - || no_reverse_cost || ',' - || empty_restrictions - || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; - - msg := '-1- ' || directed || ', no reverse_cost: from 1 to ' || i || ' to ' || j || msg_end; - RETURN query SELECT set_eq(trsp_sql, dijkstraVia_sql, msg); - - - k := k + 1; - - END LOOP; - END LOOP; - END LOOP; - END LOOP; -END -$BODY$ -language plpgsql; diff --git a/tools/testers/types_check.sql b/tools/testers/types_check.sql index e7cd3240e33..be8c13f4c0b 100644 --- a/tools/testers/types_check.sql +++ b/tools/testers/types_check.sql @@ -22,7 +22,7 @@ DECLARE startend_v TEXT[] = ARRAY[start_v,end_v]; BEGIN - IF fn IN ('pgr_trsp', 'pgr_trsp_withpoints') AND NOT min_version('3.4.0') THEN + IF fn IN ('pgr_trsp', 'pgr_trsp_withpoints', 'pgr_withpointsvia') AND NOT min_version('3.4.0') THEN RETURN QUERY SELECT skip(1, 'Signature added on 3.4.0'); RETURN; END IF; @@ -43,7 +43,7 @@ BEGIN return_params_numbers = return_params_numbers || ARRAY[20,20]::OID[]; END IF; return_params_names = return_params_names || return_params_names_end; - return_params_numbers = return_params_numbers || return_params_numbers_end; + return_params_numbers = return_params_numbers || return_params_numbers_end; IF fn LIKE '%withpoints%' THEN params_types_words := params_types_words || 'text'::TEXT; diff --git a/tools/testers/via_compare.sql b/tools/testers/via_compare.sql new file mode 100644 index 00000000000..e70e953a508 --- /dev/null +++ b/tools/testers/via_compare.sql @@ -0,0 +1,144 @@ +CREATE OR REPLACE FUNCTION trspVia_VS_dijstraVia(cant INTEGER default 18, flag boolean default true ) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE +dijkstraVia_sql TEXT; +trsp_sql TEXT; +with_reverse_cost TEXT; +no_reverse_cost TEXT; +empty_restrictions TEXT; +k INTEGER; +directed TEXT; +msg TEXT; +msg_end TEXT; +all_found BOOLEAN; +allow_u BOOLEAN; +BEGIN + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'Signature added on 3.4.0'); + RETURN; + END IF; + + directed = 'Undirected'; + IF flag THEN directed = 'Directed'; END IF; + + k := 1; + with_reverse_cost = quote_literal('SELECT id, source, target, cost, reverse_cost from edge_table ORDER BY id'); + no_reverse_cost = quote_literal('SELECT id, source, target, cost from edge_table ORDER BY id'); + empty_restrictions = quote_literal('SELECT * FROM restrictions WHERE id > 7'); + --msg_end = E'\n' || trsp_sql || E'\n' || dijkstraVia_sql; + msg_end = ' '; + + FOR i IN 1 .. cant LOOP + FOR j IN 1 .. cant LOOP + FOR l IN 0 .. 1 LOOP + FOR m IN 0 .. 1 LOOP + all_found := (l=1); + allow_u := (m=1); + + dijkstraVia_sql := 'SELECT * FROM pgr_dijkstraVia( ' + || with_reverse_cost + || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; + + trsp_sql := 'SELECT * FROM pgr_trspVia(' + || with_reverse_cost || ',' + || empty_restrictions + || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; + + msg := '-1- ' || directed || ', with reverse_cost: from 1 to ' || i || ' to ' || j || msg_end; + RETURN query SELECT set_eq(trsp_sql, dijkstraVia_sql, msg); + + dijkstraVia_sql := 'SELECT * FROM pgr_dijkstraVia( ' + || no_reverse_cost + || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; + + trsp_sql := 'SELECT * FROM pgr_trspVia(' + || no_reverse_cost || ',' + || empty_restrictions + || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; + + msg := '-1- ' || directed || ', no reverse_cost: from 1 to ' || i || ' to ' || j || msg_end; + RETURN query SELECT set_eq(trsp_sql, dijkstraVia_sql, msg); + + + k := k + 1; + + END LOOP; + END LOOP; + END LOOP; + END LOOP; +END +$BODY$ +language plpgsql; + +CREATE OR REPLACE FUNCTION withPointsVia_VS_dijstraVia(cant INTEGER default 18, flag boolean default true ) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE +dijkstraVia_sql TEXT; +withPoints_sql TEXT; +with_reverse_cost TEXT; +no_reverse_cost TEXT; +the_points TEXT; +k INTEGER; +directed TEXT; +msg TEXT; +msg_end TEXT; +all_found BOOLEAN; +allow_u BOOLEAN; +BEGIN + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'Signature added on 3.4.0'); + RETURN; + END IF; + + directed = 'Undirected'; + IF flag THEN directed = 'Directed'; END IF; + + k := 1; + with_reverse_cost = quote_literal('SELECT id, source, target, cost, reverse_cost from edge_table ORDER BY id'); + no_reverse_cost = quote_literal('SELECT id, source, target, cost from edge_table ORDER BY id'); + the_points = quote_literal('SELECT * FROM pointsOfInterest'); + msg_end = ' '; + + FOR i IN 1 .. cant LOOP + FOR j IN 1 .. cant LOOP + FOR l IN 0 .. 1 LOOP + FOR m IN 0 .. 1 LOOP + all_found := (l=1); + allow_u := (m=1); + + dijkstraVia_sql := 'SELECT * FROM pgr_dijkstraVia( ' + || with_reverse_cost + || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; + + withPoints_sql := 'SELECT * FROM pgr_withPointsVia(' + || with_reverse_cost || ',' + || the_points + || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; + + msg := '-1- ' || directed || ', with reverse_cost: from 1 to ' || i || ' to ' || j || msg_end || withPoints_sql; + RETURN query SELECT set_eq(withPoints_sql, dijkstraVia_sql, msg); + + dijkstraVia_sql := 'SELECT * FROM pgr_dijkstraVia( ' + || no_reverse_cost + || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; + + withPoints_sql := 'SELECT * FROM pgr_withPointsVia(' + || no_reverse_cost || ',' + || the_points + || ', ARRAY[1, ' || i || ', ' || j || '], ' || flag || ',' || all_found || ',' || allow_u || ')'; + + msg := '-1- ' || directed || ', no reverse_cost: from 1 to ' || i || ' to ' || j || msg_end; + RETURN query SELECT set_eq(withPoints_sql, dijkstraVia_sql, msg); + + + k := k + 1; + + END LOOP; + END LOOP; + END LOOP; + END LOOP; +END +$BODY$ +language plpgsql; From 790c7c755ae328b7f2c57010d4e64fd9fc0b424a Mon Sep 17 00:00:00 2001 From: cvvergara Date: Fri, 18 Feb 2022 13:39:39 -0600 Subject: [PATCH 02/10] [withPointsVia][pgtap] tests that need to pass --- .../compare_dijkstraVia/directed.pg | 10 +++ .../compare_dijkstraVia/undirected.pg | 10 +++ pgtap/withPoints/withPointsVia/inner_query.pg | 26 ++++++++ .../withPoints/withPointsVia/no_crash_test.pg | 62 +++++++++++++++++++ pgtap/withPoints/withPointsVia/types_check.pg | 8 +++ 5 files changed, 116 insertions(+) create mode 100644 pgtap/withPoints/withPointsVia/compare_dijkstraVia/directed.pg create mode 100644 pgtap/withPoints/withPointsVia/compare_dijkstraVia/undirected.pg create mode 100644 pgtap/withPoints/withPointsVia/inner_query.pg create mode 100644 pgtap/withPoints/withPointsVia/no_crash_test.pg create mode 100644 pgtap/withPoints/withPointsVia/types_check.pg diff --git a/pgtap/withPoints/withPointsVia/compare_dijkstraVia/directed.pg b/pgtap/withPoints/withPointsVia/compare_dijkstraVia/directed.pg new file mode 100644 index 00000000000..a50a0dcbea7 --- /dev/null +++ b/pgtap/withPoints/withPointsVia/compare_dijkstraVia/directed.pg @@ -0,0 +1,10 @@ +BEGIN; + +SELECT CASE WHEN min_version('3.4.0') THEN plan(2048) ELSE plan(1) END; +SET extra_float_digits = -3; +UPDATE edge_table SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; + +SELECT withPointsVia_VS_dijstraVia(16, true); + +SELECT * FROM finish(); +ROLLBACK; diff --git a/pgtap/withPoints/withPointsVia/compare_dijkstraVia/undirected.pg b/pgtap/withPoints/withPointsVia/compare_dijkstraVia/undirected.pg new file mode 100644 index 00000000000..564d4311874 --- /dev/null +++ b/pgtap/withPoints/withPointsVia/compare_dijkstraVia/undirected.pg @@ -0,0 +1,10 @@ +BEGIN; + +SELECT CASE WHEN min_version('3.4.0') THEN plan(2048) ELSE plan(1) END; +SET extra_float_digits = -3; +UPDATE edge_table SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(reverse_cost) + 0.001 * id * id; + +SELECT withPointsVia_VS_dijstraVia(16, false); + +SELECT * FROM finish(); +ROLLBACK; diff --git a/pgtap/withPoints/withPointsVia/inner_query.pg b/pgtap/withPoints/withPointsVia/inner_query.pg new file mode 100644 index 00000000000..b9e86754e4d --- /dev/null +++ b/pgtap/withPoints/withPointsVia/inner_query.pg @@ -0,0 +1,26 @@ +BEGIN; + +UPDATE edge_table SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN min_version('3.4.0') THEN plan(84) ELSE plan(1) END; + +CREATE OR REPLACE FUNCTION inner_query() +RETURNS SETOF TEXT AS +$BODY$ +BEGIN + IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'Signature added on 3.4.0'); + RETURN; + END IF; + + -- ONE VIA + RETURN QUERY SELECT style_dijkstra('pgr_withPointsVia(', ', $$SELECT * FROM pointsOfInterest$$, ARRAY[2,9,12])'); + RETURN QUERY SELECT innerquery_points('pgr_withPointsVia($$SELECT * FROM edge_table$$,', ', ARRAY[2,9,12])'); + +END; +$BODY$ +LANGUAGE plpgsql; + +SELECT inner_query(); + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/withPoints/withPointsVia/no_crash_test.pg b/pgtap/withPoints/withPointsVia/no_crash_test.pg new file mode 100644 index 00000000000..a86d1d85bf5 --- /dev/null +++ b/pgtap/withPoints/withPointsVia/no_crash_test.pg @@ -0,0 +1,62 @@ +BEGIN; + +UPDATE edge_table SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN min_version('3.4.0') THEN plan(19) ELSE plan(4) END; + +PREPARE edges AS +SELECT id, source, target, cost, reverse_cost FROM edge_table; + +PREPARE null_ret AS +SELECT id FROM edge_table_vertices_pgr WHERE id IN (-1); + +PREPARE null_ret_arr AS +SELECT array_agg(id) FROM edge_table_vertices_pgr WHERE id IN (-1); + +SELECT isnt_empty('edges', 'Should be not empty to tests be meaningful'); +SELECT is_empty('null_ret', 'Should be empty to tests be meaningful'); +SELECT set_eq('null_ret_arr', 'SELECT NULL::BIGINT[]', 'Should be empty to tests be meaningful'); + + +CREATE OR REPLACE FUNCTION test_function() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE +params TEXT[]; +subs TEXT[]; +BEGIN + +IF NOT min_version('3.4.0') THEN + RETURN QUERY SELECT skip(1, 'Signature added on 3.4.0'); + RETURN; +END IF; + +-- ONE VIA +params = ARRAY[ +'$$SELECT * FROM edge_table$$', +'$$SELECT * FROM pointsOfInterest$$', +'ARRAY[2,5]::BIGINT[]' +]::TEXT[]; + +subs = ARRAY[ +'NULL', +'NULL', +'(SELECT array_agg(id) FROM edge_table_vertices_pgr WHERE id IN (-1))' +]::TEXT[]; + +RETURN query SELECT * FROM no_crash_test('pgr_withPointsvia', params, subs); + +subs = ARRAY[ +'NULL', +'NULL', +'NULL::BIGINT[]' +]::TEXT[]; +RETURN query SELECT * FROM no_crash_test('pgr_withPointsvia', params, subs); + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + + +SELECT * FROM test_function(); + +ROLLBACK; diff --git a/pgtap/withPoints/withPointsVia/types_check.pg b/pgtap/withPoints/withPointsVia/types_check.pg new file mode 100644 index 00000000000..a4f5e0f8c66 --- /dev/null +++ b/pgtap/withPoints/withPointsVia/types_check.pg @@ -0,0 +1,8 @@ +BEGIN; + +SELECT CASE WHEN min_version('3.4.0') THEN plan(5) ELSE plan(1) END; + +SELECT types_check_via('pgr_withpointsvia'); + +SELECT * FROM finish(); +ROLLBACK; From cb6679071be7d05cc86f2e923c91c8b2106a97a2 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Fri, 18 Feb 2022 13:45:42 -0600 Subject: [PATCH 03/10] [withPointsVia][C/C++] adding code for new function --- .../drivers/withPoints/withPointsVia_driver.h | 74 ++++++ src/withPoints/CMakeLists.txt | 3 + src/withPoints/pgr_withPoints.cpp | 42 ++-- src/withPoints/withPointsVia.c | 224 ++++++++++++++++++ src/withPoints/withPointsVia_driver.cpp | 224 ++++++++++++++++++ 5 files changed, 540 insertions(+), 27 deletions(-) create mode 100644 include/drivers/withPoints/withPointsVia_driver.h create mode 100644 src/withPoints/withPointsVia.c create mode 100644 src/withPoints/withPointsVia_driver.cpp diff --git a/include/drivers/withPoints/withPointsVia_driver.h b/include/drivers/withPoints/withPointsVia_driver.h new file mode 100644 index 00000000000..236715ecd8e --- /dev/null +++ b/include/drivers/withPoints/withPointsVia_driver.h @@ -0,0 +1,74 @@ +/*PGR-GNU***************************************************************** +File: withPointsVia_driver.h + +Function's developer: +Copyright (c) 2022 Celia Virginia Vergara Castillo + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#ifndef INCLUDE_DRIVERS_WITHPOINTS_WITHPOINTSVIA_DRIVER_H_ +#define INCLUDE_DRIVERS_WITHPOINTS_WITHPOINTSVIA_DRIVER_H_ +#pragma once + +#ifdef __cplusplus +# include +# include +using Point_on_edge_t = struct Point_on_edge_t; +using Edge_t = struct Edge_t; +using Routes_t = struct Routes_t; +#else +# include +# include +typedef struct Point_on_edge_t Point_on_edge_t; +typedef struct Edge_t Edge_t; +typedef struct Routes_t Routes_t; +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief Process pgr_withPointsVia */ +void +do_withPointsVia( + Edge_t*, size_t, // edges + Point_on_edge_t *, size_t, // Points + Edge_t*, size_t, // edges of points + int64_t *, size_t, // via vertices + + bool, // directed + + char, // driving_side + bool, // details + + bool, // strict + bool, // U_turn_on_edge, + + Routes_t**, size_t*, // results + + char**, // log + char**, // notice + char**); // error + +#ifdef __cplusplus +} +#endif + +#endif // INCLUDE_DRIVERS_WITHPOINTS_WITHPOINTSVIA_DRIVER_H_ diff --git a/src/withPoints/CMakeLists.txt b/src/withPoints/CMakeLists.txt index 33e90124bdb..a9f5435a692 100644 --- a/src/withPoints/CMakeLists.txt +++ b/src/withPoints/CMakeLists.txt @@ -4,4 +4,7 @@ ADD_LIBRARY(withPoints OBJECT get_new_queries.cpp withPoints_driver.cpp pgr_withPoints.cpp + + withPointsVia.c + withPointsVia_driver.cpp ) diff --git a/src/withPoints/pgr_withPoints.cpp b/src/withPoints/pgr_withPoints.cpp index c888ebaf37c..0d1520ac15a 100644 --- a/src/withPoints/pgr_withPoints.cpp +++ b/src/withPoints/pgr_withPoints.cpp @@ -179,8 +179,8 @@ Pg_points_graph::eliminate_details_dd( * There is no path nothing to do */ if (path.empty()) return; - Path newPath(path.start_id(), path.end_id()); + auto edge_id = path.start_id() < 0? get_edge_id(path.start_id()) : -1; @@ -232,38 +232,26 @@ Pg_points_graph::eliminate_details( * There is no path nothing to do */ if (path.empty()) return path; + path.recalculate_agg_cost(); Path newPath(path.start_id(), path.end_id()); + double cost = 0.0; - for (const auto &pathstop : path) { - if ((pathstop.node == path.start_id()) - || (pathstop.node == path.end_id()) - || (pathstop.node > 0)) { - newPath.push_back(pathstop); - if (pathstop.node != path.end_id()) cost = 0.0; - continue; - } - cost += pathstop.cost; - } + auto current_node = path[0].node; + auto current_edge = path[0].edge; - newPath[0].cost = newPath[1].agg_cost; - for (unsigned int i = 1; i < newPath.size() - 2; ++i) { - /* newPath[i] has: node, edge, cost, agg_cost - * pgr_type_t has: id, source, target, cost, reverse_cost - * - * find the edge where the pathstop.edge == edge.id */ - - int64_t edge_to_find = newPath[i].edge; - auto edge_ptr = std::find_if( - m_edges_of_points.begin(), m_edges_of_points.end(), - [&edge_to_find](const Edge_t &edge) - {return edge_to_find == edge.id;}); - if (edge_ptr != m_edges_of_points.end()) { - newPath[i].cost = edge_ptr->target == newPath[i+1].node ? - edge_ptr->cost : edge_ptr->reverse_cost; + for (const auto &pathstop : path) { + if (pathstop.edge == current_edge) { + cost += pathstop.cost; + continue; } + newPath.push_back({current_node, current_edge, cost, 0}); + cost = pathstop.cost; + current_node = pathstop.node; + current_edge = pathstop.edge; } - newPath[newPath.size()-2].cost += cost; + newPath.push_back({current_node, current_edge, cost, 0}); + newPath.recalculate_agg_cost(); return newPath; } diff --git a/src/withPoints/withPointsVia.c b/src/withPoints/withPointsVia.c new file mode 100644 index 00000000000..636ba3779b5 --- /dev/null +++ b/src/withPoints/withPointsVia.c @@ -0,0 +1,224 @@ +/*PGR-GNU***************************************************************** +File: withPointsVia.c + +Function's developer: +Copyright (c) 2022 Celia Virginia Vergara Castillo + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#include +#include "c_common/postgres_connection.h" +#include "utils/array.h" +#include "c_types/routes_t.h" +#include "c_common/debug_macro.h" +#include "c_common/e_report.h" +#include "c_common/time_msg.h" +#include "c_common/edges_input.h" +#include "c_common/arrays_input.h" +#include "c_common/points_input.h" +#include "drivers/withPoints/get_new_queries.h" +#include "drivers/withPoints/withPointsVia_driver.h" + +PGDLLEXPORT Datum _pgr_withpointsvia(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_withpointsvia); + +static +void +process( + char* edges_sql, + char* points_sql, + ArrayType *viasArr, + bool directed, + bool strict, + bool U_turn_on_edge, + char *driving_side, + bool details, + Routes_t **result_tuples, + size_t *result_count) { + pgr_SPI_connect(); + + driving_side[0] = estimate_drivingSide(driving_side[0]); + + /* + * Processing Via + */ + size_t size_vias = 0; + int64_t* vias = (int64_t*) pgr_get_bigIntArray(&size_vias, viasArr); + + // TODO(vicky) figure out what happens when one point or 0 points are given + + /* + * Processing Points + */ + Point_on_edge_t *points = NULL; + size_t total_points = 0; + pgr_get_points(points_sql, &points, &total_points); + + char *edges_of_points_query = NULL; + char *edges_no_points_query = NULL; + get_new_queries(edges_sql, points_sql, &edges_of_points_query, &edges_no_points_query); + + Edge_t *edges_of_points = NULL; + size_t total_edges_of_points = 0; + + Edge_t *edges = NULL; + size_t total_edges = 0; + + pgr_get_edges(edges_no_points_query, &edges, &total_edges); + pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points); + + {pfree(edges_of_points_query); edges_of_points_query = NULL;} + {pfree(edges_no_points_query); edges_no_points_query = NULL;} + + if ((total_edges + total_edges_of_points) == 0) { + if (edges) {pfree(edges), edges = NULL;} + if (edges_of_points) {pfree(edges_of_points), edges_of_points = NULL;} + if (vias) {pfree(vias), vias = NULL;} + pgr_SPI_finish(); + return; + } + + clock_t start_t = clock(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; + do_withPointsVia( + edges, total_edges, + points, total_points, + edges_of_points, total_edges_of_points, + vias, size_vias, + + directed, + + driving_side[0], + details, + + strict, + U_turn_on_edge, + + result_tuples, result_count, + &log_msg, ¬ice_msg, &err_msg); + time_msg("processing pgr_withPointsVia", start_t, clock()); + + if (err_msg && (*result_tuples)) { + pfree(*result_tuples); + (*result_tuples) = NULL; + (*result_count) = 0; + } + + pgr_global_report(log_msg, notice_msg, err_msg); + + if (points) {pfree(points), points = NULL;} + if (edges) {pfree(edges), edges = NULL;} + if (edges_of_points) {pfree(edges_of_points), edges_of_points = NULL;} + if (vias) {pfree(vias), vias = NULL;} + if (log_msg) {pfree(log_msg); log_msg = NULL;} + if (notice_msg) {pfree(notice_msg); notice_msg = NULL;} + if (err_msg) {pfree(err_msg); err_msg = NULL;} + pgr_SPI_finish(); +} + + +PGDLLEXPORT Datum +_pgr_withpointsvia(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + + /**********************************************************************/ + Routes_t *result_tuples = 0; + size_t result_count = 0; + /**********************************************************************/ + + if (SRF_IS_FIRSTCALL()) { + MemoryContext oldcontext; + funcctx = SRF_FIRSTCALL_INIT(); + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + + + process( + text_to_cstring(PG_GETARG_TEXT_P(0)), + text_to_cstring(PG_GETARG_TEXT_P(1)), + PG_GETARG_ARRAYTYPE_P(2), + PG_GETARG_BOOL(3), + + PG_GETARG_BOOL(4), + PG_GETARG_BOOL(5), + + text_to_cstring(PG_GETARG_TEXT_P(6)), + PG_GETARG_BOOL(7), + + &result_tuples, + &result_count); + + /**********************************************************************/ + + funcctx->max_calls = result_count; + + funcctx->user_fctx = result_tuples; + if (get_call_result_type(fcinfo, NULL, &tuple_desc) + != TYPEFUNC_COMPOSITE) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("function returning record called in context " + "that cannot accept type record"))); + + funcctx->tuple_desc = tuple_desc; + MemoryContextSwitchTo(oldcontext); + } + + funcctx = SRF_PERCALL_SETUP(); + tuple_desc = funcctx->tuple_desc; + result_tuples = (Routes_t*) funcctx->user_fctx; + + if (funcctx->call_cntr < funcctx->max_calls) { + HeapTuple tuple; + Datum result; + Datum *values; + bool* nulls; + size_t call_cntr = funcctx->call_cntr; + + size_t numb_out = 10; + values = palloc(numb_out * sizeof(Datum)); + nulls = palloc(numb_out * sizeof(bool)); + size_t i; + for (i = 0; i< numb_out; ++i) { + nulls[i] = false; + } + + // postgres starts counting from 1 + values[0] = Int32GetDatum(call_cntr + 1); + values[1] = Int32GetDatum(result_tuples[call_cntr].path_id); + values[2] = Int32GetDatum(result_tuples[call_cntr].path_seq + 1); + values[3] = Int64GetDatum(result_tuples[call_cntr].start_vid); + values[4] = Int64GetDatum(result_tuples[call_cntr].end_vid); + values[5] = Int64GetDatum(result_tuples[call_cntr].node); + values[6] = Int64GetDatum(result_tuples[call_cntr].edge); + values[7] = Float8GetDatum(result_tuples[call_cntr].cost); + values[8] = Float8GetDatum(result_tuples[call_cntr].agg_cost); + values[9] = Float8GetDatum(result_tuples[call_cntr].route_agg_cost); + + /**********************************************************************/ + + tuple = heap_form_tuple(tuple_desc, values, nulls); + result = HeapTupleGetDatum(tuple); + SRF_RETURN_NEXT(funcctx, result); + } else { + SRF_RETURN_DONE(funcctx); + } +} diff --git a/src/withPoints/withPointsVia_driver.cpp b/src/withPoints/withPointsVia_driver.cpp new file mode 100644 index 00000000000..70e32e469cb --- /dev/null +++ b/src/withPoints/withPointsVia_driver.cpp @@ -0,0 +1,224 @@ +/*PGR-GNU***************************************************************** +File: withPointsVia_driver.cpp + +Generated with Template by: +Copyright (c) 2015 pgRouting developers + +Function's developer: +Copyright (c) 2015 Celia Virginia Vergara Castillo + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#include "drivers/withPoints/withPointsVia_driver.h" + +#include +#include +#include + +#include "dijkstra/pgr_dijkstraVia.hpp" +#include "withPoints/pgr_withPoints.hpp" +#include "c_types/routes_t.h" +#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/pgr_assert.h" + + +static +void +get_path( + int route_id, + int path_id, + const Path &path, + Routes_t **postgres_data, + double &route_cost, + size_t &sequence) { + size_t i = 0; + for (const auto e : path) { + (*postgres_data)[sequence] = { + route_id, + path_id, + static_cast(i), + path.start_id(), + path.end_id(), + e.node, + e.edge, + e.cost, + e.agg_cost, + route_cost}; + route_cost += path[i].cost; + ++i; + ++sequence; + } +} + + +static +size_t +get_route( + Routes_t **ret_path, + std::deque< Path > &paths) { + size_t sequence = 0; + int path_id = 1; + int route_id = 1; + double route_cost = 0; // routes_agg_cost + for (auto &p : paths) { + p.recalculate_agg_cost(); + } + for (const Path &path : paths) { + if (path.size() > 0) + get_path(route_id, path_id, path, ret_path, route_cost, sequence); + ++path_id; + } + return sequence; +} + +void +do_withPointsVia( + Edge_t* edges, size_t total_edges, + Point_on_edge_t *points_p, size_t total_points, + Edge_t *edges_of_points, size_t total_edges_of_points, + int64_t* via_vidsArr, size_t size_via_vidsArr, + + bool directed, + + char driving_side, + bool details, + + bool strict, + bool U_turn_on_edge, + + Routes_t** return_tuples, size_t* return_count, + + char** log_msg, + char** notice_msg, + char** err_msg) { + std::ostringstream log; + std::ostringstream err; + std::ostringstream notice; + + try { + pgassert(total_edges != 0); + pgassert(!(*log_msg)); + pgassert(!(*notice_msg)); + pgassert(!(*err_msg)); + pgassert(!(*return_tuples)); + pgassert(*return_count == 0); + + std::dequepaths; + + graphType gType = directed? DIRECTED: UNDIRECTED; + + /* + * processing via + */ + std::vector via_vertices(via_vidsArr, via_vidsArr + size_via_vidsArr); + + /* + * processing points + */ + pgrouting::Pg_points_graph pg_graph( + std::vector( + points_p, + points_p + total_points), + std::vector< Edge_t >( + edges_of_points, + edges_of_points + total_edges_of_points), + true, + driving_side, + directed); + + if (pg_graph.has_error()) { + log << pg_graph.get_log(); + err << pg_graph.get_error(); + *log_msg = pgr_msg(log.str().c_str()); + *err_msg = pgr_msg(err.str().c_str()); + return; + } + + auto vertices(pgrouting::extract_vertices(edges, total_edges)); + vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges()); + + if (directed) { + pgrouting::DirectedGraph digraph(vertices, gType); + digraph.insert_edges(edges, total_edges); + digraph.insert_edges(pg_graph.new_edges()); + pgrouting::pgr_dijkstraVia( + digraph, + via_vertices, + paths, + strict, + U_turn_on_edge, + log); + } else { + pgrouting::UndirectedGraph undigraph(vertices, gType); + undigraph.insert_edges(edges, total_edges); + undigraph.insert_edges(pg_graph.new_edges()); + pgrouting::pgr_dijkstraVia( + undigraph, + via_vertices, + paths, + strict, + U_turn_on_edge, + log); + } + + if (!details) { + for (auto &path : paths) path = pg_graph.eliminate_details(path); + } + + size_t count(0); + count = count_tuples(paths); + + if (count == 0) { + (*return_tuples) = NULL; + (*return_count) = 0; + notice << "No paths found"; + *log_msg = pgr_msg(notice.str().c_str()); + return; + } + + (*return_tuples) = pgr_alloc(count, (*return_tuples)); + (*return_count) = (get_route(return_tuples, paths)); + (*return_tuples)[count - 1].edge = -2; + + *log_msg = log.str().empty()? + *log_msg : + pgr_msg(log.str().c_str()); + *notice_msg = notice.str().empty()? + *notice_msg : + pgr_msg(notice.str().c_str()); + } catch (AssertFailedException &except) { + (*return_tuples) = pgr_free(*return_tuples); + (*return_count) = 0; + err << except.what(); + *err_msg = pgr_msg(err.str().c_str()); + *log_msg = pgr_msg(log.str().c_str()); + } catch (std::exception &except) { + (*return_tuples) = pgr_free(*return_tuples); + (*return_count) = 0; + err << except.what(); + *err_msg = pgr_msg(err.str().c_str()); + *log_msg = pgr_msg(log.str().c_str()); + } catch(...) { + (*return_tuples) = pgr_free(*return_tuples); + (*return_count) = 0; + err << "Caught unknown exception!"; + *err_msg = pgr_msg(err.str().c_str()); + *log_msg = pgr_msg(log.str().c_str()); + } +} From e2c667bf8aa1e91d585510c858468f3a77fe6857 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Fri, 18 Feb 2022 13:46:06 -0600 Subject: [PATCH 04/10] [withPointsVia][sql] adding code for new function --- sql/sigs/pgrouting--3.4.sig | 2 ++ sql/withPoints/CMakeLists.txt | 1 + sql/withPoints/_withPointsVia.sql | 51 ++++++++++++++++++++++++++ sql/withPoints/withPointsVia.sql | 60 +++++++++++++++++++++++++++---- 4 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 sql/withPoints/_withPointsVia.sql diff --git a/sql/sigs/pgrouting--3.4.sig b/sql/sigs/pgrouting--3.4.sig index a3a061b8288..4d7e998d6d6 100644 --- a/sql/sigs/pgrouting--3.4.sig +++ b/sql/sigs/pgrouting--3.4.sig @@ -302,5 +302,7 @@ pgr_withpoints(text,text,bigint,bigint,boolean,character,boolean) pgr_withpoints(text,text,text,boolean,character,boolean) _pgr_withpoints(text,text,text,boolean,character,boolean,boolean) _pgr_withpointsvia(text,bigint[],double precision[],boolean) +_pgr_withpointsvia(text,text,anyarray,boolean,boolean,boolean,character,boolean) +pgr_withpointsvia(text,text,anyarray,boolean,boolean,boolean,character,boolean) _trsp(text,text,anyarray,anyarray,boolean) _trsp(text,text,text,boolean) diff --git a/sql/withPoints/CMakeLists.txt b/sql/withPoints/CMakeLists.txt index 86bedd4884b..8ee2f361566 100644 --- a/sql/withPoints/CMakeLists.txt +++ b/sql/withPoints/CMakeLists.txt @@ -4,6 +4,7 @@ SET(LOCAL_FILES withPoints.sql withPointsCost.sql withPointsCostMatrix.sql + _withPointsVia.sql withPointsVia.sql ) diff --git a/sql/withPoints/_withPointsVia.sql b/sql/withPoints/_withPointsVia.sql new file mode 100644 index 00000000000..fa60bba35fb --- /dev/null +++ b/sql/withPoints/_withPointsVia.sql @@ -0,0 +1,51 @@ +/*PGR-GNU***************************************************************** +File: _withPointsVia.sql + +Function's developer: +Copyright (c) 2022 Celia Virginia Vergara Castillo + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +--v3.4 +CREATE FUNCTION _pgr_withPointsVia( + TEXT, -- edges_sql + TEXT, -- points_sql + ANYARRAY, -- via vids + BOOLEAN, -- directed + BOOLEAN, -- strict + BOOLEAN, -- U_turn_on_edge + CHAR, -- driving_side + BOOLEAN, -- details + + OUT seq INTEGER, + OUT path_id INTEGER, + OUT path_seq INTEGER, + OUT start_vid BIGINT, + OUT end_vid BIGINT, + OUT node BIGINT, + OUT edge BIGINT, + OUT cost FLOAT, + OUT agg_cost FLOAT, + OUT route_agg_cost FLOAT) +RETURNS SETOF RECORD AS +'MODULE_PATHNAME' +LANGUAGE c VOLATILE STRICT; + +COMMENT ON FUNCTION _pgr_withPointsVia(TEXT, TEXT, ANYARRAY, BOOLEAN, BOOLEAN, BOOLEAN, CHAR, BOOLEAN) +IS 'pgRouting internal function'; diff --git a/sql/withPoints/withPointsVia.sql b/sql/withPoints/withPointsVia.sql index e7af58dad84..d49fdfe2de2 100644 --- a/sql/withPoints/withPointsVia.sql +++ b/sql/withPoints/withPointsVia.sql @@ -6,8 +6,8 @@ Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org Function's developer: +Copyright (c) 2022 Celia Virginia Vergara Castillo Copyright (c) 2015 Celia Virginia Vergara Castillo -Mail: ------ @@ -27,11 +27,57 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ - ----------------------- --- _pgr_withPointsVia ----------------------- - +--v3.4 +CREATE FUNCTION pgr_withPointsVia( + TEXT, -- edges SQL + TEXT, -- points SQL + ANYARRAY, -- via vids + + directed BOOLEAN DEFAULT true, + + -- via parameters + strict BOOLEAN DEFAULT false, + U_turn_on_edge BOOLEAN DEFAULT true, + + -- withPoints parameters + driving_side CHAR DEFAULT 'b', -- 'r'/'l'/'b'/NULL + details BOOLEAN DEFAULT false, + + OUT seq INTEGER, + OUT path_id INTEGER, + OUT path_seq INTEGER, + OUT start_vid BIGINT, + OUT end_vid BIGINT, + OUT node BIGINT, + OUT edge BIGINT, + OUT cost FLOAT, + OUT agg_cost FLOAT, + OUT route_agg_cost FLOAT) +RETURNS SETOF RECORD AS +$BODY$ + SELECT * + FROM _pgr_withPointsVia( _pgr_get_statement($1), _pgr_get_statement($2), $3, $4, $5, $6, $7, $8); +$BODY$ +LANGUAGE SQL VOLATILE STRICT +COST 100 +ROWS 1000; + +COMMENT ON FUNCTION pgr_withPointsVia(TEXT, TEXT, ANYARRAY, BOOLEAN, BOOLEAN, BOOLEAN, CHAR, BOOLEAN) +IS 'pgr_withPointsVia +- PROPOSED +- Parameters: + - Edges SQL with columns: id, source, target, cost [,reverse_cost] + - Points SQL with columns: [pid], edge_id, fraction [,side] + - ARRAY[via vertices identifiers] +- Optional Parameters + - directed := true + - strict := false + - U_turn_on_edge := true + - driving_side := ''b'' + - details := ''false'' +- Documentation: + - ${PROJECT_DOC_LINK}/pgr_withPointsVia.html +'; --v2.6 CREATE FUNCTION _pgr_withPointsVia( @@ -178,4 +224,4 @@ CREATE FUNCTION _pgr_withPointsVia( COMMENT ON FUNCTION _pgr_withPointsVia(TEXT, BIGINT[], FLOAT[], BOOLEAN) -IS 'pgRouting internal function'; +IS 'pgRouting deprecated internal function'; From e09a45ba1302f0af68f488058295d04586286003 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Fri, 18 Feb 2022 13:47:12 -0600 Subject: [PATCH 05/10] [withPointsVia][queries] adding queries for the documentation --- docqueries/withPoints/CMakeLists.txt | 1 + docqueries/withPoints/test.conf | 11 +- docqueries/withPoints/withPointsVia.result | 129 +++++++++++++++++++ docqueries/withPoints/withPointsVia.test.sql | 47 +++++++ 4 files changed, 179 insertions(+), 9 deletions(-) create mode 100644 docqueries/withPoints/withPointsVia.result create mode 100644 docqueries/withPoints/withPointsVia.test.sql diff --git a/docqueries/withPoints/CMakeLists.txt b/docqueries/withPoints/CMakeLists.txt index bbf5e755e64..de41f299c64 100644 --- a/docqueries/withPoints/CMakeLists.txt +++ b/docqueries/withPoints/CMakeLists.txt @@ -6,6 +6,7 @@ SET(LOCAL_FILES doc-pgr_withPointsKSP-cygwin doc-pgr_withPointsKSP doc-pgr_withPoints + withPointsVia ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/withPoints/test.conf b/docqueries/withPoints/test.conf index 8f0c567e660..e7f7ac8e12a 100644 --- a/docqueries/withPoints/test.conf +++ b/docqueries/withPoints/test.conf @@ -10,6 +10,7 @@ doc-pgr_withPointsCostMatrix doc-pgr_withPointsDD doc-pgr_withPointsKSP + withPointsVia )], 'documentation' => [qw( doc-pgr_withPoints @@ -17,15 +18,7 @@ doc-pgr_withPointsCostMatrix doc-pgr_withPointsDD doc-pgr_withPointsKSP - )], - 'linux' => [qw( - doc-pgr_withPointsKSP - )], - 'cygwin' => [qw( - doc-pgr_withPointsKSP-cygwin - )], - 'not on 2.2' => [qw( - doc-pgr_withPointsVia + withPointsVia )], }, ); diff --git a/docqueries/withPoints/withPointsVia.result b/docqueries/withPoints/withPointsVia.result new file mode 100644 index 00000000000..25fe32601e5 --- /dev/null +++ b/docqueries/withPoints/withPointsVia.result @@ -0,0 +1,129 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +SET extra_float_digits=-3; +SET +/* -- q0 */ +SELECT * FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, -3, 9], false); + seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost +-----+---------+----------+-----------+---------+------+------+------+----------+---------------- + 1 | 1 | 1 | -1 | -3 | -1 | 1 | 0.6 | 0 | 0 + 2 | 1 | 2 | -1 | -3 | 2 | 4 | 1 | 0.6 | 0.6 + 3 | 1 | 3 | -1 | -3 | 5 | 10 | 1 | 1.6 | 1.6 + 4 | 1 | 4 | -1 | -3 | 10 | 12 | 0.6 | 2.6 | 2.6 + 5 | 1 | 5 | -1 | -3 | -3 | -1 | 0 | 3.2 | 3.2 + 6 | 2 | 1 | -3 | 9 | -3 | 12 | 0.4 | 0 | 3.2 + 7 | 2 | 2 | -3 | 9 | 11 | 11 | 1 | 0.4 | 3.6 + 8 | 2 | 3 | -3 | 9 | 6 | 9 | 1 | 1.4 | 4.6 + 9 | 2 | 4 | -3 | 9 | 9 | -2 | 0 | 2.4 | 5.6 +(9 rows) + +/* -- q1 */ +SELECT * FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]); + seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost +-----+---------+----------+-----------+---------+------+------+------+----------+---------------- + 1 | 1 | 1 | -1 | 5 | -1 | 1 | 0.6 | 0 | 0 + 2 | 1 | 2 | -1 | 5 | 2 | 4 | 1 | 0.6 | 0.6 + 3 | 1 | 3 | -1 | 5 | 5 | -1 | 0 | 1.6 | 1.6 + 4 | 2 | 1 | 5 | -3 | 5 | 10 | 1 | 0 | 1.6 + 5 | 2 | 2 | 5 | -3 | 10 | 12 | 0.6 | 1 | 2.6 + 6 | 2 | 3 | 5 | -3 | -3 | -1 | 0 | 1.6 | 3.2 + 7 | 3 | 1 | -3 | 9 | -3 | 12 | 0.4 | 0 | 3.2 + 8 | 3 | 2 | -3 | 9 | 11 | 13 | 1 | 0.4 | 3.6 + 9 | 3 | 3 | -3 | 9 | 12 | 15 | 1 | 1.4 | 4.6 + 10 | 3 | 4 | -3 | 9 | 9 | -1 | 0 | 2.4 | 5.6 + 11 | 4 | 1 | 9 | 4 | 9 | 16 | 1 | 0 | 5.6 + 12 | 4 | 2 | 9 | 4 | 4 | -2 | 0 | 1 | 6.6 +(12 rows) + +/* -- q2 */ +SELECT agg_cost FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]) +WHERE path_id = 3 AND edge <0; + agg_cost +---------- + 2.4 +(1 row) + +/* -- q3 */ +SELECT route_agg_cost FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]) +WHERE path_id = 3 AND edge < 0; + route_agg_cost +---------------- + 5.6 +(1 row) + +/* -- q4 */ +SELECT row_number() over () as node_seq, node +FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]) +WHERE edge <> -1 ORDER BY seq; + node_seq | node +----------+------ + 1 | -1 + 2 | 2 + 3 | 5 + 4 | 10 + 5 | -3 + 6 | 11 + 7 | 12 + 8 | 9 + 9 | 4 +(9 rows) + +/* -- q5 */ +SELECT path_id, route_agg_cost FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]) +WHERE edge < 0; + path_id | route_agg_cost +---------+---------------- + 1 | 1.6 + 2 | 3.2 + 3 | 5.6 + 4 | 6.6 +(4 rows) + +/* -- q6 */ +SELECT seq, node, +CASE WHEN edge = -1 THEN 'visits' +ELSE 'passes in front' +END as status +FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4], details => true) +WHERE agg_cost <> 0 or seq = 1; + seq | node | status +-----+------+----------------- + 1 | -1 | passes in front + 2 | 2 | passes in front + 3 | -6 | passes in front + 4 | 5 | visits + 6 | 10 | passes in front + 7 | -3 | visits + 9 | 11 | passes in front + 10 | 12 | passes in front + 11 | -2 | passes in front + 12 | 9 | visits + 14 | 4 | passes in front +(11 rows) + +/* -- q7 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/withPoints/withPointsVia.test.sql b/docqueries/withPoints/withPointsVia.test.sql new file mode 100644 index 00000000000..bdb4e2de3b5 --- /dev/null +++ b/docqueries/withPoints/withPointsVia.test.sql @@ -0,0 +1,47 @@ +SET extra_float_digits=-3; +/* -- q0 */ +SELECT * FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, -3, 9], false); +/* -- q1 */ +SELECT * FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]); +/* -- q2 */ +SELECT agg_cost FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]) +WHERE path_id = 3 AND edge <0; +/* -- q3 */ +SELECT route_agg_cost FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]) +WHERE path_id = 3 AND edge < 0; +/* -- q4 */ +SELECT row_number() over () as node_seq, node +FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]) +WHERE edge <> -1 ORDER BY seq; +/* -- q5 */ +SELECT path_id, route_agg_cost FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4]) +WHERE edge < 0; +/* -- q6 */ +SELECT seq, node, +CASE WHEN edge = -1 THEN 'visits' +ELSE 'passes in front' +END as status +FROM pgr_withPointsVia( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', + 'SELECT pid, edge_id, fraction, side from pointsOfInterest', + ARRAY[-1, 5, -3, 9, 4], details => true) +WHERE agg_cost <> 0 or seq = 1; +/* -- q7 */ From 8f632f239b0531e5335d544b9903f14079143ca1 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Fri, 18 Feb 2022 13:48:00 -0600 Subject: [PATCH 06/10] [Via][queries] standarizng queries for via functions --- .../dijkstra/doc-pgr_dijkstraVia.result | 120 +++++++++--------- .../dijkstra/doc-pgr_dijkstraVia.test.sql | 22 ++-- docqueries/trsp/trspVia.result | 15 ++- docqueries/trsp/trspVia.test.sql | 2 +- 4 files changed, 81 insertions(+), 78 deletions(-) diff --git a/docqueries/dijkstra/doc-pgr_dijkstraVia.result b/docqueries/dijkstra/doc-pgr_dijkstraVia.result index 94bca3f3928..74f1f95e3fa 100644 --- a/docqueries/dijkstra/doc-pgr_dijkstraVia.result +++ b/docqueries/dijkstra/doc-pgr_dijkstraVia.result @@ -2,89 +2,75 @@ BEGIN; BEGIN SET client_min_messages TO NOTICE; SET -/* -- q00 */ -SELECT * FROM pgr_dijkstraVia( - 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 3, 9] -); - seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost ------+---------+----------+-----------+---------+------+------+------+----------+---------------- - 1 | 1 | 1 | 1 | 3 | 1 | 1 | 1 | 0 | 0 - 2 | 1 | 2 | 1 | 3 | 2 | 4 | 1 | 1 | 1 - 3 | 1 | 3 | 1 | 3 | 5 | 8 | 1 | 2 | 2 - 4 | 1 | 4 | 1 | 3 | 6 | 9 | 1 | 3 | 3 - 5 | 1 | 5 | 1 | 3 | 9 | 16 | 1 | 4 | 4 - 6 | 1 | 6 | 1 | 3 | 4 | 3 | 1 | 5 | 5 - 7 | 1 | 7 | 1 | 3 | 3 | -1 | 0 | 6 | 6 - 8 | 2 | 1 | 3 | 9 | 3 | 5 | 1 | 0 | 6 - 9 | 2 | 2 | 3 | 9 | 6 | 9 | 1 | 1 | 7 - 10 | 2 | 3 | 3 | 9 | 9 | -2 | 0 | 2 | 8 -(10 rows) - /* -- q01 */ SELECT * FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 3, 9], false, strict:=true, U_turn_on_edge:=false + ARRAY[1, 7, 10] ); seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost -----+---------+----------+-----------+---------+------+------+------+----------+---------------- - 1 | 1 | 1 | 1 | 3 | 1 | 1 | 1 | 0 | 0 - 2 | 1 | 2 | 1 | 3 | 2 | 2 | 1 | 1 | 1 - 3 | 1 | 3 | 1 | 3 | 3 | -1 | 0 | 2 | 2 - 4 | 2 | 1 | 3 | 9 | 3 | 3 | 1 | 0 | 2 - 5 | 2 | 2 | 3 | 9 | 4 | 16 | 1 | 1 | 3 - 6 | 2 | 3 | 3 | 9 | 9 | -2 | 0 | 2 | 4 -(6 rows) + 1 | 1 | 1 | 1 | 7 | 1 | 1 | 1 | 0 | 0 + 2 | 1 | 2 | 1 | 7 | 2 | 4 | 1 | 1 | 1 + 3 | 1 | 3 | 1 | 7 | 5 | 7 | 1 | 2 | 2 + 4 | 1 | 4 | 1 | 7 | 8 | 6 | 1 | 3 | 3 + 5 | 1 | 5 | 1 | 7 | 7 | -1 | 0 | 4 | 4 + 6 | 2 | 1 | 7 | 10 | 7 | 6 | 1 | 0 | 4 + 7 | 2 | 2 | 7 | 10 | 8 | 7 | 1 | 1 | 5 + 8 | 2 | 3 | 7 | 10 | 5 | 10 | 1 | 2 | 6 + 9 | 2 | 4 | 7 | 10 | 10 | -2 | 0 | 3 | 7 +(9 rows) /* -- q1 */ SELECT * FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ); seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost -----+---------+----------+-----------+---------+------+------+------+----------+---------------- 1 | 1 | 1 | 1 | 5 | 1 | 1 | 1 | 0 | 0 2 | 1 | 2 | 1 | 5 | 2 | 4 | 1 | 1 | 1 3 | 1 | 3 | 1 | 5 | 5 | -1 | 0 | 2 | 2 - 4 | 2 | 1 | 5 | 3 | 5 | 8 | 1 | 0 | 2 - 5 | 2 | 2 | 5 | 3 | 6 | 9 | 1 | 1 | 3 - 6 | 2 | 3 | 5 | 3 | 9 | 16 | 1 | 2 | 4 - 7 | 2 | 4 | 5 | 3 | 4 | 3 | 1 | 3 | 5 - 8 | 2 | 5 | 5 | 3 | 3 | -1 | 0 | 4 | 6 - 9 | 3 | 1 | 3 | 9 | 3 | 5 | 1 | 0 | 6 - 10 | 3 | 2 | 3 | 9 | 6 | 9 | 1 | 1 | 7 - 11 | 3 | 3 | 3 | 9 | 9 | -1 | 0 | 2 | 8 - 12 | 4 | 1 | 9 | 4 | 9 | 16 | 1 | 0 | 8 - 13 | 4 | 2 | 9 | 4 | 4 | -2 | 0 | 1 | 9 -(13 rows) + 4 | 2 | 1 | 5 | 7 | 5 | 7 | 1 | 0 | 2 + 5 | 2 | 2 | 5 | 7 | 8 | 6 | 1 | 1 | 3 + 6 | 2 | 3 | 5 | 7 | 7 | -1 | 0 | 2 | 4 + 7 | 3 | 1 | 7 | 10 | 7 | 6 | 1 | 0 | 4 + 8 | 3 | 2 | 7 | 10 | 8 | 7 | 1 | 1 | 5 + 9 | 3 | 3 | 7 | 10 | 5 | 10 | 1 | 2 | 6 + 10 | 3 | 4 | 7 | 10 | 10 | -1 | 0 | 3 | 7 + 11 | 4 | 1 | 10 | 4 | 10 | 12 | 1 | 0 | 7 + 12 | 4 | 2 | 10 | 4 | 11 | 13 | 1 | 1 | 8 + 13 | 4 | 3 | 10 | 4 | 12 | 15 | 1 | 2 | 9 + 14 | 4 | 4 | 10 | 4 | 9 | 16 | 1 | 3 | 10 + 15 | 4 | 5 | 10 | 4 | 4 | -2 | 0 | 4 | 11 +(15 rows) /* -- q2 */ SELECT agg_cost FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ) WHERE path_id = 3 AND edge <0; agg_cost ---------- - 2 + 3 (1 row) /* -- q3 */ SELECT route_agg_cost FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ) WHERE path_id = 3 AND edge < 0; route_agg_cost ---------------- - 8 + 7 (1 row) /* -- q4 */ SELECT row_number() over () as node_seq, node FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ) WHERE edge <> -1 ORDER BY seq; node_seq | node @@ -92,27 +78,29 @@ WHERE edge <> -1 ORDER BY seq; 1 | 1 2 | 2 3 | 5 - 4 | 6 - 5 | 9 - 6 | 4 - 7 | 3 - 8 | 6 - 9 | 9 - 10 | 4 -(10 rows) + 4 | 8 + 5 | 7 + 6 | 8 + 7 | 5 + 8 | 10 + 9 | 11 + 10 | 12 + 11 | 9 + 12 | 4 +(12 rows) /* -- q5 */ SELECT path_id, route_agg_cost FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ) WHERE edge < 0; path_id | route_agg_cost ---------+---------------- 1 | 2 - 2 | 6 - 3 | 8 - 4 | 9 + 2 | 4 + 3 | 7 + 4 | 11 (4 rows) /* -- q6 */ @@ -122,13 +110,23 @@ ELSE 'passes in front' END as status FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4]) -WHERE node = 9 and (agg_cost <> 0 or seq = 1); + ARRAY[1, 5, 7, 10, 4]) +WHERE agg_cost <> 0 or seq = 1; seq | route_agg_cost | node | agg_cost | status -----+----------------+------+----------+----------------- - 6 | 4 | 9 | 2 | passes in front - 11 | 8 | 9 | 2 | visits -(2 rows) + 1 | 0 | 1 | 0 | passes in front + 2 | 1 | 2 | 1 | passes in front + 3 | 2 | 5 | 2 | visits + 5 | 3 | 8 | 1 | passes in front + 6 | 4 | 7 | 2 | visits + 8 | 5 | 8 | 1 | passes in front + 9 | 6 | 5 | 2 | passes in front + 10 | 7 | 10 | 3 | visits + 12 | 8 | 11 | 1 | passes in front + 13 | 9 | 12 | 2 | passes in front + 14 | 10 | 9 | 3 | passes in front + 15 | 11 | 4 | 4 | passes in front +(12 rows) ROLLBACK; ROLLBACK diff --git a/docqueries/dijkstra/doc-pgr_dijkstraVia.test.sql b/docqueries/dijkstra/doc-pgr_dijkstraVia.test.sql index f08fc2bf5a2..838824736a2 100644 --- a/docqueries/dijkstra/doc-pgr_dijkstraVia.test.sql +++ b/docqueries/dijkstra/doc-pgr_dijkstraVia.test.sql @@ -1,25 +1,20 @@ -- documentation queries -/* -- q00 */ -SELECT * FROM pgr_dijkstraVia( - 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 3, 9] -); /* -- q01 */ SELECT * FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 3, 9], false, strict:=true, U_turn_on_edge:=false + ARRAY[1, 7, 10] ); /* -- q1 */ SELECT * FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ); /* -- q2 */ SELECT agg_cost FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ) WHERE path_id = 3 AND edge <0; @@ -27,7 +22,7 @@ WHERE path_id = 3 AND edge <0; /* -- q3 */ SELECT route_agg_cost FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ) WHERE path_id = 3 AND edge < 0; @@ -36,7 +31,7 @@ WHERE path_id = 3 AND edge < 0; SELECT row_number() over () as node_seq, node FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ) WHERE edge <> -1 ORDER BY seq; @@ -44,7 +39,7 @@ WHERE edge <> -1 ORDER BY seq; /* -- q5 */ SELECT path_id, route_agg_cost FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4] + ARRAY[1, 5, 7, 10, 4] ) WHERE edge < 0; @@ -56,6 +51,5 @@ ELSE 'passes in front' END as status FROM pgr_dijkstraVia( 'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id', - ARRAY[1, 5, 3, 9, 4]) -WHERE node = 9 and (agg_cost <> 0 or seq = 1); - + ARRAY[1, 5, 7, 10, 4]) +WHERE agg_cost <> 0 or seq = 1; diff --git a/docqueries/trsp/trspVia.result b/docqueries/trsp/trspVia.result index 2ebba579131..2722209ade9 100644 --- a/docqueries/trsp/trspVia.result +++ b/docqueries/trsp/trspVia.result @@ -124,11 +124,22 @@ FROM pgr_trspVia( $$SELECT id, source, target, cost, reverse_cost FROM edge_table order by id$$, $$SELECT path, cost FROM restrictions$$, ARRAY[1, 5, 7, 10, 4]) -WHERE node = 9 and (agg_cost <> 0 or seq = 1); +WHERE agg_cost <> 0 or seq = 1; seq | route_agg_cost | node | agg_cost | status -----+----------------+------+----------+----------------- + 1 | 0 | 1 | 0 | passes in front + 2 | 1 | 2 | 1 | passes in front + 3 | 2 | 5 | 2 | visits + 5 | 3 | 8 | 1 | passes in front + 6 | 4 | 7 | 2 | visits + 8 | 5 | 8 | 1 | passes in front + 9 | 6 | 5 | 2 | passes in front + 10 | 107 | 10 | 103 | visits + 12 | 108 | 11 | 1 | passes in front + 13 | 109 | 12 | 2 | passes in front 14 | 110 | 9 | 3 | passes in front -(1 row) + 15 | 111 | 4 | 4 | passes in front +(12 rows) /* -- q7 */ SELECT * FROM pgr_dijkstraVia( diff --git a/docqueries/trsp/trspVia.test.sql b/docqueries/trsp/trspVia.test.sql index de94dcda8ce..7a940cb2c80 100644 --- a/docqueries/trsp/trspVia.test.sql +++ b/docqueries/trsp/trspVia.test.sql @@ -49,7 +49,7 @@ FROM pgr_trspVia( $$SELECT id, source, target, cost, reverse_cost FROM edge_table order by id$$, $$SELECT path, cost FROM restrictions$$, ARRAY[1, 5, 7, 10, 4]) -WHERE node = 9 and (agg_cost <> 0 or seq = 1); +WHERE agg_cost <> 0 or seq = 1; /* -- q7 */ SELECT * FROM pgr_dijkstraVia( $$SELECT id, source, target, cost, reverse_cost FROM edge_table order by id$$, From ace2d55652d5db873d9b97eab3417b781384e410 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Fri, 18 Feb 2022 13:53:14 -0600 Subject: [PATCH 07/10] [withPointsVia][queries] adding documentation for new function --- doc/withPoints/pgr_withPointsVia.rst | 244 ++++++++++++++++----------- doc/withPoints/withPoints-family.rst | 2 + 2 files changed, 150 insertions(+), 96 deletions(-) diff --git a/doc/withPoints/pgr_withPointsVia.rst b/doc/withPoints/pgr_withPointsVia.rst index ef80f65c970..71d02d42eae 100644 --- a/doc/withPoints/pgr_withPointsVia.rst +++ b/doc/withPoints/pgr_withPointsVia.rst @@ -11,39 +11,46 @@ * **Supported versions:** `Latest `__ - (`3.3 `__) - `3.2 `__ - `3.1 `__ - `3.0 `__ + (`3.4 `__) -pgr_withPointsVia - Proposed +``pgr_withPointsVia`` - Proposed =============================================================================== -``pgr_withPointsVia`` - Get a path using the vertices/points indicated +``pgr_withPointsVia`` Via points/vertices routing. .. include:: proposed.rst - :start-after: begin-warning - :end-before: end-warning + :start-after: stable-begin-warning + :end-before: stable-end-warning .. figure:: images/boost-inside.jpeg :target: https://www.boost.org/libs/graph/doc/table_of_contents.html Boost Graph Inside -.. rubric:: Availability: +.. rubric:: Availability -* Version 3.0.0 +* Version 3.4.0 - * New **proposed** function + * New **proposed** function ``pgr_withPointsVia`` (`One Via`_) +| + Description ------------------------------------------------------------------------------- -Modify the graph to include points and -using Dijkstra algorithm, extracts all the nodes and points that have costs less -than or equal to the value ``distance`` from the starting point. -The edges extracted will conform the corresponding spanning tree. +Given a list of vertices and a graph, this function is equivalent to finding the +shortest path between :math:`vertex_i` and :math:`vertex_{i+1}` for all :math:`i +< size\_of(via\;vertices)` when vertices can be points. + +The paths represents the sections of the route. + +The general algorithm is as follows: + +* Add the additional points to the graph +* Execute a :doc:`pgr_dijkstraVia`. + +| Signatures ------------------------------------------------------------------------------- @@ -51,128 +58,173 @@ Signatures .. rubric:: Summary .. index:: - single: withPointsVia - Proposed on v2.2 + single: withPointsVia - Proposed on v3.4 -.. code-block:: none +.. parsed-literal:: - withPointsVia(edges_sql, points_sql, start_pid, distance [, directed] [, driving_side] [, details]) - RETURNS SET OF (seq, node, edge, cost, agg_cost) + pgr_withPointsVia(`Edges SQL`_, `Points SQL`_, **via vertices** + [, directed] [, strict] [, U_turn_on_edge]) -- Proposed on v3.4 + RETURNS SET OF (seq, path_pid, path_seq, start_vid, end_vid, + node, edge, cost, agg_cost, route_agg_cost) + OR EMPTY SET -.. rubric:: Using defaults -................................................... +| -.. code-block:: none +One Via +............................................................................... - withPointsVia(edges_sql, points_sql, start_pid, distance) - RETURNS SET OF (seq, node, edge, cost, agg_cost) +.. parsed-literal:: -:Example: * **TBD** + pgr_withPointsVia(`Edges SQL`_, `Points SQL`_, **via vertices** + [, directed] [, strict] [, U_turn_on_edge]) -- Proposed on v3.4 + RETURNS SET OF (seq, path_pid, path_seq, start_vid, end_vid, + node, edge, cost, agg_cost, route_agg_cost) + OR EMPTY SET -- For a **directed** graph. -- The driving side is set as **b** both. So arriving/departing to/from the point(s) can be in any direction. -- No **details** are given about distance of other points of the query. +:Example: Find the route that visits the vertices :math:`\{ -1, -3, 9\}` in that + order on an **undirected** graph. -.. literalinclude:: doc-pgr_withPointsVia.queries - :start-after: --q1 - :end-before: --q2 +.. literalinclude:: withPointsVia.queries + :start-after: -- q0 + :end-before: -- q1 -.. index:: - single: withPointsVia(edges_sql, points_sql, start_pid, distance, directed, driving_side, details) -- proposed +| -Driving distance from a single point +Parameters +------------------------------------------------------------------------------- + +.. list-table:: + :width: 81 + :widths: 14 20 7 40 + :header-rows: 1 + + * - Parameter + - Type + - Default + - Description + * - `Edges SQL`_ + - ``TEXT`` + - + - SQL query as described. + * - `Points SQL`_ + - ``TEXT`` + - + - SQL query as described. + * - **via vertices** + - ``ARRAY[`` **ANY-INTEGER** ``]`` + - + - Array of ordered vertices identifiers that are going to be visited. + + * When positive it is considered a vertex identifier + * When negative it is considered a point identifier + * - ``directed`` + - ``BOOLEAN`` + - ``true`` + - - When ``true`` Graph is considered `Directed` + - When ``false`` the graph is considered as Undirected. + +| + +Via optional parameters ............................................................................... -Finds the driving distance depending on the optional parameters setup. +.. include:: via-category.rst + :start-after: via_opt_parameters_start + :end-before: via_opt_parameters_end -.. code-block:: none +| - pgr_withPointsVia(edges_sql, points_sql, start_pid, distance, - directed := true, driving_side := 'b', details := false) - RETURNS SET OF (seq, node, edge, cost, agg_cost) +With points optional parameters +............................................................................... -:Example: Right side driving topology +.. include:: via-category.rst + :start-after: withPoints_parameters_start + :end-before: withPoints_parameters_end -.. literalinclude:: doc-pgr_withPointsVia.queries - :start-after: --q2 - :end-before: --q3 +| Inner query ------------------------------------------------------------------------------- -.. - description of the sql queries + +| + +Edges SQL +............................................................................... .. include:: pgRouting-concepts.rst :start-after: basic_edges_sql_start :end-before: basic_edges_sql_end +| + +Points SQL +............................................................................... + .. include:: pgRouting-concepts.rst :start-after: points_sql_start :end-before: points_sql_end -Parameters -............................................................................... +| + +Return Columns +------------------------------------------------------------------------------- + +.. include:: via-category.rst + :start-after: result columns start + :end-before: result columns end + +.. Note:: When ``start_vid`` or ``end_vid`` is negative, then it is a point. -================ ================= ================================================= -Parameter Type Description -================ ================= ================================================= -**edges_sql** ``TEXT`` Edges SQL query as described above. -**points_sql** ``TEXT`` Points SQL query as described above. -**start_pid** ``ANY-INTEGER`` Starting point id. -**distance** ``ANY_NUMERICAL`` Distance from the start_pid -**directed** ``BOOLEAN`` (optional). When ``false`` the graph is considered as Undirected. Default is ``true`` which considers the graph as Directed. -**driving_side** ``CHAR`` (optional) Value in ['b', 'r', 'l', NULL] indicating if the driving side is: - - In the right or left or - - If it doesn't matter with 'b' or NULL. - - If column not present 'b' is considered. - -**details** ``BOOLEAN`` (optional). When ``true`` the results will include the driving distance to the points with in Distance. - Default is ``false`` which ignores other points of the points_sql. -================ ================= ================================================= - -Result Columns -................................................... - -============ =========== ================================================= -Column Type Description -============ =========== ================================================= -**seq** ``INT`` row sequence. -**node** ``BIGINT`` Identifier of the node within the Distance from ``start_pid``. If ``details =: true`` a negative value is the identifier of a point. -**edge** ``BIGINT`` Identifier of the edge used to go from ``node`` to the next node in the path sequence. - - ``-1`` for the last row in the path sequence. - -**cost** ``FLOAT`` Cost to traverse from ``node`` using ``edge`` to the next ``node`` in the path sequence. - - ``0`` for the last row in the path sequence. - -**agg_cost** ``FLOAT`` Aggregate cost from ``start_pid`` to ``node``. - - ``0`` for the first row in the path sequence. - -============ =========== ================================================= +| Additional Examples ------------------------------------------------------------------------------- -- For queries marked as ``directed`` with ``cost`` and ``reverse_cost`` columns -- The examples in this section use the following :ref:`fig1` +:Example 1: Find the route that visits the vertices :math:`\{-1, 5, -3, 9, 4\}` + in that order on a **directed** graph + +.. literalinclude:: withPointsVia.queries + :start-after: -- q1 + :end-before: -- q2 + +:Example 2: What's the aggregate cost of the third path? + +.. literalinclude:: withPointsVia.queries + :start-after: -- q2 + :end-before: -- q3 + +:Example 3: What's the route's aggregate cost of the route at the end of the + third path? + +.. literalinclude:: withPointsVia.queries + :start-after: -- q3 + :end-before: -- q4 + +:Example 4: How are the nodes visited in the route? + +.. literalinclude:: withPointsVia.queries + :start-after: -- q4 + :end-before: -- q5 -:Example: Left side driving topology +:Example 5: What are the aggregate costs of the route when the visited vertices + are reached? -.. literalinclude:: doc-pgr_withPointsVia.queries - :start-after: --q3 - :end-before: --q4 +.. literalinclude:: withPointsVia.queries + :start-after: -- q5 + :end-before: -- q6 -:Example: Does not matter driving side. +:Example 6: Show a status of "passes in front" or "visits" of the nodes and + points. -.. literalinclude:: doc-pgr_withPointsVia.queries - :start-after: --q4 - :end-before: --q5 +.. literalinclude:: withPointsVia.queries + :start-after: -- q6 + :end-before: -- q7 See Also ------------------------------------------------------------------------------- -* :doc:`pgr_drivingDistance` - Driving distance using dijkstra. -* :doc:`pgr_alphaShape` - Alpha shape computation. -* :doc:`pgr_pointsAsPolygon` - Polygon around set of points. -* The queries use the :doc:`sampledata` network. +* :doc:`via-category` +* :doc:`sampledata` network. .. rubric:: Indices and tables diff --git a/doc/withPoints/withPoints-family.rst b/doc/withPoints/withPoints-family.rst index 4955966f5ca..a9beeb29ea6 100644 --- a/doc/withPoints/withPoints-family.rst +++ b/doc/withPoints/withPoints-family.rst @@ -38,6 +38,7 @@ When points are also given as input: - :doc:`pgr_withPointsCostMatrix` - Costs of the shortest paths. - :doc:`pgr_withPointsKSP` - K shortest paths. - :doc:`pgr_withPointsDD` - Driving distance. +- :doc:`pgr_withPointsVia` - Driving distance. .. index proposed to here @@ -49,6 +50,7 @@ When points are also given as input: pgr_withPointsCostMatrix pgr_withPointsKSP pgr_withPointsDD + pgr_withPointsVia Images From 2c08a6b605e1267aecf8f8b5b53952c014c5b6e1 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Fri, 18 Feb 2022 13:54:37 -0600 Subject: [PATCH 08/10] [Via][doc] standarizing Via functions documentation --- doc/conf.py.in | 8 +- doc/dijkstra/pgr_dijkstraVia.rst | 127 ++++++++++------- doc/src/CMakeLists.txt | 1 + doc/src/pgRouting-concepts.rst | 13 +- doc/src/proposed.rst | 6 + doc/src/routingFunctions.rst | 7 + doc/src/via-category.rst | 231 +++++++++++++++++++++++++++++++ doc/trsp/pgr_trspVia.rst | 91 ++++++++---- doc/trsp/pgr_trsp_withPoints.rst | 2 +- 9 files changed, 397 insertions(+), 89 deletions(-) create mode 100644 doc/src/via-category.rst diff --git a/doc/conf.py.in b/doc/conf.py.in index 115206d03f1..dbdfa095b60 100644 --- a/doc/conf.py.in +++ b/doc/conf.py.in @@ -95,11 +95,6 @@ locale_dirs = ['@CMAKE_SOURCE_DIR@/locale/'] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = [ - 'doc/build', - 'pgr_withPointsVia.rst', - 'maxFlowApplications.rst', - '*/notUsed', - 'tools/template' ] # 'src/pickDeliver/doc/pgr_withPointsVia.rst', @@ -321,7 +316,8 @@ linkcheck_ignore = [ 'https://docs.pgrouting.org/latest/en/TRSP-family.html', 'https://docs.pgrouting.org/latest/en/pgr_trsp_withPoints.html', 'https://docs.pgrouting.org/latest/en/pgr_trspVia.html', - 'https://docs.pgrouting.org/3.4/en/pgr_trspVia.html', + 'https://docs.pgrouting.org/latest/en/pgr_withPointsVia.html', + 'https://docs.pgrouting.org/3.4/en/pgr_withPointsVia.html', diff --git a/doc/dijkstra/pgr_dijkstraVia.rst b/doc/dijkstra/pgr_dijkstraVia.rst index 49fc95e97d2..72fcec32df3 100644 --- a/doc/dijkstra/pgr_dijkstraVia.rst +++ b/doc/dijkstra/pgr_dijkstraVia.rst @@ -44,14 +44,19 @@ a list of vertices. * New **proposed** function +| + Description ------------------------------------------------------------------------------- Given a list of vertices and a graph, this function is equivalent to finding the -shortest path between :math:`vertex_i` and :math:`vertex_{i+1}` for all :math:`i < size\_of(vertex_via)`. +shortest path between :math:`vertex_i` and :math:`vertex_{i+1}` for all :math:`i +< size\_of(vertex_via)`. The paths represents the sections of the route. +| + Signatures ------------------------------------------------------------------------------- @@ -60,54 +65,82 @@ Signatures .. index:: single: dijkstraVia - Proposed on 2.2 -.. code-block:: none - - pgr_dijkstraVia(edges_sql, via_vertices [, directed] [, strict] [, U_turn_on_edge]) - RETURNS SET OF (seq, path_pid, path_seq, start_vid, end_vid, - node, edge, cost, agg_cost, route_agg_cost) - OR EMPTY SET - -.. rubric:: Using default - -.. code-block:: none +.. parsed-literal:: - pgr_dijkstraVia(edges_sql, via_vertices) + pgr_dijkstraVia(`Edges SQL`_, **via vertices** + [, directed] [, strict] [, U_turn_on_edge]) RETURNS SET OF (seq, path_pid, path_seq, start_vid, end_vid, - node, edge, cost, agg_cost, route_agg_cost) + node, edge, cost, agg_cost, route_agg_cost) OR EMPTY SET -:Example: Find the route that visits the vertices :math:`\{ 1, 3, 9\}` in that order - -.. literalinclude:: doc-pgr_dijkstraVia.queries - :start-after: -- q00 - :end-before: -- q01 +| One Via ............................................................................... -.. code-block:: none +.. parsed-literal:: - pgr_dijkstraVia(edges_sql, via_vertices [, directed] [, strict] [, U_turn_on_edge]) + pgr_dijkstraVia(`Edges SQL`_, **via vertices** + [, directed] [, strict] [, U_turn_on_edge]) RETURNS SET OF (seq, path_pid, path_seq, start_vid, end_vid, - node, edge, cost, agg_cost, route_agg_cost) + node, edge, cost, agg_cost, route_agg_cost) OR EMPTY SET -:Example: Find the route that visits the vertices :math:`\{ 1, 3, 9\}` in that order on an **undirected** graph, avoiding U-turns when possible +:Example: Find the route that visits the vertices :math:`\{ 1, 7, 10\}` in that + order on an **directed** graph. .. literalinclude:: doc-pgr_dijkstraVia.queries :start-after: -- q01 :end-before: -- q1 +| + Parameters ------------------------------------------------------------------------------- -.. include:: pgRouting-concepts.rst - :start-after: pgr_dijkstra_via_parameters_start - :end-before: pgr_dijkstra_via_parameters_end +.. parameters_start + +.. list-table:: + :width: 81 + :widths: 14 20 7 40 + :header-rows: 1 + + * - Parameter + - Type + - Default + - Description + * - `Edges SQL`_ + - ``TEXT`` + - + - SQL query as described. + * - **via vertices** + - ``ARRAY[`` **ANY-INTEGER** ``]`` + - + - Array of ordered vertices identifiers that are going to be visited. + * - ``directed`` + - ``BOOLEAN`` + - ``true`` + - - When ``true`` Graph is considered `Directed` + - When ``false`` the graph is considered as Undirected. + +.. parameters_end + +| + +Via optional parameters +............................................................................... + +.. include:: via-category.rst + :start-after: via_opt_parameters_start + :end-before: via_opt_parameters_end + +| Inner query ------------------------------------------------------------------------------- +| + Edges SQL ............................................................................... @@ -115,38 +148,22 @@ Edges SQL :start-after: basic_edges_sql_start :end-before: basic_edges_sql_end +| + Return Columns ------------------------------------------------------------------------------- -.. via result columns start - -Returns set of ``(seq, path_pid, path_seq, start_vid, end_vid, node, edge, cost, agg_cost, route_agg_cost)`` - -================== ============= ================================================= -Column Type Description -================== ============= ================================================= -``seq`` ``BIGINT`` Sequential value starting from 1. -``path_pid`` ``BIGINT`` Identifier of the path. -``path_seq`` ``BIGINT`` Sequential value starting from 1 for the path. -``start_vid`` ``BIGINT`` Identifier of the starting vertex of the path. -``end_vid`` ``BIGINT`` Identifier of the ending vertex of the path. -``node`` ``BIGINT`` Identifier of the node in the path from start_vid to end_vid. -``edge`` ``BIGINT`` Identifier of the edge used to go from node to the next node in the path sequence. - - * -1 for the last node of the path. - * -2 for the last node of the route. +.. include:: via-category.rst + :start-after: result columns start + :end-before: result columns end -``cost`` ``FLOAT`` Cost to traverse from ``node`` using ``edge`` to the next node in the route sequence. -``agg_cost`` ``FLOAT`` Total cost from ``start_vid`` to ``end_vid`` of the path. -``route_agg_cost`` ``FLOAT`` Total cost from ``start_vid`` of ``seq = 1`` to ``end_vid`` of the current ``seq``. -================== ============= ================================================= - -.. via result columns end +| Additional Examples ------------------------------------------------------------------------------- -:Example 1: Find the route that visits the vertices :math:`\{1, 5, 3, 9, 4\}` in that order +:Example 1: Find the route that visits the vertices :math:`\{1, 5, 7, 10, 4\}` + in that order .. literalinclude:: doc-pgr_dijkstraVia.queries :start-after: -- q1 @@ -158,7 +175,8 @@ Additional Examples :start-after: -- q2 :end-before: -- q3 -:Example 3: What's the route's aggregate cost of the route at the end of the third path? +:Example 3: What's the route's aggregate cost of the route at the end of the + third path? .. literalinclude:: doc-pgr_dijkstraVia.queries :start-after: -- q3 @@ -170,13 +188,15 @@ Additional Examples :start-after: -- q4 :end-before: -- q5 -:Example 5: What are the aggregate costs of the route when the visited vertices are reached? +:Example 5: What are the aggregate costs of the route when the visited vertices + are reached? .. literalinclude:: doc-pgr_dijkstraVia.queries :start-after: -- q5 :end-before: -- q6 -:Example 6: Show the route's seq and aggregate cost and a status of "passes in front" or "visits" node :math:`9` +:Example 6: Show the route's seq and aggregate cost and a status of "passes in + front" or "visits" .. literalinclude:: doc-pgr_dijkstraVia.queries :start-after: -- q6 @@ -184,8 +204,9 @@ Additional Examples See Also ------------------------------------------------------------------------------- -* https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm +* :doc:`via-category`. * :doc:`sampledata` network. +* https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm .. rubric:: Indices and tables diff --git a/doc/src/CMakeLists.txt b/doc/src/CMakeLists.txt index 0ebf598abd3..25fb11db646 100644 --- a/doc/src/CMakeLists.txt +++ b/doc/src/CMakeLists.txt @@ -12,6 +12,7 @@ SET(LOCAL_FILES support.rst cost-category.rst costMatrix-category.rst + via-category.rst ) foreach (f ${LOCAL_FILES}) diff --git a/doc/src/pgRouting-concepts.rst b/doc/src/pgRouting-concepts.rst index 0eab7e89b5f..a91b28a3bfd 100644 --- a/doc/src/pgRouting-concepts.rst +++ b/doc/src/pgRouting-concepts.rst @@ -504,10 +504,12 @@ Points SQL * - ``pid`` - **ANY-INTEGER** - **value** - - (optional) Identifier of the point. + - Identifier of the point. - * If column present, it can not be NULL. - * If column not present, a sequential negative **value** will be given + * Use with positive value, as internally will be converted to negative + value + * If column is present, it can not be NULL. + * If column is not present, a sequential negative **value** will be given automatically. * - ``edge_id`` - **ANY-INTEGER** @@ -585,6 +587,11 @@ Parameters .. pgr_dijkstra_via_parameters_end +.. rubric:: Parameters for the Via functions: + +* :doc:`pgr_withPointsVia` + + | Return columns diff --git a/doc/src/proposed.rst b/doc/src/proposed.rst index 78515cb5d72..82a9cbcb5f2 100644 --- a/doc/src/proposed.rst +++ b/doc/src/proposed.rst @@ -115,6 +115,12 @@ Proposed Functions :start-after: index proposed from here :end-before: index proposed to here +:doc:`via-category` + +.. include:: via-category.rst + :start-after: proposed start + :end-before: proposed end + .. toctree:: :hidden: diff --git a/doc/src/routingFunctions.rst b/doc/src/routingFunctions.rst index 1576e4c954e..c9d4060073d 100644 --- a/doc/src/routingFunctions.rst +++ b/doc/src/routingFunctions.rst @@ -142,6 +142,12 @@ Functions by categories :start-after: index from here :end-before: index to here +:doc:`via-category` + +.. include:: via-category.rst + :start-after: from here + :end-before: to here + .. to-here .. toctree:: @@ -169,6 +175,7 @@ Functions by categories costMatrix-category drivingDistance-category spanningTree-family + via-category See Also ------------------------------------------------------------------------------- diff --git a/doc/src/via-category.rst b/doc/src/via-category.rst new file mode 100644 index 00000000000..3f2a3607ddb --- /dev/null +++ b/doc/src/via-category.rst @@ -0,0 +1,231 @@ +.. + **************************************************************************** + pgRouting Manual + Copyright(c) pgRouting Contributors + + This documentation is licensed under a Creative Commons Attribution-Share + Alike 3.0 License: https://creativecommons.org/licenses/by-sa/3.0/ + **************************************************************************** + +| + +* **Supported versions:** + `Latest `__ + (`3.4 `__) + +Via - Category +=============================================================================== + +.. from here + +* :doc:`pgr_dijkstraVia` + +.. to here + + +.. rubric:: proposed + +.. include:: proposed.rst + :start-after: begin-warning + :end-before: end-warning + +.. proposed start + +* :doc:`pgr_trspVia` +* :doc:`pgr_withPointsVia` + +.. proposed end + +General Information +------------------------------------------------------------------------------- + +This category intends to solve the general problem: + + Given a graph and a list of vertices, find the shortest path between + :math:`vertex_i` and :math:`vertex_{i+1}` for all vertices + +In other words, find a continuos route that visits all the vertices in the order +given. + +**path** + represents a section of a **route**. +**route** + is a sequence of **paths** + +| + +Parameters +------------------------------------------------------------------------------- + +Besides the compulsory parameters each function has, there are optional +parameters that exist due to the kind of function. + +Via optional parameters +............................................................................... + +.. rubric:: Used on all Via functions + +.. via_opt_parameters_start + +.. list-table:: + :width: 81 + :widths: 14 7 7 60 + :header-rows: 1 + + * - Parameter + - Type + - Default + - Description + * - ``strict`` + - ``BOOLEAN`` + - ``false`` + - * When ``true`` if a path is missing stops and returns **EMPTY SET** + * When ``false`` ignores missing paths returning all paths found + * - ``U_turn_on_edge`` + - ``BOOLEAN`` + - ``true`` + - * When ``true`` departing from a visited vertex will not try to avoid + +.. via_opt_parameters_end + +With points optional parameters +............................................................................... + +Used on + +* :doc:`pgr_withPointsVia` + +.. withPoints_parameters_start + +.. list-table:: + :width: 81 + :widths: 14 7 7 60 + :header-rows: 1 + + * - Parameter + - Type + - Default + - Description + * - ``driving_side`` + - ``CHAR`` + - ``b`` + - Value in [``b``, ``r``, ``l``, ``NULL``] indicating if the driving side is: + + - ``r`` for right driving side + - ``l`` for left driving side + - ``b`` for both, or ignore driving side + * - ``details`` + - ``BOOLEAN`` + - ``false`` + - - When ``true`` the results will include the points that are in the path. + - When ``false`` the results will not include the points that are in the path. + +.. withPoints_parameters_end + +| + +Inner query +------------------------------------------------------------------------------- + +Depending on the function one or more inner queries are needed. + +| + +Edges SQL +............................................................................... + +.. rubric:: Used on all Via functions + +.. include:: pgRouting-concepts.rst + :start-after: basic_edges_sql_start + :end-before: basic_edges_sql_end +| + +Restrictions SQL +............................................................................... + +Used on + +* :doc:`pgr_trspVia` + +.. include:: TRSP-family.rst + :start-after: restrictions_columns_start + :end-before: restrictions_columns_end +| + +Points SQL +............................................................................... + +Used on + +* :doc:`pgr_withPointsVia` + +.. include:: pgRouting-concepts.rst + :start-after: points_sql_start + :end-before: points_sql_end +| + +Return Columns +------------------------------------------------------------------------------- + +.. result columns start + +.. list-table:: + :width: 81 + :widths: 12 14 60 + :header-rows: 1 + + * - Column + - Type + - Description + * - ``seq`` + - ``INTEGER`` + - Sequential value starting from **1**. + * - ``path_id`` + - ``INTEGER`` + - Identifier of a path. Has value **1** for the first path. + * - ``path_seq`` + - ``INTEGER`` + - Relative position in the path. Has value **1** for the beginning of a path. + * - ``start_vid`` + - ``BIGINT`` + - Identifier of the starting vertex of the path. + * - ``end_vid`` + - ``BIGINT`` + - Identifier of the ending vertex of the path. + * - ``node`` + - ``BIGINT`` + - Identifier of the node in the path from ``start_vid`` to ``end_vid``. + * - ``edge`` + - ``BIGINT`` + - Identifier of the edge used to go from ``node`` to the next node in the + path sequence. + + * -1 for the last node of the path. + * -2 for the last node of the route. + * - ``cost`` + - ``FLOAT`` + - Cost to traverse from ``node`` using ``edge`` to the next node in the + path sequence. + * - ``agg_cost`` + - ``FLOAT`` + - Aggregate cost from ``start_vid`` to ``node``. + * - ``route_agg_cost`` + - ``FLOAT`` + - Total cost from ``start_vid`` of ``seq = 1`` to ``end_vid`` of the current ``seq``. + +.. result columns end + +| + +See Also +................ + +* :doc:`pgr_dijkstraVia` +* :doc:`pgr_trspVia` +* :doc:`pgr_withPointsVia` + +.. rubric:: Indices and tables + +* :ref:`genindex` +* :ref:`search` diff --git a/doc/trsp/pgr_trspVia.rst b/doc/trsp/pgr_trspVia.rst index 35c7873136c..f5c5abd0cd7 100644 --- a/doc/trsp/pgr_trspVia.rst +++ b/doc/trsp/pgr_trspVia.rst @@ -33,12 +33,14 @@ * New **proposed** function ``pgr_trspVia`` (`One Via`_) +| Description ------------------------------------------------------------------------------- -Given a list of vertices and a graph, this function is equivalent to finding the shortest path between :math:`vertex_i` -and :math:`vertex_{i+1}` for all :math:`i < size\_of(via\;vertices)` trying not to use restricted paths. +Given a list of vertices and a graph, this function is equivalent to finding the +shortest path between :math:`vertex_i` and :math:`vertex_{i+1}` for all :math:`i +< size\_of(via\;vertices)` trying not to use restricted paths. The paths represents the sections of the route. @@ -51,6 +53,8 @@ The general algorithm is as follows: * **NOTE** when this is done, ``U_turn_on_edge`` flag is ignored. +| + Signatures ------------------------------------------------------------------------------- @@ -61,36 +65,57 @@ Signatures .. parsed-literal:: - pgr_trspVia(`Edges SQL`_, `Restrictions SQL`_, **via vertices** [, directed] [, strict] [, U_turn_on_edge]) - RETURNS SET OF (seq, path_pid, path_seq, start_vid, end_vid, node, edge, cost, agg_cost, route_agg_cost) + pgr_trspVia(`Edges SQL`_, `Restrictions SQL`_, **via vertices** + [, directed] [, strict] [, U_turn_on_edge]) -- Proposed on v3.4 + RETURNS SET OF (seq, path_pid, path_seq, start_vid, end_vid, + node, edge, cost, agg_cost, route_agg_cost) OR EMPTY SET +| + One Via ............................................................................... .. parsed-literal:: - pgr_trspVia(`Edges SQL`_, `Restrictions SQL`_, **via vertices** [, directed] [, strict] [, U_turn_on_edge]) + pgr_trspVia(`Edges SQL`_, `Restrictions SQL`_, **via vertices** + [, directed] [, strict] [, U_turn_on_edge]) -- Proposed on v3.4 RETURNS SET OF (seq, path_pid, path_seq, start_vid, end_vid, - node, edge, cost, agg_cost, route_agg_cost) + node, edge, cost, agg_cost, route_agg_cost) OR EMPTY SET -:Example: Find the route that visits the vertices :math:`\{ 1, 7, 10\}` in that order on an **directed** graph. +:Example: Find the route that visits the vertices :math:`\{ 1, 7, 10\}` in that + order on an **directed** graph. .. literalinclude:: trspVia.queries :start-after: -- q0 :end-before: -- q1 +| + Parameters ------------------------------------------------------------------------------- -.. include:: pgRouting-concepts.rst - :start-after: pgr_dijkstra_via_parameters_start - :end-before: pgr_dijkstra_via_parameters_end +.. include:: pgr_dijkstraVia.rst + :start-after: parameters_start + :end-before: parameters_end + +| + +Via optional parameters +............................................................................... + +.. include:: via-category.rst + :start-after: via_opt_parameters_start + :end-before: via_opt_parameters_end + +| Inner query ------------------------------------------------------------------------------- +| + Edges SQL ............................................................................... @@ -98,6 +123,8 @@ Edges SQL :start-after: basic_edges_sql_start :end-before: basic_edges_sql_end +| + Restrictions SQL ............................................................................... @@ -105,17 +132,22 @@ Restrictions SQL :start-after: restrictions_columns_start :end-before: restrictions_columns_end +| + Return Columns ------------------------------------------------------------------------------- -.. include:: pgr_dijkstraVia.rst - :start-after: via result columns start - :end-before: via result columns end +.. include:: via-category.rst + :start-after: result columns start + :end-before: result columns end + +| Additional Examples ------------------------------------------------------------------------------- -:Example 1: Find the route that visits the vertices :math:`\{1, 5, 7, 10, 4\}` in that order +:Example 1: Find the route that visits the vertices :math:`\{1, 5, 7, 10, 4\}` + in that order .. literalinclude:: trspVia.queries :start-after: -- q1 @@ -127,7 +159,8 @@ Additional Examples :start-after: -- q2 :end-before: -- q3 -:Example 3: What's the route's aggregate cost of the route at the end of the third path? +:Example 3: What's the route's aggregate cost of the route at the end of the + third path? .. literalinclude:: trspVia.queries :start-after: -- q3 @@ -139,13 +172,15 @@ Additional Examples :start-after: -- q4 :end-before: -- q5 -:Example 5: What are the aggregate costs of the route when the visited vertices are reached? +:Example 5: What are the aggregate costs of the route when the visited vertices + are reached? .. literalinclude:: trspVia.queries :start-after: -- q5 :end-before: -- q6 -:Example 6: Show the route's seq and aggregate cost and a status of "passes in front" or "visits" node :math:`9` +:Example 6: Show the route's seq and aggregate cost and a status of "passes in + front" or "visits" .. literalinclude:: trspVia.queries :start-after: -- q6 @@ -159,8 +194,9 @@ The algorithm performs a :doc:`pgr_dijkstraVia` :start-after: -- q7 :end-before: -- q8 -Detects which of the sub paths pass through a restriction in this case is for the ``path_id = 1`` from ``2`` to ``8`` -because the path :math:`4 \rightarrow 7` is restricted. +Detects which of the sub paths pass through a restriction in this case is for +the ``path_id = 1`` from ``2`` to ``8`` because the path :math:`4 \rightarrow 7` +is restricted. Executes the :doc:`pgr_trsp` algorithm for the conflicting paths. @@ -168,8 +204,8 @@ Executes the :doc:`pgr_trsp` algorithm for the conflicting paths. :start-after: -- q8 :end-before: -- q9 -From the :doc:`pgr_dijkstraVia` result it removes the conflicting paths and builds the solution with the results of the -:doc:`pgr_trsp` algorithm: +From the :doc:`pgr_dijkstraVia` result it removes the conflicting paths and +builds the solution with the results of the :doc:`pgr_trsp` algorithm: .. literalinclude:: trspVia.queries :start-after: -- q9 @@ -181,16 +217,19 @@ Getting the same result as ``pgr_trspVia``: :start-after: -- q10 :end-before: -- q11 -:Example 8: Sometimes ``U_turn_on_edge`` flag is ignored when is set to ``false``. +:Example 8: Sometimes ``U_turn_on_edge`` flag is ignored when is set to + ``false``. -The first step, doing a :doc:`pgr_dijkstraVia` does consider not making a U turn on the same edge. But the path :math:`9 -\rightarrow 16` is restricted and the result is using it. +The first step, doing a :doc:`pgr_dijkstraVia` does consider not making a U turn +on the same edge. But the path :math:`9 \rightarrow 16` (Rows 4 and 5) is +restricted and the result is using it. .. literalinclude:: trspVia.queries :start-after: -- q11 :end-before: -- q12 -When executing the :doc:`pgr_trsp` algorithm for the conflicting path, there is no ``U_turn_on_edge`` flag. +When executing the :doc:`pgr_trsp` algorithm for the conflicting path, there is +no ``U_turn_on_edge`` flag. .. literalinclude:: trspVia.queries :start-after: -- q12 @@ -205,7 +244,7 @@ Therefore the result ignores the ``U_turn_on_edge`` flag when set to ``false``. See Also ------------------------------------------------------------------------------- -* :doc:`pgr_dijkstraVia` +* :doc:`via-category` * :doc:`sampledata` network. .. rubric:: Indices and tables diff --git a/doc/trsp/pgr_trsp_withPoints.rst b/doc/trsp/pgr_trsp_withPoints.rst index 92f4ad3c501..cc3a1297ede 100644 --- a/doc/trsp/pgr_trsp_withPoints.rst +++ b/doc/trsp/pgr_trsp_withPoints.rst @@ -202,7 +202,7 @@ Parameter Type Default Description ``directed`` ``BOOLEAN`` ``true`` - When ``true`` the graph is considered as directed. - When ``false`` the graph is considred as undirected. -``driving_side`` ``CHAR`` ``b`` Value in :math:`{b,r,l}` indicating if the driving side is: +``driving_side`` ``CHAR`` ``b`` Value in :math:`{b,r,l}` indicating if the driving side is: - ``r`` for right driving side - ``l`` for left driving side - ``b`` for both, or ignore driving side From 608b156f0fe3317376bfab17a194244fb1ab5576 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Fri, 18 Feb 2022 13:55:42 -0600 Subject: [PATCH 09/10] [doc] updating notes and news --- NEWS | 10 +++++++--- doc/src/release_notes.rst | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index ba885c92934..a25c03d75fb 100644 --- a/NEWS +++ b/NEWS @@ -3,13 +3,17 @@ pgRouting 3.4.0 Release Notes **New proposed functions** +* With points + + * ``pgr_withPointsVia`` (One Via) + * Turn Restrictions - * pgr_trspVia + * ``pgr_trspVia`` * ``pgr_trspVia`` (One Via) - * pgr_trsp + * ``pgr_trsp`` * ``pgr_trsp`` (One to One) * ``pgr_trsp`` (One to Many) @@ -17,7 +21,7 @@ pgRouting 3.4.0 Release Notes * ``pgr_trsp`` (Many to Many) * ``pgr_trsp`` (Combinations) - * pgr_trsp_withPoints + * ``pgr_trsp_withPoints`` * ``pgr_trsp_withPoints`` (One to One) * ``pgr_trsp_withPoints`` (One to Many) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 17412163362..e60b4033185 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -39,13 +39,17 @@ pgRouting 3.4.0 Release Notes .. rubric:: New proposed functions +* With points + + * ``pgr_withPointsVia`` (One Via) + * Turn Restrictions - * pgr_trspVia + * ``pgr_trspVia`` * ``pgr_trspVia`` (One Via) - * pgr_trsp + * ``pgr_trsp`` * ``pgr_trsp`` (One to One) * ``pgr_trsp`` (One to Many) @@ -53,7 +57,7 @@ pgRouting 3.4.0 Release Notes * ``pgr_trsp`` (Many to Many) * ``pgr_trsp`` (Combinations) - * pgr_trsp_withPoints + * ``pgr_trsp_withPoints`` * ``pgr_trsp_withPoints`` (One to One) * ``pgr_trsp_withPoints`` (One to Many) From d940d6dd81bae553b32e6dcaf36bd0f58ddd69ea Mon Sep 17 00:00:00 2001 From: cvvergara Date: Sat, 19 Feb 2022 08:07:42 -0600 Subject: [PATCH 10/10] [doc] ignoring links not exisiting yet --- doc/conf.py.in | 2 ++ doc/src/via-category.rst | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/conf.py.in b/doc/conf.py.in index dbdfa095b60..447c1594655 100644 --- a/doc/conf.py.in +++ b/doc/conf.py.in @@ -317,7 +317,9 @@ linkcheck_ignore = [ 'https://docs.pgrouting.org/latest/en/pgr_trsp_withPoints.html', 'https://docs.pgrouting.org/latest/en/pgr_trspVia.html', 'https://docs.pgrouting.org/latest/en/pgr_withPointsVia.html', + 'https://docs.pgrouting.org/latest/en/via-category.html', 'https://docs.pgrouting.org/3.4/en/pgr_withPointsVia.html', + 'https://docs.pgrouting.org/3.4/en/via-category.html', diff --git a/doc/src/via-category.rst b/doc/src/via-category.rst index 3f2a3607ddb..96621daf496 100644 --- a/doc/src/via-category.rst +++ b/doc/src/via-category.rst @@ -11,7 +11,7 @@ * **Supported versions:** `Latest `__ - (`3.4 `__) + (`3.4 `__) Via - Category ===============================================================================