diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 203f3c889b1..afe66d47ebb 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,3 +4,11 @@ updates: directory: "/" schedule: interval: "weekly" + target-branch: main + +#develop branch starts here +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + target-branch: develop diff --git a/.github/workflows/boost_version.yml b/.github/workflows/boost_version.yml index be1ee66cc92..b5c697698f2 100644 --- a/.github/workflows/boost_version.yml +++ b/.github/workflows/boost_version.yml @@ -131,5 +131,5 @@ jobs: sudo service postgresql start psql -c "CREATE DATABASE ___pgr___test___;" DIR=$(git rev-parse --show-toplevel) - bash "${DIR}/tools/testers/setup_db.sh" "${PGPORT}" ___pgr___test___ "${PG_RUNNER_USER}" "3.6.3" + bash "${DIR}/tools/testers/setup_db.sh" "${PGPORT}" ___pgr___test___ "${PG_RUNNER_USER}" "3.7.0" pg_prove -Q -f --normalize --directives --recurse -U "${PG_RUNNER_USER}" -d ___pgr___test___ "pgtap" diff --git a/.github/workflows/check-queries.yml b/.github/workflows/check-queries.yml index aa7addeaeff..432d50cde55 100644 --- a/.github/workflows/check-queries.yml +++ b/.github/workflows/check-queries.yml @@ -111,10 +111,13 @@ jobs: - name: Test documentation queries are up to date run: | sudo -u postgres createdb -p ${PGPORT} pgr_test__db__test - TESTDIRS="version" + # queries that might change + # version: will catch the current version + # mincut: results change depending on boost + TESTDIRS="version mincut" for d in ${TESTDIRS} do - ./tools/testers/doc_queries_generator.pl -pgver "${PGVER}" -pguser runner -documentation -alg "${d}" + ./tools/testers/doc_queries_generator.pl -pgver "${PGVER}" -pguser runner -documentation -alg "docqueries/${d}" done ./tools/testers/doc_queries_generator.pl -pgver "${PGVER}" diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2386333f2b8..3e1fceedec1 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -54,7 +54,7 @@ jobs: - name: install deps run: | - brew install postgresql postgis boost + brew install postgresql@14 postgis boost - name: Configure run: | @@ -66,24 +66,21 @@ jobs: run: | cd build make -j - sudo make install + make install - name: Install pgTAP - if: false run: | git clone https://github.com/theory/pgtap.git pgTapExtension cd pgTapExtension make -j - sudo make install - sudo cpan TAP::Parser::SourceHandler::pgTAP - sudo find /usr/local -name pg_prove - sudo ln -s /usr/local/Cellar/perl/5.32.1_1/bin/pg_prove symlink it into /usr/local/bin + make install + cpan TAP::Parser::SourceHandler::pgTAP + ln -s $(find `brew --prefix` -name pg_prove) symlink it into $(brew --prefix)/bin - name: Test - if: false run: | - export PATH=/usr/local/Cellar/perl/$(perl -e 'print substr($^V, 1)')/bin:$PATH - pg_ctl -D /usr/local/var/postgres start + export PATH=$(brew --prefix)/Cellar/perl/$(perl -e 'print substr($^V, 1)')/bin:$PATH + pg_ctl -D $(brew --prefix)/var/postgresql@14 start createuser -s postgres createdb ___pgr___test___ bash ./tools/testers/pg_prove_tests.sh postgres 5432 Release diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index d18d17c0192..4a023e06d42 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -29,12 +29,9 @@ jobs: strategy: fail-fast: false matrix: - psql: [11,12,13,14,15,16] + psql: [13,14,15,16] postgis: [3] - os: [ubuntu-latest, ububtu-22.04, ubuntu-20.04] - exclude: - - os: ubuntu-latest - psql: 11 + os: [ubuntu-latest, ubuntu-22.04, ubuntu-20.04] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 3227b31b0b2..2678618ec92 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - old_pgr: [3.6.2, 3.6.1, 3.6.0, 3.5.1, 3.5.0, 3.4.2, 3.4.1, 3.4.0, 3.3.5, 3.3.4, 3.3.3, 3.3.2, 3.3.1, 3.3.0, 3.0.6, 3.1.3, 3.2.0, 3.2.1, 3.2.2] + old_pgr: [3.6.3, 3.6.2, 3.6.1, 3.6.0, 3.5.1, 3.5.0, 3.4.2, 3.4.1, 3.4.0, 3.3.5, 3.3.4, 3.3.3, 3.3.2, 3.3.1, 3.3.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.6, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.2.0, 3.2.1, 3.2.2] steps: - uses: actions/checkout@v4 @@ -122,6 +122,6 @@ jobs: run: | sudo service postgresql start psql -p "${PGPORT}" -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();" - psql -p "${PGPORT}" -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.6.3';" + psql -p "${PGPORT}" -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.7.0';" psql -p "${PGPORT}" -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();" pg_prove -Q -f --normalize --directives --recurse -U "${PG_RUNNER_USER}" -d ___pgr___test___ "pgtap" diff --git a/CMakeLists.txt b/CMakeLists.txt index 32b88573e2e..8735fba9e7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ include(pgr/BuildType) #--------------------------------------------- #--------------------------------------------- -project(PGROUTING VERSION 3.6.3 +project(PGROUTING VERSION 3.7.0 LANGUAGES C CXX ) set(PROJECT_VERSION_DEV "") string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER) @@ -31,8 +31,9 @@ set(PROJECT_LIB_NAME "${PROJECT_NAME_LOWER}-${PROJECT_LIB_VERSION}") string(TIMESTAMP COMPILATION_DATE "%Y/%m/%d" UTC) -set(MINORS 3.6 3.5 3.4 3.3 3.2 3.1 3.0 2.6) +set(MINORS 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0 2.6) set(OLD_SIGNATURES + 3.6.3 3.6.2 3.6.1 3.6.0 @@ -61,7 +62,7 @@ include(pgr/Configure) #--------------------------------------------- set(DOXYGEN_MINIMUM_VERSION "1.7") set(SPHINX_MINIMUM_VERSION "4.0") -set(POSTGRESQL_MINIMUM_VERSION "11.0.0") +set(POSTGRESQL_MINIMUM_VERSION "13.0.0") set(BOOST_MINIMUM_VERSION "1.56.0") set(POSTGIS_MINIMUM_VERSION "3.0.0") @@ -187,6 +188,7 @@ string(REPLACE "." ";" VERSION_LIST ${POSTGRESQL_VERSION}) list(GET VERSION_LIST 0 POSTGRESQL_VERSION_MAYOR) list(GET VERSION_LIST 1 POSTGRESQL_VERSION_MINOR) +# calculate math value of postgres version math(EXPR PGSQL_VERSION "${POSTGRESQL_VERSION_MAYOR} * 1000 + ${POSTGRESQL_VERSION_MINOR}") message(STATUS "PGSQL_VERSION=${PGSQL_VERSION}") diff --git a/NEWS.md b/NEWS.md index ebff1e031c5..f376a828218 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,11 +1,69 @@ # pgRouting 3 -## pgRouting 3.6 +## pgRouting 3.7 .. current +### pgRouting 3.7.0 Release Notes + +To see all issues & pull requests closed by this release see the [Git closed +milestone for 3.7.0 +](https://github.com/pgRouting/pgrouting/issues?utf8=%E2%9C%93&q=milestone%3A%22Release%203.7.0%22) + +**Support** + +* [#2656](https://github.com/pgRouting/pgrouting/pull/2656) Stop support of + PostgreSQL12 on pgrouting v3.7 + + * Stopping support of PostgreSQL 12 + * CI does not test for PostgreSQL 12 + +**New experimental functions** + +* Metrics + + * pgr_betweennessCentrality + +**Official functions changes** + +* [#2605](https://github.com/pgRouting/pgrouting/pull/2605) Standarize + spanning tree functions output + + * Functions: + + * ``pgr_kruskalDD`` + * ``pgr_kruskalDFS`` + * ``pgr_kruskalBFS`` + * ``pgr_primDD`` + * ``pgr_primDFS`` + * ``pgr_primBFS`` + + * Standarizing output columns to ``(seq, depth, start_vid, pred, node, edge, cost, agg_cost)`` + * Added ``pred`` result columns. + +**Experimental promoted to proposed.** + +* [#2635](https://github.com/pgRouting/pgrouting/pull/2635) pgr_LineGraph + ignores directed flag and use negative values for identifiers. + + * ``pgr_lineGraph`` + + * Promoted to **proposed** signature. + * Works for directed and undirected graphs. + +**Code enhancement** + +* [#2599](https://github.com/pgRouting/pgrouting/pull/2599) Driving distance + cleanup +* [#2607](https://github.com/pgRouting/pgrouting/pull/2607) Read postgresql + data on C++ +* [#2614](https://github.com/pgRouting/pgrouting/pull/2614) Clang tidy does + not work + +## pgRouting 3.6 + ### pgRouting 3.6.3 Release Notes @@ -104,91 +162,61 @@ milestone for 3.6.0 * [#2547](https://github.com/pgRouting/pgrouting/pull/2547) Standarize output and modifying signature pgr_KSP - * Result columns standarized to: ``(seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)`` * ``pgr_ksp`` (One to One) - * Added ``start_vid`` and ``end_vid`` result columns. - * New overload functions: - * ``pgr_ksp`` (One to Many) * ``pgr_ksp`` (Many to One) * ``pgr_ksp`` (Many to Many) * ``pgr_ksp`` (Combinations) - * [#2548](https://github.com/pgRouting/pgrouting/pull/2548) Standarize output pgr_drivingdistance - * Standarizing output columns to ``(seq, depth, start_vid, pred, node, edge, cost, agg_cost)`` - * ``pgr_drivingdistance`` (Single vertex) - * Added ``depth`` and ``start_vid`` result columns. - * ``pgr_drivingdistance`` (Multiple vertices) - * Result column name change: ``from_v`` to ``start_vid``. * Added ``depth`` and ``pred`` result columns. - **Proposed functions changes** * [#2544](https://github.com/pgRouting/pgrouting/pull/2544) Standarize output and modifying signature pgr_withPointsDD - * Signature change: ``driving_side`` parameter changed from named optional to unnamed compulsory **driving side**. - * ``pgr_withPointsDD`` (`Single vertex`) * ``pgr_withPointsDD`` (`Multiple vertices`) - * Standarizing output columns to ``(seq, depth, start_vid, pred, node, edge, cost, agg_cost)`` - * ``pgr_withPointsDD`` (`Single vertex`) - * Added ``depth``, ``pred`` and ``start_vid`` column. - * ``pgr_withPointsDD`` (`Multiple vertices`) - * Added ``depth``, ``pred`` columns. - * When ``details`` is ``false``: - * Only points that are visited are removed, that is, points reached within the distance are included - * Deprecated signatures - * ``pgr_withpointsdd(text,text,bigint,double precision,boolean,character,boolean)`` * ``pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean)`` - * [#2546](https://github.com/pgRouting/pgrouting/pull/2546) Standarize output and modifying signature pgr_withPointsKSP - * Standarizing output columns to ``(seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)`` * ``pgr_withPointsKSP`` (One to One) - * Signature change: ``driving_side`` parameter changed from named optional to unnamed compulsory **driving side**. * Added ``start_vid`` and ``end_vid`` result columns. - * New overload functions - * ``pgr_withPointsKSP`` (One to Many) * ``pgr_withPointsKSP`` (Many to One) * ``pgr_withPointsKSP`` (Many to Many) * ``pgr_withPointsKSP`` (Combinations) - * Deprecated signature - * ``pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,char,boolean)`` - **C/C++ code enhancements** diff --git a/README.md b/README.md index ce6604abc27..3b4a0e0b175 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ The latest documentation: https://docs.pgrouting.org/latest * Compiling with Boost 1.56 up to Boost 1.74 requires C++ Compiler with C++03 or C++11 standard support * Compiling with Boost 1.75 requires C++ Compiler with C++14 standard support * Postgresql = Supported [version](https://www.postgresql.org/support/versioning/) by PostgreSQL + * Not supporting v12 & under * The Boost Graph Library (BGL) >= 1.56 * CMake >= 3.2 * 7.0 > Sphinx >= 4.0.0 diff --git a/ci/winnie/build_pgrouting.sh b/ci/winnie/build_pgrouting.sh index db8a10a7c5a..72ca229af9a 100644 --- a/ci/winnie/build_pgrouting.sh +++ b/ci/winnie/build_pgrouting.sh @@ -162,7 +162,6 @@ cmake --version cmake -G "MSYS Makefiles" -DCMAKE_VERBOSE_MAKEFILE=ON \ -DBOOST_ROOT:PATH="${BOOSTROOT_PATH}" \ -DBoost_USE_STATIC_LIBS=ON \ - -DBoost_USE_MULTITHREADED=ON \ -DCMAKE_BUILD_TYPE=Release \ "../branches/${PGROUTING_VER}" diff --git a/configuration.conf b/configuration.conf index aa53bb647b3..1f63c989983 100644 --- a/configuration.conf +++ b/configuration.conf @@ -46,6 +46,7 @@ planar | Y | Y | Y dominator | Y | Y | Y ordering | Y | Y | Y circuits | Y | Y | Y +metrics | Y | Y | Y #---------------------- # SQL only directories #---------------------- diff --git a/doc/_static/page_history.js b/doc/_static/page_history.js index 52eac606859..c29bbf5d25f 100644 --- a/doc/_static/page_history.js +++ b/doc/_static/page_history.js @@ -4,7 +4,7 @@ function createInfo(file, newat, altnames = '') { this.altnames = altnames; } -var versionsArr = ['3.6', '3.5', '3.4', '3.3', '3.2', '3.1', '3.0']; +var versionsArr = ['3.7', '3.6', '3.5', '3.4', '3.3', '3.2', '3.1', '3.0']; var unsuportedArr = ['2.6', '2.5', '2.4', '2.3', '2.2', '2.1', '2.0']; var titles = [ {k: 'en', v: ['Supported versions', 'Unsupported versions']}, @@ -14,6 +14,8 @@ var titles = [ var newpages = [ + {v: '3.7', pages: ['metrics-family', 'pgr_betweennessCentrality']}, + {v: '3.4', pages: ['TRSP-family', 'pgr_withPointsVia', 'pgr_trsp_withPoints', 'pgr_trspVia_withPoints', 'pgr_trspVia', 'pgr_hawickCircuits', 'pgr_findCloseEdges', 'pgr_cuthillMckeeOrdering', 'ordering-family', 'migration']}, diff --git a/doc/allpairs/pgr_floydWarshall.rst b/doc/allpairs/pgr_floydWarshall.rst index b3295130968..d0e5b687fab 100644 --- a/doc/allpairs/pgr_floydWarshall.rst +++ b/doc/allpairs/pgr_floydWarshall.rst @@ -60,7 +60,7 @@ Signatures :Example: For a directed subgraph with edges :math:`\{1, 2, 3, 4\}`. -.. literalinclude:: doc-floydWarshall.queries +.. literalinclude:: floydWarshall.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/allpairs/pgr_johnson.rst b/doc/allpairs/pgr_johnson.rst index c3effa52c8e..69102e68fba 100644 --- a/doc/allpairs/pgr_johnson.rst +++ b/doc/allpairs/pgr_johnson.rst @@ -58,7 +58,7 @@ Signatures :Example: For a directed subgraph with edges :math:`\{1, 2, 3, 4\}`. -.. literalinclude:: doc-johnson.queries +.. literalinclude:: johnson.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/alpha_shape/pgr_alphaShape.rst b/doc/alpha_shape/pgr_alphaShape.rst index d4c18cefc5a..81abc58200b 100644 --- a/doc/alpha_shape/pgr_alphaShape.rst +++ b/doc/alpha_shape/pgr_alphaShape.rst @@ -75,7 +75,7 @@ Signatures :Example: passing a geometry collection with spoon radius :math:`1.5` using the return variable ``geom`` -.. literalinclude:: doc-pgr_alphashape.queries +.. literalinclude:: alphashape.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/astar/pgr_aStar.rst b/doc/astar/pgr_aStar.rst index a8ce21fde24..95f268e2768 100644 --- a/doc/astar/pgr_aStar.rst +++ b/doc/astar/pgr_aStar.rst @@ -113,7 +113,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`12` on a **directed** graph with heuristic :math:`2` -.. literalinclude:: doc-astar.queries +.. literalinclude:: astar.queries :start-after: -- q2 :end-before: -- q3 @@ -135,7 +135,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 12\}` on a **directed** graph with heuristic :math:`3` and factor :math:`3.5` -.. literalinclude:: doc-astar.queries +.. literalinclude:: astar.queries :start-after: -- q3 :end-before: -- q4 @@ -157,7 +157,7 @@ Many to One :Example: From vertices :math:`\{6, 8\}` to vertex :math:`10` on an **undirected** graph with heuristic :math:`4` -.. literalinclude:: doc-astar.queries +.. literalinclude:: astar.queries :start-after: -- q4 :end-before: -- q5 @@ -179,7 +179,7 @@ Many to Many :Example: From vertices :math:`\{6, 8\}` to vertices :math:`\{10, 12\}` on a **directed** graph with factor :math:`0.5` -.. literalinclude:: doc-astar.queries +.. literalinclude:: astar.queries :start-after: -- q5 :end-before: -- q51 @@ -203,13 +203,13 @@ Combinations The combinations table: -.. literalinclude:: doc-astar.queries +.. literalinclude:: astar.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-astar.queries +.. literalinclude:: astar.queries :start-after: -- q52 :end-before: -- q6 @@ -263,19 +263,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-astar.queries +.. literalinclude:: astar.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start vids** the same as **end vids**. -.. literalinclude:: doc-astar.queries +.. literalinclude:: astar.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-astar.queries +.. literalinclude:: astar.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/astar/pgr_aStarCost.rst b/doc/astar/pgr_aStarCost.rst index cc77338152e..e25866d3857 100644 --- a/doc/astar/pgr_aStarCost.rst +++ b/doc/astar/pgr_aStarCost.rst @@ -99,7 +99,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`12` on a **directed** graph with heuristic :math:`2` -.. literalinclude:: doc-aStarCost.queries +.. literalinclude:: aStarCost.queries :start-after: -- q2 :end-before: -- q3 @@ -121,7 +121,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 12\}` on a **directed** graph with heuristic :math:`3` and factor :math:`3.5` -.. literalinclude:: doc-aStarCost.queries +.. literalinclude:: aStarCost.queries :start-after: -- q3 :end-before: -- q4 @@ -143,7 +143,7 @@ Many to One :Example: From vertices :math:`\{6, 8\}` to vertex :math:`10` on an **undirected** graph with heuristic :math:`4` -.. literalinclude:: doc-aStarCost.queries +.. literalinclude:: aStarCost.queries :start-after: -- q4 :end-before: -- q5 @@ -165,7 +165,7 @@ Many to Many :Example: From vertices :math:`\{6, 8\}` to vertices :math:`\{10, 12\}` on a **directed** graph with factor :math:`0.5` -.. literalinclude:: doc-aStarCost.queries +.. literalinclude:: aStarCost.queries :start-after: -- q5 :end-before: -- q51 @@ -189,13 +189,13 @@ Combinations The combinations table: -.. literalinclude:: doc-aStarCost.queries +.. literalinclude:: aStarCost.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-aStarCost.queries +.. literalinclude:: aStarCost.queries :start-after: -- q52 :end-before: -- q6 @@ -249,19 +249,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-aStarCost.queries +.. literalinclude:: aStarCost.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start vids** the same as **end vids**. -.. literalinclude:: doc-aStarCost.queries +.. literalinclude:: aStarCost.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-aStarCost.queries +.. literalinclude:: aStarCost.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/astar/pgr_aStarCostMatrix.rst b/doc/astar/pgr_aStarCostMatrix.rst index a4668eb6ed6..7f0320e57d6 100644 --- a/doc/astar/pgr_aStarCostMatrix.rst +++ b/doc/astar/pgr_aStarCostMatrix.rst @@ -72,7 +72,7 @@ Signatures :Example: Symmetric cost matrix for vertices :math:`\{5, 6, 10, 15\}` on an **undirected** graph using heuristic :math:`2` -.. literalinclude:: doc-aStarCostMatrix.queries +.. literalinclude:: aStarCostMatrix.queries :start-after: -- q2 :end-before: -- q3 @@ -119,7 +119,7 @@ Additional Examples :Example: Use with :doc:`pgr_TSP` -.. literalinclude:: doc-aStarCostMatrix.queries +.. literalinclude:: aStarCostMatrix.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/bdAstar/pgr_bdAstar.rst b/doc/bdAstar/pgr_bdAstar.rst index 1e4c2d6242c..5ef6b9a46cf 100644 --- a/doc/bdAstar/pgr_bdAstar.rst +++ b/doc/bdAstar/pgr_bdAstar.rst @@ -111,7 +111,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`12` on a **directed** graph with heuristic :math:`2` -.. literalinclude:: doc-pgr_bdAstar.queries +.. literalinclude:: bdAstar.queries :start-after: -- q2 :end-before: -- q3 @@ -133,7 +133,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 12\}` on a **directed** graph with heuristic :math:`3` and factor :math:`3.5` -.. literalinclude:: doc-pgr_bdAstar.queries +.. literalinclude:: bdAstar.queries :start-after: -- q3 :end-before: -- q4 @@ -155,7 +155,7 @@ Many to One :Example: From vertices :math:`\{6, 8\}` to vertex :math:`10` on an **undirected** graph with heuristic :math:`4` -.. literalinclude:: doc-pgr_bdAstar.queries +.. literalinclude:: bdAstar.queries :start-after: -- q4 :end-before: -- q5 @@ -177,7 +177,7 @@ Many to Many :Example: From vertices :math:`\{6, 8\}` to vertices :math:`\{10, 12\}` on a **directed** graph with factor :math:`0.5` -.. literalinclude:: doc-pgr_bdAstar.queries +.. literalinclude:: bdAstar.queries :start-after: -- q5 :end-before: -- q51 @@ -201,13 +201,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_bdAstar.queries +.. literalinclude:: bdAstar.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-pgr_bdAstar.queries +.. literalinclude:: bdAstar.queries :start-after: -- q52 :end-before: -- q6 @@ -261,19 +261,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-pgr_bdAstar.queries +.. literalinclude:: bdAstar.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start vids** the same as **end vids**. -.. literalinclude:: doc-pgr_bdAstar.queries +.. literalinclude:: bdAstar.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_bdAstar.queries +.. literalinclude:: bdAstar.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/bdAstar/pgr_bdAstarCost.rst b/doc/bdAstar/pgr_bdAstarCost.rst index 22bb68ded56..0a1fe77cb52 100644 --- a/doc/bdAstar/pgr_bdAstarCost.rst +++ b/doc/bdAstar/pgr_bdAstarCost.rst @@ -100,7 +100,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`12` on a **directed** graph with heuristic :math:`2` -.. literalinclude:: doc-pgr_bdAstarCost.queries +.. literalinclude:: bdAstarCost.queries :start-after: -- q2 :end-before: -- q3 @@ -122,7 +122,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 12\}` on a **directed** graph with heuristic :math:`3` and factor :math:`3.5` -.. literalinclude:: doc-pgr_bdAstarCost.queries +.. literalinclude:: bdAstarCost.queries :start-after: -- q3 :end-before: -- q4 @@ -144,7 +144,7 @@ Many to One :Example: From vertices :math:`\{6, 8\}` to vertex :math:`10` on an **undirected** graph with heuristic :math:`4` -.. literalinclude:: doc-pgr_bdAstarCost.queries +.. literalinclude:: bdAstarCost.queries :start-after: -- q4 :end-before: -- q5 @@ -166,7 +166,7 @@ Many to Many :Example: From vertices :math:`\{6, 8\}` to vertices :math:`\{10, 12\}` on a **directed** graph with factor :math:`0.5` -.. literalinclude:: doc-pgr_bdAstarCost.queries +.. literalinclude:: bdAstarCost.queries :start-after: -- q5 :end-before: -- q51 @@ -190,13 +190,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_bdAstarCost.queries +.. literalinclude:: bdAstarCost.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-pgr_bdAstarCost.queries +.. literalinclude:: bdAstarCost.queries :start-after: -- q52 :end-before: -- q6 @@ -250,19 +250,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-pgr_bdAstarCost.queries +.. literalinclude:: bdAstarCost.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start vids** the same as **end vids**. -.. literalinclude:: doc-pgr_bdAstarCost.queries +.. literalinclude:: bdAstarCost.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_bdAstarCost.queries +.. literalinclude:: bdAstarCost.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/bdAstar/pgr_bdAstarCostMatrix.rst b/doc/bdAstar/pgr_bdAstarCostMatrix.rst index d250933a483..6f97f581270 100644 --- a/doc/bdAstar/pgr_bdAstarCostMatrix.rst +++ b/doc/bdAstar/pgr_bdAstarCostMatrix.rst @@ -72,7 +72,7 @@ Signatures :Example: Symmetric cost matrix for vertices :math:`\{5, 6, 10, 15\}` on an **undirected** graph using heuristic :math:`2` -.. literalinclude:: doc-pgr_bdAstarCostMatrix.queries +.. literalinclude:: bdAstarCostMatrix.queries :start-after: -- q2 :end-before: -- q3 @@ -119,7 +119,7 @@ Additional Examples :Example: Use with :doc:`pgr_TSP` -.. literalinclude:: doc-pgr_bdAstarCostMatrix.queries +.. literalinclude:: bdAstarCostMatrix.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/bdDijkstra/pgr_bdDijkstra.rst b/doc/bdDijkstra/pgr_bdDijkstra.rst index fd309b2deda..da46ca8c1af 100644 --- a/doc/bdDijkstra/pgr_bdDijkstra.rst +++ b/doc/bdDijkstra/pgr_bdDijkstra.rst @@ -94,7 +94,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`10` on a **directed** graph -.. literalinclude:: doc-pgr_bdDijkstra.queries +.. literalinclude:: bdDijkstra.queries :start-after: -- q2 :end-before: -- q3 @@ -115,7 +115,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 17\}` on a **directed** graph -.. literalinclude:: doc-pgr_bdDijkstra.queries +.. literalinclude:: bdDijkstra.queries :start-after: -- q3 :end-before: -- q4 @@ -136,7 +136,7 @@ Many to One :Example: From vertices :math:`\{6, 1\}` to vertex :math:`17` on a **directed** graph -.. literalinclude:: doc-pgr_bdDijkstra.queries +.. literalinclude:: bdDijkstra.queries :start-after: -- q4 :end-before: -- q5 @@ -157,7 +157,7 @@ Many to Many :Example: From vertices :math:`\{6, 1\}` to vertices :math:`\{10, 17\}` on an **undirected** graph -.. literalinclude:: doc-pgr_bdDijkstra.queries +.. literalinclude:: bdDijkstra.queries :start-after: -- q5 :end-before: -- q51 @@ -179,13 +179,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_bdDijkstra.queries +.. literalinclude:: bdDijkstra.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-pgr_bdDijkstra.queries +.. literalinclude:: bdDijkstra.queries :start-after: -- q52 :end-before: -- q6 @@ -232,19 +232,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-pgr_bdDijkstra.queries +.. literalinclude:: bdDijkstra.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start vids** the same as **end vids**. -.. literalinclude:: doc-pgr_bdDijkstra.queries +.. literalinclude:: bdDijkstra.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_bdDijkstra.queries +.. literalinclude:: bdDijkstra.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/bdDijkstra/pgr_bdDijkstraCost.rst b/doc/bdDijkstra/pgr_bdDijkstraCost.rst index f0e87ccbc4c..69cd2e453dc 100644 --- a/doc/bdDijkstra/pgr_bdDijkstraCost.rst +++ b/doc/bdDijkstra/pgr_bdDijkstraCost.rst @@ -85,7 +85,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`10` on a **directed** graph -.. literalinclude:: doc-pgr_bdDijkstraCost.queries +.. literalinclude:: bdDijkstraCost.queries :start-after: -- q2 :end-before: -- q3 @@ -106,7 +106,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 17\}` on a **directed** graph -.. literalinclude:: doc-pgr_bdDijkstraCost.queries +.. literalinclude:: bdDijkstraCost.queries :start-after: -- q3 :end-before: -- q4 @@ -127,7 +127,7 @@ Many to One :Example: From vertices :math:`\{6, 1\}` to vertex :math:`17` on a **directed** graph -.. literalinclude:: doc-pgr_bdDijkstraCost.queries +.. literalinclude:: bdDijkstraCost.queries :start-after: -- q4 :end-before: -- q5 @@ -148,7 +148,7 @@ Many to Many :Example: From vertices :math:`\{6, 1\}` to vertices :math:`\{10, 17\}` on an **undirected** graph -.. literalinclude:: doc-pgr_bdDijkstraCost.queries +.. literalinclude:: bdDijkstraCost.queries :start-after: -- q5 :end-before: -- q51 @@ -170,13 +170,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_bdDijkstraCost.queries +.. literalinclude:: bdDijkstraCost.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-pgr_bdDijkstraCost.queries +.. literalinclude:: bdDijkstraCost.queries :start-after: -- q52 :end-before: -- q6 @@ -223,19 +223,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-pgr_bdDijkstraCost.queries +.. literalinclude:: bdDijkstraCost.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start vids** the same as **end vids**. -.. literalinclude:: doc-pgr_bdDijkstraCost.queries +.. literalinclude:: bdDijkstraCost.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_bdDijkstraCost.queries +.. literalinclude:: bdDijkstraCost.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/bdDijkstra/pgr_bdDijkstraCostMatrix.rst b/doc/bdDijkstra/pgr_bdDijkstraCostMatrix.rst index 6931cd50d4f..cebff3a6001 100644 --- a/doc/bdDijkstra/pgr_bdDijkstraCostMatrix.rst +++ b/doc/bdDijkstra/pgr_bdDijkstraCostMatrix.rst @@ -64,7 +64,7 @@ Signatures :Example: Symmetric cost matrix for vertices :math:`\{5, 6, 10, 15\}` on an **undirected** graph -.. literalinclude:: doc-pgr_bdDijkstraCostMatrix.queries +.. literalinclude:: bdDijkstraCostMatrix.queries :start-after: -- q2 :end-before: -- q3 @@ -104,7 +104,7 @@ Additional Examples :Example: Use with :doc:`pgr_TSP`. -.. literalinclude:: doc-pgr_bdDijkstraCostMatrix.queries +.. literalinclude:: bdDijkstraCostMatrix.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/bellman_ford/pgr_bellmanFord.rst b/doc/bellman_ford/pgr_bellmanFord.rst index 1cf033cbf31..b0292322d7c 100644 --- a/doc/bellman_ford/pgr_bellmanFord.rst +++ b/doc/bellman_ford/pgr_bellmanFord.rst @@ -112,7 +112,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`10` on a **directed** graph -.. literalinclude:: doc-pgr_bellmanFord.queries +.. literalinclude:: bellmanFord.queries :start-after: -- q2 :end-before: -- q3 @@ -133,7 +133,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{ 10, 17\}` on a **directed** graph -.. literalinclude:: doc-pgr_bellmanFord.queries +.. literalinclude:: bellmanFord.queries :start-after: -- q3 :end-before: -- q4 @@ -154,7 +154,7 @@ Many to One :Example: From vertices :math:`\{6, 1\}` to vertex :math:`17` on a **directed** graph -.. literalinclude:: doc-pgr_bellmanFord.queries +.. literalinclude:: bellmanFord.queries :start-after: -- q4 :end-before: -- q5 @@ -175,7 +175,7 @@ Many to Many :Example: From vertices :math:`\{6, 1\}` to vertices :math:`\{10, 17\}` on an **undirected** graph -.. literalinclude:: doc-pgr_bellmanFord.queries +.. literalinclude:: bellmanFord.queries :start-after: -- q5 :end-before: -- q51 @@ -197,13 +197,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_bellmanFord.queries +.. literalinclude:: bellmanFord.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-pgr_bellmanFord.queries +.. literalinclude:: bellmanFord.queries :start-after: -- q52 :end-before: -- q6 @@ -250,19 +250,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-pgr_bellmanFord.queries +.. literalinclude:: bellmanFord.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start vids** the same as **end vids**. -.. literalinclude:: doc-pgr_bellmanFord.queries +.. literalinclude:: bellmanFord.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_bellmanFord.queries +.. literalinclude:: bellmanFord.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/bellman_ford/pgr_edwardMoore.rst b/doc/bellman_ford/pgr_edwardMoore.rst index ff103648894..e4a2c93eccc 100644 --- a/doc/bellman_ford/pgr_edwardMoore.rst +++ b/doc/bellman_ford/pgr_edwardMoore.rst @@ -114,7 +114,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`10` on a **directed** graph -.. literalinclude:: doc-pgr_edwardMoore.queries +.. literalinclude:: edwardMoore.queries :start-after: -- q2 :end-before: -- q3 @@ -135,7 +135,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{ 10, 17\}` on a **directed** graph -.. literalinclude:: doc-pgr_edwardMoore.queries +.. literalinclude:: edwardMoore.queries :start-after: -- q3 :end-before: -- q4 @@ -156,7 +156,7 @@ Many to One :Example: From vertices :math:`\{6, 1\}` to vertex :math:`17` on a **directed** graph -.. literalinclude:: doc-pgr_edwardMoore.queries +.. literalinclude:: edwardMoore.queries :start-after: -- q4 :end-before: -- q5 @@ -177,7 +177,7 @@ Many to Many :Example: From vertices :math:`\{6, 1\}` to vertices :math:`\{10, 17\}` on an **undirected** graph -.. literalinclude:: doc-pgr_edwardMoore.queries +.. literalinclude:: edwardMoore.queries :start-after: -- q5 :end-before: -- q51 @@ -199,13 +199,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_edwardMoore.queries +.. literalinclude:: edwardMoore.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-pgr_edwardMoore.queries +.. literalinclude:: edwardMoore.queries :start-after: -- q52 :end-before: -- q6 @@ -252,19 +252,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-pgr_edwardMoore.queries +.. literalinclude:: edwardMoore.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start vids** the same as **end vids**. -.. literalinclude:: doc-pgr_edwardMoore.queries +.. literalinclude:: edwardMoore.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_edwardMoore.queries +.. literalinclude:: edwardMoore.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/breadthFirstSearch/pgr_binaryBreadthFirstSearch.rst b/doc/breadthFirstSearch/pgr_binaryBreadthFirstSearch.rst index efcb51a6b6f..010310100b0 100644 --- a/doc/breadthFirstSearch/pgr_binaryBreadthFirstSearch.rst +++ b/doc/breadthFirstSearch/pgr_binaryBreadthFirstSearch.rst @@ -113,7 +113,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`10` on a **directed** graph -.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries +.. literalinclude:: binaryBreadthFirstSearch.queries :start-after: -- q1 :end-before: -- q2 @@ -134,7 +134,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 17\}` on a **directed** graph -.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries +.. literalinclude:: binaryBreadthFirstSearch.queries :start-after: -- q2 :end-before: -- q3 @@ -155,7 +155,7 @@ Many to One :Example: From vertices :math:`\{6, 1\}` to vertex :math:`17` on a **directed** graph -.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries +.. literalinclude:: binaryBreadthFirstSearch.queries :start-after: -- q3 :end-before: -- q4 @@ -176,7 +176,7 @@ Many to Many :Example: From vertices :math:`\{6, 1\}` to vertices :math:`\{10, 17\}` on an **undirected** graph -.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries +.. literalinclude:: binaryBreadthFirstSearch.queries :start-after: -- q4 :end-before: -- q5 @@ -198,13 +198,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries +.. literalinclude:: binaryBreadthFirstSearch.queries :start-after: -- q5 :end-before: -- q51 The query: -.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries +.. literalinclude:: binaryBreadthFirstSearch.queries :start-after: -- q51 :end-before: -- q6 @@ -252,7 +252,7 @@ Additional Examples :Example: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries +.. literalinclude:: binaryBreadthFirstSearch.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/breadthFirstSearch/pgr_breadthFirstSearch.rst b/doc/breadthFirstSearch/pgr_breadthFirstSearch.rst index 38e0af043ef..eb8c6d61e26 100644 --- a/doc/breadthFirstSearch/pgr_breadthFirstSearch.rst +++ b/doc/breadthFirstSearch/pgr_breadthFirstSearch.rst @@ -78,7 +78,7 @@ Single vertex :Example: From root vertex :math:`6` on a **directed** graph with edges in ascending order of ``id`` -.. literalinclude:: doc-pgr_breadthFirstSearch.queries +.. literalinclude:: breadthFirstSearch.queries :start-after: -- q1 :end-before: -- q2 @@ -99,7 +99,7 @@ Multiple vertices :Example: From root vertices :math:`\{12, 6\}` on an **undirected** graph with **depth** :math:`<= 2` and edges in ascending order of ``id`` -.. literalinclude:: doc-pgr_breadthFirstSearch.queries +.. literalinclude:: breadthFirstSearch.queries :start-after: -- q2 :end-before: -- q3 @@ -146,13 +146,13 @@ Additional Examples :Example: Same as `Single vertex`_ with edges in ascending order of ``id``. -.. literalinclude:: doc-pgr_breadthFirstSearch.queries +.. literalinclude:: breadthFirstSearch.queries :start-after: -- q1 :end-before: -- q2 :Example: Same as `Single vertex`_ with edges in descending order of ``id``. -.. literalinclude:: doc-pgr_breadthFirstSearch.queries +.. literalinclude:: breadthFirstSearch.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/chinese/pgr_chinesePostman.rst b/doc/chinese/pgr_chinesePostman.rst index c9526773166..4991c9bc254 100644 --- a/doc/chinese/pgr_chinesePostman.rst +++ b/doc/chinese/pgr_chinesePostman.rst @@ -52,7 +52,7 @@ Signatures :Example: -.. literalinclude:: doc-pgr_chinesePostman.queries +.. literalinclude:: chinesePostman.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/chinese/pgr_chinesePostmanCost.rst b/doc/chinese/pgr_chinesePostmanCost.rst index 0035a3f3a39..99fcdaa6170 100644 --- a/doc/chinese/pgr_chinesePostmanCost.rst +++ b/doc/chinese/pgr_chinesePostmanCost.rst @@ -51,7 +51,7 @@ Signatures :Example: -.. literalinclude:: doc-pgr_chinesePostmanCost.queries +.. literalinclude:: chinesePostmanCost.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/coloring/pgr_bipartite.rst b/doc/coloring/pgr_bipartite.rst index 86a98f45193..732ca04c93d 100644 --- a/doc/coloring/pgr_bipartite.rst +++ b/doc/coloring/pgr_bipartite.rst @@ -66,7 +66,7 @@ Signatures :Example: When the graph is bipartite -.. literalinclude:: doc-bipartite.queries +.. literalinclude:: bipartite.queries :start-after: --q1 :end-before: --q2 @@ -102,7 +102,7 @@ Additional Example The edge :math:`5 \rightarrow 1` will make subgraph with vertices :math:`\{1, 3, 7, 6, 5\}` an odd length cyclic graph, as the cycle has 5 vertices. -.. literalinclude:: doc-bipartite.queries +.. literalinclude:: bipartite.queries :start-after: --q2 :end-before: --q3 @@ -111,7 +111,7 @@ Edges in blue represent odd length cycle subgraph. .. image:: images/bipartite.png :scale: 40% -.. literalinclude:: doc-bipartite.queries +.. literalinclude:: bipartite.queries :start-after: --q3 :end-before: --q4 diff --git a/doc/coloring/pgr_edgeColoring.rst b/doc/coloring/pgr_edgeColoring.rst index 9c48d28ee0e..509ee6e8506 100644 --- a/doc/coloring/pgr_edgeColoring.rst +++ b/doc/coloring/pgr_edgeColoring.rst @@ -86,7 +86,7 @@ Signatures :Example: Graph coloring of pgRouting :doc:`sampledata` -.. literalinclude:: doc-edgeColoring.queries +.. literalinclude:: edgeColoring.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/coloring/pgr_sequentialVertexColoring.rst b/doc/coloring/pgr_sequentialVertexColoring.rst index 652e0e1b152..568fa305a87 100644 --- a/doc/coloring/pgr_sequentialVertexColoring.rst +++ b/doc/coloring/pgr_sequentialVertexColoring.rst @@ -76,7 +76,7 @@ Signatures :Example: Graph coloring of pgRouting :doc:`sampledata` -.. literalinclude:: doc-pgr_sequentialVertexColoring.queries +.. literalinclude:: sequentialVertexColoring.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/components/pgr_articulationPoints.rst b/doc/components/pgr_articulationPoints.rst index 1daaf30879d..8c1775231ce 100644 --- a/doc/components/pgr_articulationPoints.rst +++ b/doc/components/pgr_articulationPoints.rst @@ -67,7 +67,7 @@ Signatures :Example: The articulation points of the graph -.. literalinclude:: doc-pgr_articulationPoints.queries +.. literalinclude:: articulationPoints.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/components/pgr_biconnectedComponents.rst b/doc/components/pgr_biconnectedComponents.rst index cd3d36d7571..a4ed2df7b58 100644 --- a/doc/components/pgr_biconnectedComponents.rst +++ b/doc/components/pgr_biconnectedComponents.rst @@ -75,7 +75,7 @@ Signatures :Example: The biconnected components of the graph -.. literalinclude:: doc-pgr_biconnectedComponents.queries +.. literalinclude:: biconnectedComponents.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/components/pgr_bridges.rst b/doc/components/pgr_bridges.rst index 941da6b6193..093d6224878 100644 --- a/doc/components/pgr_bridges.rst +++ b/doc/components/pgr_bridges.rst @@ -63,7 +63,7 @@ Signatures :Example: The bridges of the graph -.. literalinclude:: doc-pgr_bridges.queries +.. literalinclude:: bridges.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/components/pgr_connectedComponents.rst b/doc/components/pgr_connectedComponents.rst index dc864e50dc0..b29b99fdca3 100644 --- a/doc/components/pgr_connectedComponents.rst +++ b/doc/components/pgr_connectedComponents.rst @@ -72,7 +72,7 @@ Signatures :Example: The connected components of the graph -.. literalinclude:: doc-pgr_connectedComponents.queries +.. literalinclude:: connectedComponents.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/components/pgr_makeConnected.rst b/doc/components/pgr_makeConnected.rst index 9382d01eaff..47f38dee98d 100644 --- a/doc/components/pgr_makeConnected.rst +++ b/doc/components/pgr_makeConnected.rst @@ -70,7 +70,7 @@ Signatures :Example: Query done on :doc:`sampledata` network gives the list of edges that are needed to connect the graph. -.. literalinclude:: doc-pgr_makeConnected.queries +.. literalinclude:: makeConnected.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/components/pgr_strongComponents.rst b/doc/components/pgr_strongComponents.rst index b0b58670e7a..d39b94ccf92 100644 --- a/doc/components/pgr_strongComponents.rst +++ b/doc/components/pgr_strongComponents.rst @@ -70,7 +70,7 @@ Signatures :Example: The strong components of the graph -.. literalinclude:: doc-pgr_strongComponents.queries +.. literalinclude:: strongComponents.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/contraction/contraction-family.rst b/doc/contraction/contraction-family.rst index 2dfc549683f..87a9c127cd6 100644 --- a/doc/contraction/contraction-family.rst +++ b/doc/contraction/contraction-family.rst @@ -439,7 +439,7 @@ Construction of the graph in the database The following query shows the original data involved in the contraction operation. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q00 :end-before: -- q01 @@ -458,7 +458,7 @@ algorithm. Observe that vertices, for example, :math:`6` do not appear in the results because it was not affected by the contraction algorithm. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q2 :end-before: -- q3 @@ -507,7 +507,7 @@ tables, where: * when ``false`` the edge is an original edge, might be or not part of the contracted graph. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q1 :end-before: -- q2 @@ -516,7 +516,7 @@ Store contraction information Store the `contraction results`_ in a table -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q3 :end-before: -- q4 @@ -526,20 +526,20 @@ The vertex table update Use ``is_contracted`` column to indicate the vertices that are contracted. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q4 :end-before: -- q5 Fill ``contracted_vertices`` with the information from the results tha belong to the vertices. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q6 :end-before: -- q7 The modified vertices table: -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q7 :end-before: -- q8 @@ -548,13 +548,13 @@ The edge table update Insert the new edges generated by pgr_contraction. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q8 :end-before: -- q9 The modified ``edge_table``. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q9 :end-before: -- q10 @@ -565,14 +565,14 @@ The contracted graph Vertices that belong to the contracted graph. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q10 :end-before: -- q11 Edges that belong to the contracted graph. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- q11 :end-before: -- case1 @@ -599,7 +599,7 @@ Case 1: Both source and target belong to the contracted graph. Using the `Edges that belong to the contracted graph.`_ on lines 11 to 20. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :emphasize-lines: 11-20 :start-after: -- case1 :end-before: -- use1 @@ -609,7 +609,7 @@ Using the `Edges that belong to the contracted graph.`_ on lines 11 to 20. When both source and target belong to the contracted graph, a path is found. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- use1 :end-before: -- use1-1 @@ -620,7 +620,7 @@ When source and/or target belong to an edge subgraph then a path is not found. In this case, the contracted graph do not have an edge connecting with node :math:`4`. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- use1-1 :end-before: -- use1-2 @@ -631,7 +631,7 @@ When source and/or target belong to a vertex then a path is not found. In this case, the contracted graph do not have an edge connecting with node :math:`7` and of node :math:`4` of the second case. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- use1-2 :end-before: -- case2 @@ -643,7 +643,7 @@ Refining the above function to include nodes that belong to an edge. - The vertices that need to be expanded are calculated on lines 11 to 17. - Adding to the contracted graph that additional section on lines 26 to 28. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :emphasize-lines: 11-17, 26-28 :start-after: -- case2 :end-before: -- use2 @@ -653,7 +653,7 @@ Refining the above function to include nodes that belong to an edge. When both source and target belong to the contracted graph, a path is found. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- use2 :end-before: -- use2-1 @@ -663,7 +663,7 @@ When source and/or target belong to an edge subgraph, now, a path is found. The routing graph now has an edge connecting with node :math:`4`. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- use2-1 :end-before: -- use2-2 @@ -674,7 +674,7 @@ When source and/or target belong to a vertex then a path is not found. In this case, the contracted graph do not have an edge connecting with node :math:`7`. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- use2-2 :end-before: -- case3 @@ -686,7 +686,7 @@ Refining the above function to include nodes that belong to an edge. - The vertices that need to be expanded are calculated on lines 19 to 24. - Adding to the contracted graph that additional section on lines 38 to 40. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :emphasize-lines: 19-24, 39-41 :start-after: -- case3 :end-before: -- use3 @@ -696,7 +696,7 @@ Refining the above function to include nodes that belong to an edge. When both source and target belong to the contracted graph, a path is found. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- use3 :end-before: -- use3-1 @@ -705,7 +705,7 @@ When both source and target belong to the contracted graph, a path is found. The code change do not affect this case so when source and/or target belong to an edge subgraph, a path is still found. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- use3-1 :end-before: -- use3-2 @@ -715,7 +715,7 @@ When source and/or target belong to a vertex, now, a path is found. Now, the routing graph has an edge connecting with node :math:`7`. -.. literalinclude:: doc-contraction-family.queries +.. literalinclude:: contraction-family.queries :start-after: -- use3-2 :end-before: -- end diff --git a/doc/contraction/pgr_contraction.rst b/doc/contraction/pgr_contraction.rst index c8d8774b9fa..7505cfe6bef 100644 --- a/doc/contraction/pgr_contraction.rst +++ b/doc/contraction/pgr_contraction.rst @@ -87,7 +87,7 @@ The pgr_contraction function has the following signature: :Example: Making a dead end and linear contraction in that order on an undirected graph. -.. literalinclude:: doc-pgr_contraction.queries +.. literalinclude:: contraction.queries :start-after: -- q1 :end-before: -- q2 @@ -213,13 +213,13 @@ Additional Examples :Example: Only dead end contraction -.. literalinclude:: doc-pgr_contraction.queries +.. literalinclude:: contraction.queries :start-after: -- q2 :end-before: -- q3 :Example: Only linear contraction -.. literalinclude:: doc-pgr_contraction.queries +.. literalinclude:: contraction.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/dagShortestPath/pgr_dagShortestPath.rst b/doc/dagShortestPath/pgr_dagShortestPath.rst index 62febb30470..c7a118b2f32 100644 --- a/doc/dagShortestPath/pgr_dagShortestPath.rst +++ b/doc/dagShortestPath/pgr_dagShortestPath.rst @@ -113,7 +113,7 @@ One to One :Example: From vertex :math:`5` to vertex :math:`11` on a **directed** graph -.. literalinclude:: doc-pgr_dagShortestPath.queries +.. literalinclude:: dagShortestPath.queries :start-after: -- q2 :end-before: -- q3 @@ -133,7 +133,7 @@ One to Many :Example: From vertex :math:`5` to vertices :math:`\{7, 11\}` -.. literalinclude:: doc-pgr_dagShortestPath.queries +.. literalinclude:: dagShortestPath.queries :start-after: -- q3 :end-before: -- q4 @@ -153,7 +153,7 @@ Many to One :Example: From vertices :math:`\{5, 10\}` to vertex :math:`11` -.. literalinclude:: doc-pgr_dagShortestPath.queries +.. literalinclude:: dagShortestPath.queries :start-after: -- q4 :end-before: -- q5 @@ -174,7 +174,7 @@ Many to Many :Example: From vertices :math:`\{5, 15\}` to vertices :math:`\{11, 17\}` on an **undirected** graph -.. literalinclude:: doc-pgr_dagShortestPath.queries +.. literalinclude:: dagShortestPath.queries :start-after: -- q5 :end-before: -- q51 @@ -196,13 +196,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-pgr_dagShortestPath.queries +.. literalinclude:: dagShortestPath.queries :start-after: -- q52 :end-before: -- q6 @@ -242,19 +242,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-pgr_dagShortestPath.queries +.. literalinclude:: dagShortestPath.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start_vids** the same as **end_vids** -.. literalinclude:: doc-pgr_dagShortestPath.queries +.. literalinclude:: dagShortestPath.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_dagShortestPath.queries +.. literalinclude:: dagShortestPath.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/dijkstra/pgr_dijkstra.rst b/doc/dijkstra/pgr_dijkstra.rst index f5fc67744ed..a4366700350 100644 --- a/doc/dijkstra/pgr_dijkstra.rst +++ b/doc/dijkstra/pgr_dijkstra.rst @@ -108,7 +108,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`10` on a **directed** graph -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q2 :end-before: -- q3 @@ -128,7 +128,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 17\}` on a **directed** -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q3 :end-before: -- q4 @@ -149,7 +149,7 @@ Many to One :Example: From vertices :math:`\{6, 1\}` to vertex :math:`17` on a **directed** graph -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q4 :end-before: -- q5 @@ -170,7 +170,7 @@ Many to Many :Example: From vertices :math:`\{6, 1\}` to vertices :math:`\{10, 17\}` on an **undirected** graph -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q5 :end-before: -- q51 @@ -192,13 +192,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q52 :end-before: -- q6 @@ -245,19 +245,19 @@ Additional Examples :Example: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start_vids** the same as **end_vids** -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q7 :end-before: -- q8 :Example: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q8 :end-before: -- q9 @@ -278,28 +278,28 @@ For **directed** graphs with ``cost`` and ``reverse_cost`` columns 1) Path from :math:`6` to :math:`10` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q70 :end-before: -- q71 2) Path from :math:`6` to :math:`7` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q71 :end-before: -- q72 3) Path from :math:`12` to :math:`10` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q72 :end-before: -- q73 4) Path from :math:`12` to :math:`7` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q73 :end-before: -- q74 @@ -308,7 +308,7 @@ For **directed** graphs with ``cost`` and ``reverse_cost`` columns Paths :math:`\{6\}\rightarrow\{10, 7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q74 :end-before: -- q75 @@ -317,7 +317,7 @@ Paths :math:`\{6\}\rightarrow\{10, 7\}` Paths :math:`\{6, 12\}\rightarrow\{7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q75 :end-before: -- q76 @@ -326,7 +326,7 @@ Paths :math:`\{6, 12\}\rightarrow\{7\}` Paths :math:`\{6, 12\}\rightarrow\{10, 7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q76 :end-before: -- q77 @@ -335,7 +335,7 @@ Paths :math:`\{6, 12\}\rightarrow\{10, 7\}` Paths :math:`\{6\}\rightarrow\{10, 7\}\cup\{12\}\rightarrow\{10\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q77 :end-before: -- q80 @@ -350,28 +350,28 @@ For **undirected** graphs with ``cost`` and ``reverse_cost`` columns 9) Path from :math:`6` to :math:`10` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q90 :end-before: -- q91 10) Path from :math:`6` to :math:`7` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q91 :end-before: -- q92 11) Path from :math:`12` to :math:`10` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q92 :end-before: -- q93 12) Path from :math:`12` to :math:`7` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q93 :end-before: -- q94 @@ -380,7 +380,7 @@ For **undirected** graphs with ``cost`` and ``reverse_cost`` columns Paths :math:`\{6\}\rightarrow\{10, 7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q94 :end-before: -- q95 @@ -389,7 +389,7 @@ Paths :math:`\{6\}\rightarrow\{10, 7\}` Paths :math:`\{6, 12\}\rightarrow\{7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q95 :end-before: -- q96 @@ -398,7 +398,7 @@ Paths :math:`\{6, 12\}\rightarrow\{7\}` Paths :math:`\{6, 12\}\rightarrow\{10, 7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q96 :end-before: -- q97 @@ -407,7 +407,7 @@ Paths :math:`\{6, 12\}\rightarrow\{10, 7\}` Paths :math:`\{6\}\rightarrow\{10, 7\}\cup\{12\}\rightarrow\{10\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q97 :end-before: -- q10 @@ -422,28 +422,28 @@ For **directed** graphs only with ``cost`` column 17) Path from :math:`6` to :math:`10` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q11 :end-before: -- q111 18) Path from :math:`6` to :math:`7` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q111 :end-before: -- q112 19) Path from :math:`12` to :math:`10` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q112 :end-before: -- q113 20) Path from :math:`12` to :math:`7` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q113 :end-before: -- q114 @@ -452,7 +452,7 @@ For **directed** graphs only with ``cost`` column Paths :math:`\{6\}\rightarrow\{10, 7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q114 :end-before: -- q115 @@ -461,7 +461,7 @@ Paths :math:`\{6\}\rightarrow\{10, 7\}` Paths :math:`\{6, 12\}\rightarrow\{7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q115 :end-before: -- q116 @@ -470,7 +470,7 @@ Paths :math:`\{6, 12\}\rightarrow\{7\}` Paths :math:`\{6, 12\}\rightarrow\{10, 7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q116 :end-before: -- q117 @@ -479,7 +479,7 @@ Paths :math:`\{6, 12\}\rightarrow\{10, 7\}` Paths :math:`\{6\}\rightarrow\{10, 7\}\cup\{12\}\rightarrow\{10\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q117 :end-before: -- q12 @@ -494,28 +494,28 @@ For **undirected** graphs only with ``cost`` column 25) Path from :math:`6` to :math:`10` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q13 :end-before: -- q131 26) Path from :math:`6` to :math:`7` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q131 :end-before: -- q132 27) Path from :math:`12` to :math:`10` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q132 :end-before: -- q133 28) Path from :math:`12` to :math:`7` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q133 :end-before: -- q134 @@ -524,7 +524,7 @@ For **undirected** graphs only with ``cost`` column Paths :math:`\{6\}\rightarrow\{10, 7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q134 :end-before: -- q135 @@ -533,7 +533,7 @@ Paths :math:`\{6\}\rightarrow\{10, 7\}` Paths :math:`\{6, 12\}\rightarrow\{7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q135 :end-before: -- q136 @@ -542,7 +542,7 @@ Paths :math:`\{6, 12\}\rightarrow\{7\}` Paths :math:`\{6, 12\}\rightarrow\{10, 7\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q136 :end-before: -- q137 @@ -551,7 +551,7 @@ Paths :math:`\{6, 12\}\rightarrow\{10, 7\}` Paths :math:`\{6\}\rightarrow\{10, 7\}\cup\{12\}\rightarrow\{10\}` -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q137 :end-before: -- q14 @@ -564,35 +564,35 @@ The following examples find the path for :math:`\{6\}\rightarrow\{10\}` 33) Using `One to One`_ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q15 :end-before: -- q151 34) Using `One to Many`_ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q151 :end-before: -- q152 35) Using `Many to One`_ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q152 :end-before: -- q153 36) Using `Many to Many`_ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q153 :end-before: -- q154 37) Using `Combinations`_ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q154 :end-before: -- q16 diff --git a/doc/dijkstra/pgr_dijkstraCost.rst b/doc/dijkstra/pgr_dijkstraCost.rst index f462f9c37db..96265e27f98 100644 --- a/doc/dijkstra/pgr_dijkstraCost.rst +++ b/doc/dijkstra/pgr_dijkstraCost.rst @@ -86,7 +86,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`10` on a **directed** graph -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q2 :end-before: -- q3 @@ -107,7 +107,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 17\}` on a **directed** graph -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q3 :end-before: -- q4 @@ -128,7 +128,7 @@ Many to One :Example: From vertices :math:`\{6, 1\}` to vertex :math:`17` on a **directed** graph -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q4 :end-before: -- q5 @@ -149,7 +149,7 @@ Many to Many :Example: From vertices :math:`\{6, 1\}` to vertices :math:`\{10, 17\}` on an **undirected** graph -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q5 :end-before: -- q51 @@ -171,13 +171,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q52 :end-before: -- q6 @@ -224,19 +224,19 @@ Additional Examples :Example 1: Demonstration of repeated values are ignored, and result is sorted. -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q6 :end-before: -- q7 :Example 2: Making **start_vids** the same as **end_vids** -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q7 :end-before: -- q8 :Example 3: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_dijkstraCost.queries +.. literalinclude:: dijkstraCost.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/dijkstra/pgr_dijkstraCostMatrix.rst b/doc/dijkstra/pgr_dijkstraCostMatrix.rst index 2af45b2e8f8..3ad97f1f70c 100644 --- a/doc/dijkstra/pgr_dijkstraCostMatrix.rst +++ b/doc/dijkstra/pgr_dijkstraCostMatrix.rst @@ -62,7 +62,7 @@ Signatures :Example: Symmetric cost matrix for vertices :math:`\{5, 6, 10, 15\}` on an **undirected** graph -.. literalinclude:: doc-pgr_dijkstraCostMatrix.queries +.. literalinclude:: dijkstraCostMatrix.queries :start-after: -- q1 :end-before: -- q2 @@ -102,7 +102,7 @@ Additional Examples :Example: Use with :doc:`pgr_TSP`. -.. literalinclude:: doc-pgr_dijkstraCostMatrix.queries +.. literalinclude:: dijkstraCostMatrix.queries :start-after: -- q2 :end-before: -- q3 diff --git a/doc/dijkstra/pgr_dijkstraNear.rst b/doc/dijkstra/pgr_dijkstraNear.rst index a3b7b470aba..f1989f74128 100644 --- a/doc/dijkstra/pgr_dijkstraNear.rst +++ b/doc/dijkstra/pgr_dijkstraNear.rst @@ -118,7 +118,7 @@ One to Many * `cap => 1` -.. literalinclude:: doc-pgr_dijkstraNear.queries +.. literalinclude:: dijkstraNear.queries :start-after: -- q1 :end-before: -- q2 :linenos: @@ -148,7 +148,7 @@ Many to One * On line `4`: using the positional parameter: `directed` set to ``true`` * In line `5`: using named parameter `cap => 2` -.. literalinclude:: doc-pgr_dijkstraNear.queries +.. literalinclude:: dijkstraNear.queries :start-after: -- q2 :end-before: -- q3 :linenos: @@ -182,7 +182,7 @@ Many to Many * `cap => 1` * `global => true` -.. literalinclude:: doc-pgr_dijkstraNear.queries +.. literalinclude:: dijkstraNear.queries :start-after: -- q3 :end-before: -- q4 :linenos: @@ -216,7 +216,7 @@ Combinations The combinations contents: -.. literalinclude:: doc-pgr_dijkstraNear.queries +.. literalinclude:: dijkstraNear.queries :start-after: -- q4 :end-before: -- q41 @@ -232,7 +232,7 @@ The query: * `directed => true` * `cap => 1` -.. literalinclude:: doc-pgr_dijkstraNear.queries +.. literalinclude:: dijkstraNear.queries :start-after: -- q41 :end-before: -- q5 :linenos: diff --git a/doc/dijkstra/pgr_dijkstraNearCost.rst b/doc/dijkstra/pgr_dijkstraNearCost.rst index cb714fecaad..4327b8d4f73 100644 --- a/doc/dijkstra/pgr_dijkstraNearCost.rst +++ b/doc/dijkstra/pgr_dijkstraNearCost.rst @@ -93,7 +93,7 @@ One to Many * `cap => 1` -.. literalinclude:: doc-pgr_dijkstraNearCost.queries +.. literalinclude:: dijkstraNearCost.queries :start-after: -- q1 :end-before: -- q2 :linenos: @@ -123,7 +123,7 @@ Many to One * On line `4`: using the positional parameter: `directed` set to ``true`` * In line `5`: using named parameter `cap => 2` -.. literalinclude:: doc-pgr_dijkstraNearCost.queries +.. literalinclude:: dijkstraNearCost.queries :start-after: -- q2 :end-before: -- q3 :linenos: @@ -157,7 +157,7 @@ Many to Many * `cap => 1` * `global => true` -.. literalinclude:: doc-pgr_dijkstraNearCost.queries +.. literalinclude:: dijkstraNearCost.queries :start-after: -- q3 :end-before: -- q4 :linenos: @@ -191,7 +191,7 @@ Combinations The combinations contents: -.. literalinclude:: doc-pgr_dijkstraNear.queries +.. literalinclude:: dijkstraNear.queries :start-after: -- q4 :end-before: -- q41 @@ -207,7 +207,7 @@ The query: * `directed => true` * `cap => 1` -.. literalinclude:: doc-pgr_dijkstraNearCost.queries +.. literalinclude:: dijkstraNearCost.queries :start-after: -- q41 :end-before: -- q5 :linenos: diff --git a/doc/dijkstra/pgr_dijkstraVia.rst b/doc/dijkstra/pgr_dijkstraVia.rst index 729224777c1..9a6b0f00e29 100644 --- a/doc/dijkstra/pgr_dijkstraVia.rst +++ b/doc/dijkstra/pgr_dijkstraVia.rst @@ -61,7 +61,7 @@ One Via :Example: Find the route that visits the vertices :math:`\{5, 1, 8\}` in that order on an directed graph. -.. literalinclude:: doc-pgr_dijkstraVia.queries +.. literalinclude:: dijkstraVia.queries :start-after: -- q01 :end-before: -- q1 @@ -115,42 +115,42 @@ All this examples are about the route that visits the vertices :math:`\{5, 7, 1, The main query ............................................................................... -.. literalinclude:: doc-pgr_dijkstraVia.queries +.. literalinclude:: dijkstraVia.queries :start-after: -- q1 :end-before: -- q2 Aggregate cost of the third path. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstraVia.queries +.. literalinclude:: dijkstraVia.queries :start-after: -- q2 :end-before: -- q3 Route's aggregate cost of the route at the end of the third path. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstraVia.queries +.. literalinclude:: dijkstraVia.queries :start-after: -- q3 :end-before: -- q4 Nodes visited in the route. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstraVia.queries +.. literalinclude:: dijkstraVia.queries :start-after: -- q4 :end-before: -- q5 The aggregate costs of the route when the visited vertices are reached. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstraVia.queries +.. literalinclude:: dijkstraVia.queries :start-after: -- q5 :end-before: -- q6 Status of "passes in front" or "visits" of the nodes. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_dijkstraVia.queries +.. literalinclude:: dijkstraVia.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/dominator/pgr_lengauerTarjanDominatorTree.rst b/doc/dominator/pgr_lengauerTarjanDominatorTree.rst index 53e4def6640..cbdd2049ca3 100644 --- a/doc/dominator/pgr_lengauerTarjanDominatorTree.rst +++ b/doc/dominator/pgr_lengauerTarjanDominatorTree.rst @@ -66,7 +66,7 @@ Signatures :Example: The dominator tree with root vertex :math:`5` -.. literalinclude:: doc-lengauerTarjanDominatorTree.queries +.. literalinclude:: lengauerTarjanDominatorTree.queries :start-after: --q1 :end-before: --q2 @@ -109,7 +109,7 @@ Additional Examples :Example: Dominator tree of another component. -.. literalinclude:: doc-lengauerTarjanDominatorTree.queries +.. literalinclude:: lengauerTarjanDominatorTree.queries :start-after: --q2 :end-before: --q3 diff --git a/doc/driving_distance/drivingDistance-category.rst b/doc/driving_distance/drivingDistance-category.rst index 08978bef70c..440e6820ed0 100644 --- a/doc/driving_distance/drivingDistance-category.rst +++ b/doc/driving_distance/drivingDistance-category.rst @@ -61,7 +61,7 @@ Calculate nodes that are within a distance. Parameters ------------------------------------------------------------------------------- -.. mst-dd-params_start +.. spantree-params_start .. list-table:: :width: 81 @@ -91,7 +91,7 @@ Where: :ANY-NUMERIC: ``SMALLINT``, ``INTEGER``, ``BIGINT``, ``REAL``, ``FLOAT`` -.. mst-dd-params_end +.. spantree-params_end Inner Queries ------------------------------------------------------------------------------- diff --git a/doc/driving_distance/pgr_drivingDistance.rst b/doc/driving_distance/pgr_drivingDistance.rst index 003f563ebb7..e8ca25e24f3 100644 --- a/doc/driving_distance/pgr_drivingDistance.rst +++ b/doc/driving_distance/pgr_drivingDistance.rst @@ -79,7 +79,7 @@ Single Vertex :Example: From vertex :math:`11` for a distance of :math:`3.0` -.. literalinclude:: pgr_drivingDistance.queries +.. literalinclude:: drivingDistance.queries :start-after: --q5 :end-before: --q6 @@ -100,7 +100,7 @@ Multiple Vertices :Example: From vertices :math:`\{11, 16\}` for a distance of :math:`3.0` with equi-cost on a directed graph -.. literalinclude:: pgr_drivingDistance.queries +.. literalinclude:: drivingDistance.queries :start-after: --q6 :end-before: --q10 @@ -108,8 +108,8 @@ Parameters ------------------------------------------------------------------------------- .. include:: drivingDistance-category.rst - :start-after: mst-dd-params_start - :end-before: mst-dd-params_end + :start-after: spantree-params_start + :end-before: spantree-params_end Optional parameters ............................................................................... @@ -165,7 +165,7 @@ Additional Examples :Example: From vertices :math:`\{11, 16\}` for a distance of :math:`3.0` on an undirected graph -.. literalinclude:: pgr_drivingDistance.queries +.. literalinclude:: drivingDistance.queries :start-after: --q10 :end-before: --q15 diff --git a/doc/ksp/pgr_KSP.rst b/doc/ksp/pgr_KSP.rst index 6a17e818f1e..e0d7dd5f3f4 100644 --- a/doc/ksp/pgr_KSP.rst +++ b/doc/ksp/pgr_KSP.rst @@ -89,7 +89,7 @@ One to One :Example: Get 2 paths from :math:`6` to :math:`17` on a directed graph. -.. literalinclude:: doc-ksp.queries +.. literalinclude:: ksp.queries :start-after: --q1 :end-before: --q2 @@ -110,7 +110,7 @@ One to Many :Example: Get 2 paths from vertex :math:`6` to vertices :math:`\{10, 17\}` on a directed graph. -.. literalinclude:: doc-ksp.queries +.. literalinclude:: ksp.queries :start-after: --q2 :end-before: --q3 @@ -131,7 +131,7 @@ Many to One :Example: Get 2 paths from vertices :math:`\{6, 1\}` to vertex :math:`17` on a directed graph. -.. literalinclude:: doc-ksp.queries +.. literalinclude:: ksp.queries :start-after: --q3 :end-before: --q4 @@ -152,7 +152,7 @@ Many to Many :Example: Get 2 paths vertices :math:`\{6, 1\}` to vertices :math:`\{10, 17\}` on a directed graph. -.. literalinclude:: doc-ksp.queries +.. literalinclude:: ksp.queries :start-after: --q4 :end-before: --q5 @@ -175,13 +175,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_dijkstra.queries +.. literalinclude:: dijkstra.queries :start-after: -- q51 :end-before: -- q52 The query: -.. literalinclude:: doc-ksp.queries +.. literalinclude:: ksp.queries :start-after: --q5 :end-before: --q6 @@ -322,7 +322,7 @@ Additional Examples Also get the paths in the heap. -.. literalinclude:: doc-ksp.queries +.. literalinclude:: ksp.queries :start-after: --q6 :end-before: --q7 @@ -330,13 +330,13 @@ Also get the paths in the heap. Also get the paths in the heap. -.. literalinclude:: doc-ksp.queries +.. literalinclude:: ksp.queries :start-after: --q7 :end-before: --q8 :Example: Get 2 paths from vertices :math:`\{6, 1\}` to vertex :math:`17` on a undirected graph. -.. literalinclude:: doc-ksp.queries +.. literalinclude:: ksp.queries :start-after: --q8 :end-before: --q9 @@ -344,7 +344,7 @@ Also get the paths in the heap. Also get the paths in the heap. -.. literalinclude:: doc-ksp.queries +.. literalinclude:: ksp.queries :start-after: --q9 :end-before: --q10 diff --git a/doc/lineGraph/pgr_lineGraph.rst b/doc/lineGraph/pgr_lineGraph.rst index bbef0d027a5..8d64d93e980 100644 --- a/doc/lineGraph/pgr_lineGraph.rst +++ b/doc/lineGraph/pgr_lineGraph.rst @@ -10,7 +10,7 @@ | -pgr_lineGraph - Experimental +pgr_lineGraph - Proposed =============================================================================== ``pgr_lineGraph`` — Transforms the given graph into its corresponding edge-based @@ -21,12 +21,17 @@ graph. Boost Graph Inside -.. include:: experimental.rst - :start-after: begin-warn-expr - :end-before: end-warn-expr +.. include:: proposed.rst + :start-after: stable-begin-warning + :end-before: stable-end-warning .. rubric:: Availability +* Version 3.7.0 + + * Promoted to **proposed** signature. + * Works for directed and undirected graphs. + * Version 2.5.0 * New **Experimental** function @@ -47,12 +52,16 @@ Given a graph :math:`G`, its line graph :math:`L(G)` is a graph such that: - The ``cost`` and ``reverse_cost`` columns of the result represent existence of the edge. - When the graph is directed the result is directed. + + - To get the complete Line Graph use unique identifiers on the double way + edges (See `Additional Examples`_). + - When the graph is undirected the result is undirected. - The ``reverse_cost`` is always :math:`-1`. .. index:: - single: lineGraph - Experimental on v2.5 + single: lineGraph - Proposed on v3.7 Signatures ------------------------------------------------------------------------------- @@ -67,7 +76,7 @@ Signatures :Example: For an undirected graph with edges :math:'{2,4,5,8}' -.. literalinclude:: doc-pgr_lineGraph.queries +.. literalinclude:: lineGraph.queries :start-after: -- q1 :end-before: -- q2 @@ -163,6 +172,285 @@ Returns set of |result-lineg| * When `negative`: edge (``target``, ``source``) does not exist, therefore it’s not part of the graph. + +Additional Examples +------------------------------------------------------------------------------- + +.. contents:: + :local: + +Given the following directed graph + +:math:`G(V,E) = G(\{1,2,3,4\},\{ +1 \rightarrow 2, +1 \rightarrow 4, +2 \rightarrow 3, +3 \rightarrow 1, +3 \rightarrow 2, +3 \rightarrow 4, +4 \rightarrow 3\})` + +.. graphviz:: + + digraph G { + + subgraph clusterA { + style=invis; + edge [arrowsize=0.5,color=blue]; + node [shape=circle;style=filled;fontsize=8;fixedsize=true;width=.4;color=deepskyblue]; + v1 [label=1,pos="0,2!"]; + v2 [label=2,pos="2,2!"]; + v3 [label=3,pos="2,0!"]; + v4 [label=4,pos="0,0!"]; + + v1->{v2,v4} [color=blue]; + v3->{v2,v4} [dir=both,color=blue]; + v3->v1 [arrowsize=0.5,color=blue ]; + } + } + + +Representation as directed with shared edge identifiers +............................................................................... + +For the simplicity, the design of the edges table on the database, has the +edge's identifiers are represented with 3 digits: + +:hundreds: the source vertex +:tens: always 0, acts as a separator +:units: the target vertex + +In this image, + +* Single or double head arrows represent one edge (row) on the edges table. +* The numbers in the yellow shadow are the edge identifiers. + +.. graphviz:: + + digraph G { + + subgraph clusterA { + style=invis; + edge [arrowsize=0.5,color=blue]; + node [shape=circle;style=filled;fontsize=8;fixedsize=true;width=.4;color=deepskyblue]; + v1 [label=1,pos="0,2!"]; + v2 [label=2,pos="2,2!"]; + v3 [label=3,pos="2,0!"]; + v4 [label=4,pos="0,0!"]; + + v1->{v2,v4} [color=blue]; + v3->{v2,v4} [dir=both,color=blue]; + v3->v1 [arrowsize=0.5,color=blue ]; + } + + subgraph clusterB { + style=invis; + edge [arrowsize=0.5,color=red,fontsize=10,fontcolor=red]; + node [shape=circle;style=filled;fontsize=8;fixedsize=true;width=.4;color=yellow] + + s102 [label="102",pos="1,2!"]; + s104 [label="104",pos="0,1!"]; + s301 [label="301",pos="1,1!"]; + s203 [label="203",pos="2,1!"]; + s304 [label="304",pos="1,0!"]; + } + } + +Two pair of edges share the same identifier when the ``reverse_cost`` column is +used. + +* Edges :math:`{2 \rightarrow 3, 3 \rightarrow 2}` are represented with one edge + row with :math:`id=203`. +* Edges :math:`{3 \rightarrow 4, 4 \rightarrow 3}` are represented with one edge + row with :math:`id=304`. + +The graph can be created as follows: + +.. literalinclude:: lineGraph.queries + :start-after: -- q2 + :end-before: INSERT 0 5 + + +Line Graph of a directed graph represented with shared edges ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. literalinclude:: lineGraph.queries + :start-after: INSERT 0 5 + :end-before: -- q3 + +* The result is a directed graph. +* For :math:`seq=4` from :math:`203 \leftrightarrow 304` represent two edges +* For all the other values of ``seq`` represent one edge. +* The ``cost`` and ``reverse_cost`` values represent the existence of the edge. + + * When positive: the edge exists. + * When negative: the edge does not exist. + +.. graphviz:: + + digraph G { + + subgraph clusterA { + style=invis; + edge [arrowsize=0.5,color=blue]; + node [shape=circle;style=filled;fontsize=8;fixedsize=true;width=.4;color=deepskyblue]; + v1 [label=1,pos="0,4!"]; + v2 [label=2,pos="4,4!"]; + v3 [label=3,pos="4,0!"]; + v4 [label=4,pos="0,0!"]; + + v1->{v2,v4} [color=blue]; + v3->{v2,v4} [dir=both,color=blue]; + v3->v1 [arrowsize=0.5,color=blue ]; + } + + subgraph clusterB { + style=invis; + edge [arrowsize=0.5,labelfloat=true,color=red,fontsize=14,fontcolor=red]; + node [shape=circle;style=filled;fontsize=8;fixedsize=true;width=.4;color=yellow] + + s102 [label="102",pos="2,4!"]; + s104 [label="104",pos="0,2!"]; + s301 [label="301",pos="2,2!"]; + s203 [label="203",pos="4,2!"]; + s304 [label="304",pos="2,0!"]; + + s102 -> s203 [label=1]; + s104 -> s304 [label=2]; + s203 -> s203 [label=3,dir=both]; + s203 -> s301 [label=4]; + s203 -> s304 [label=5,dir=both]; + s301 -> s102 [label=6]; + s301 -> s104 [label=7]; + s304 -> s301 [label=8]; + s304 -> s304 [label=9,dir=both]; + } + } + +Representation as directed with unique edge identifiers +............................................................................... + +For the simplicity, the design of the edges table on the database, has the +edge's identifiers are represented with 3 digits: + +:hundreds: the source vertex +:tens: always 0, acts as a separator +:units: the target vertex + +In this image, + +* Single head arrows represent one edge (row) on the edges table. +* There are no double head arrows +* The numbers in the yellow shadow are the edge identifiers. + +.. graphviz:: + + digraph G { + + subgraph clusterA { + style=invis; + edge [arrowsize=0.5,color=blue]; + node [shape=circle;style=filled;fontsize=8;fixedsize=true;width=.4;color=deepskyblue] + v1 [label=1,pos="0,2!"]; + v2 [label=2,pos="2,2!"]; + v3 [label=3,pos="2,0!"]; + v4 [label=4,pos="0,0!"]; + + v1->{v2,v4}; + v3->{v1,v2,v4}; + {v4,v2}->v3; + } + + subgraph clusterB { + style=invis; + edge [arrowsize=0.5,color=red,fontsize=6,fontcolor=red]; + node [shape=circle;style=filled;fontsize=8;fixedsize=true;width=.4;color=yellow] + + sa [label="102",pos="1,2!"]; + sb [label="203",pos="2.2,1!"]; + sc [label="302",pos="1.8,1!"]; + sd [label="104",pos="0,1!"]; + se [label="403",pos="1,0.2!"]; + sf [label="304",pos="1,-0.2!"]; + sg [label="301",pos="1,1!"]; + } + } + +Two pair of edges share the same ending nodes and the ``reverse_cost`` column is +not used. + +* Edges :math:`{2 \rightarrow 3, 3 \rightarrow 2}` are represented with two + edges :math:`id=203` and :math:`id=302` respectively. +* Edges :math:`{3 \rightarrow 4, 4 \rightarrow 3}` are represented with two + edges :math:`id=304` and :math:`id=403` respectively. + +The graph can be created as follows: + +.. literalinclude:: lineGraph.queries + :start-after: -- q3 + :end-before: INSERT 0 7 + +Line Graph of a directed graph represented with unique edges ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. literalinclude:: lineGraph.queries + :start-after: INSERT 0 7 + :end-before: -- q4 + +* The result is a directed graph. +* For :math:`seq=7` from :math:`203 \leftrightarrow 302` represent two edges. +* For :math:`seq=8` from :math:`304 \leftrightarrow 403` represent two edges. +* For all the other values of ``seq`` represent one edge. +* The ``cost`` and ``reverse_cost`` values represent the existence of the edge. + + * When positive: the edge exists. + * When negative: the edge does not exist. + +.. graphviz:: + + digraph G { + + subgraph clusterA { + style=invis; + edge [arrowsize=0.5,color=blue]; + node [shape=circle;style=filled;fontsize=10;fixedsize=true;width=.4;color=deepskyblue] + v1 [label=1,pos="0,4!"]; + v2 [label=2,pos="4,4!"]; + v3 [label=3,pos="4,0!"]; + v4 [label=4,pos="0,0!"]; + + v1->{v2,v4}; + v3->{v1,v2,v4}; + {v4,v2}->v3; + } + + subgraph clusterB { + style=invis; + edge [arrowsize=0.5,labelfloat=true,color=red,fontsize=14,fontcolor=red]; + node [shape=circle;style=filled;fontsize=8;fixedsize=true;width=.4;color=yellow] + + sa [label="102",pos="2,4!"]; + sb [label="203",pos="4.4,2!"]; + sc [label="302",pos="3.6,2!"]; + sd [label="104",pos="0,2!"]; + se [label="403",pos="2,0.4!"]; + sf [label="304",pos="2,-0.4!"]; + sg [label="301",pos="2,2!"]; + + sa -> sb [label=1]; + sd -> se [label=2]; + sb -> sg [label=3]; + sb -> sf [label=4]; + sg -> sa [label=5]; + sg -> sd [label=6]; + sc -> sb [dir=both,label=7]; + sf -> se [dir=both,label=8]; + se -> sg [label=9]; + se -> sc [label=10]; + } + } + + See Also ------------------------------------------------------------------------------- diff --git a/doc/lineGraph/pgr_lineGraphFull.rst b/doc/lineGraph/pgr_lineGraphFull.rst index d5bcd5a5adf..aecceeb83f6 100644 --- a/doc/lineGraph/pgr_lineGraphFull.rst +++ b/doc/lineGraph/pgr_lineGraphFull.rst @@ -72,7 +72,7 @@ Signatures :Example: Full line graph of subgraph of edges :math:`\{4, 7, 8, 10\}` -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q1 :end-before: -- q2 @@ -151,7 +151,7 @@ The data This example displays how this graph transformation works to create additional edges for each possible turn in a graph. -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q0 :end-before: -- q1 @@ -165,7 +165,7 @@ edges for each possible turn in a graph. The transformation ............................................................................... -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q1 :end-before: -- q2 @@ -200,7 +200,7 @@ Store edge results The first step is to store the results of the ``pgr_lineGraphFull`` call into a table -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q2 :end-before: -- q3 @@ -209,13 +209,13 @@ Create the mapping table From the original graph's vertex information -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q3 :end-before: -- q4 Add the new vertices -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q4 :end-before: -- q5 @@ -224,44 +224,44 @@ Filling the mapping table The positive vertex identifiers are the original identifiers -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q5 :end-before: -- q6 Inspecting the vertices map -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q6 :end-before: -- q7 The self loops happen when there is no cost traveling to the ``target`` and the source has an original value. -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q7 :end-before: -- q8 Updating values from self loops -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q8 :end-before: -- q9 Inspecting the vertices table -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q9 :end-before: -- q10 Updating from inner self loops -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q10 :end-before: -- q11 Inspecting the vertices map -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q11 :end-before: -- q12 @@ -276,14 +276,14 @@ Idenifying the restriction Running a :doc:`pgr_dijkstraNear` the edge with cost 0, edge 8, is where the cost will be increased -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q12 :end-before: -- q13 The edge to be altered is ``WHERE cost = 0 AND seq != 1 AND edge != -1`` from the previus query: -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q13 :end-before: -- q14 @@ -292,7 +292,7 @@ Adding a value to the restriction Updating the cost to the edge: -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q14 :end-before: -- q15 @@ -300,7 +300,7 @@ Updating the cost to the edge: Now the route does not use edge 8 and does a U turn on a leaf vertex. -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q15 :end-before: -- q16 @@ -314,13 +314,13 @@ Using the vertex map give the leaf verices their original value. On the source column -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q16 :end-before: -- q17 On the target column -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q17 :end-before: -- q18 @@ -329,13 +329,13 @@ Removing self loops on leaf nodes The self loops of the leaf nodes are -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q18 :end-before: -- q19 Which can be removed -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q19 :end-before: -- q20 @@ -343,7 +343,7 @@ Which can be removed Routing can be done now using the original vertices id using :doc:`pgr_dijkstra` -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q20 :end-before: -- q21 @@ -356,20 +356,20 @@ Add edges from the original graph Add all the edges that are not involved in the line graph process to the new table -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q21 :end-before: -- q22 Some administrative tasks to get new identifiers for the edges -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q22 :end-before: -- q23 Add the newly calculated edges +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q23 :end-before: -- q24 @@ -380,13 +380,13 @@ When using this method for routing with soft restrictions there will be uturns :Example: Routing from :math:`6` to :math:`3` -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q24 :end-before: -- q25 :Example: Routing from :math:`5` to :math:`1` -.. literalinclude:: doc-pgr_lineGraphFull.queries +.. literalinclude:: lineGraphFull.queries :start-after: -- q25 :end-before: -- q26 diff --git a/doc/lineGraph/transformation-family.rst b/doc/lineGraph/transformation-family.rst index ca4eed41277..393329cacaf 100644 --- a/doc/lineGraph/transformation-family.rst +++ b/doc/lineGraph/transformation-family.rst @@ -9,20 +9,29 @@ -Transformation - Family of functions (Experimental) +Transformation - Family of functions =============================================================================== +.. include:: proposed.rst + :start-after: stable-begin-warning + :end-before: stable-end-warning + +.. index proposed from here + +* :doc:`pgr_lineGraph` - Transformation algorithm for generating a Line Graph. + +.. index proposed to here + .. include:: experimental.rst :start-after: begin-warn-expr :end-before: end-warn-expr -.. index from here +.. index experimental from here -* :doc:`pgr_lineGraph` - Transformation algorithm for generating a Line Graph. * :doc:`pgr_lineGraphFull` - Transformation algorithm for generating a Line Graph out of each vertex in the input graph. -.. index to here +.. index experimental to here .. toctree:: @@ -33,7 +42,7 @@ Transformation - Family of functions (Experimental) Introduction ------------------------- +------------------------------------------------------------------------------- This family of functions is used for transforming a given input graph :math:`G(V,E)` into a new graph :math:`G'(V',E')`. diff --git a/doc/max_flow/pgr_boykovKolmogorov.rst b/doc/max_flow/pgr_boykovKolmogorov.rst index 969f496ffb4..99900409abc 100644 --- a/doc/max_flow/pgr_boykovKolmogorov.rst +++ b/doc/max_flow/pgr_boykovKolmogorov.rst @@ -85,7 +85,7 @@ One to One :Example: From vertex :math:`11` to vertex :math:`12` -.. literalinclude:: doc-pgr_boykovKolmogorov.queries +.. literalinclude:: boykovKolmogorov.queries :start-after: -- q1 :end-before: -- q2 @@ -105,7 +105,7 @@ One to Many :Example: From vertex :math:`11` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_boykovKolmogorov.queries +.. literalinclude:: boykovKolmogorov.queries :start-after: -- q2 :end-before: -- q3 @@ -125,7 +125,7 @@ Many to One :Example: From vertices :math:`\{11, 3, 17\}` to vertex :math:`12` -.. literalinclude:: doc-pgr_boykovKolmogorov.queries +.. literalinclude:: boykovKolmogorov.queries :start-after: -- q3 :end-before: -- q4 @@ -145,7 +145,7 @@ Many to Many :Example: From vertices :math:`\{11, 3, 17\}` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_boykovKolmogorov.queries +.. literalinclude:: boykovKolmogorov.queries :start-after: -- q4 :end-before: -- q5 @@ -168,13 +168,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_boykovKolmogorov.queries +.. literalinclude:: boykovKolmogorov.queries :start-after: -- q5 :end-before: -- q51 The query: -.. literalinclude:: doc-pgr_boykovKolmogorov.queries +.. literalinclude:: boykovKolmogorov.queries :start-after: -- q51 :end-before: -- q6 @@ -214,7 +214,7 @@ Additional Examples :Example: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_boykovKolmogorov.queries +.. literalinclude:: boykovKolmogorov.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/max_flow/pgr_edgeDisjointPaths.rst b/doc/max_flow/pgr_edgeDisjointPaths.rst index 0c9f46229d3..12e7ea13648 100644 --- a/doc/max_flow/pgr_edgeDisjointPaths.rst +++ b/doc/max_flow/pgr_edgeDisjointPaths.rst @@ -88,7 +88,7 @@ One to One :Example: From vertex :math:`11` to vertex :math:`12` -.. literalinclude:: doc-pgr_edgeDisjointPaths.queries +.. literalinclude:: edgeDisjointPaths.queries :start-after: -- q1 :end-before: -- q2 @@ -109,7 +109,7 @@ One to Many :Example: From vertex :math:`11` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_edgeDisjointPaths.queries +.. literalinclude:: edgeDisjointPaths.queries :start-after: -- q2 :end-before: -- q3 @@ -129,7 +129,7 @@ Many to One :Example: From vertices :math:`\{11, 3, 17\}` to vertex :math:`12` -.. literalinclude:: doc-pgr_edgeDisjointPaths.queries +.. literalinclude:: edgeDisjointPaths.queries :start-after: -- q3 :end-before: -- q4 @@ -149,7 +149,7 @@ Many to Many :Example: From vertices :math:`\{11, 3, 17\}` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_edgeDisjointPaths.queries +.. literalinclude:: edgeDisjointPaths.queries :start-after: -- q4 :end-before: -- q5 @@ -173,13 +173,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_edgeDisjointPaths.queries +.. literalinclude:: edgeDisjointPaths.queries :start-after: -- q5 :end-before: -- q51 The query: -.. literalinclude:: doc-pgr_edgeDisjointPaths.queries +.. literalinclude:: edgeDisjointPaths.queries :start-after: -- q51 :end-before: -- q6 @@ -226,7 +226,7 @@ Additional Examples :Example: Manually assigned vertex combinations on an undirected graph. -.. literalinclude:: doc-pgr_edgeDisjointPaths.queries +.. literalinclude:: edgeDisjointPaths.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/max_flow/pgr_edmondsKarp.rst b/doc/max_flow/pgr_edmondsKarp.rst index 0f5016b1113..d6eb81f362d 100644 --- a/doc/max_flow/pgr_edmondsKarp.rst +++ b/doc/max_flow/pgr_edmondsKarp.rst @@ -85,7 +85,7 @@ One to One :Example: From vertex :math:`11` to vertex :math:`12` -.. literalinclude:: doc-pgr_edmondsKarp.queries +.. literalinclude:: edmondsKarp.queries :start-after: -- q1 :end-before: -- q2 @@ -105,7 +105,7 @@ One to Many :Example: From vertex :math:`11` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_edmondsKarp.queries +.. literalinclude:: edmondsKarp.queries :start-after: -- q2 :end-before: -- q3 @@ -125,7 +125,7 @@ Many to One :Example: From vertices :math:`\{11, 3, 17\}` to vertex :math:`12` -.. literalinclude:: doc-pgr_edmondsKarp.queries +.. literalinclude:: edmondsKarp.queries :start-after: -- q3 :end-before: -- q4 @@ -145,7 +145,7 @@ Many to Many :Example: From vertices :math:`\{11, 3, 17\}` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_edmondsKarp.queries +.. literalinclude:: edmondsKarp.queries :start-after: -- q4 :end-before: -- q5 @@ -168,13 +168,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_edmondsKarp.queries +.. literalinclude:: edmondsKarp.queries :start-after: -- q5 :end-before: -- q51 The query: -.. literalinclude:: doc-pgr_edmondsKarp.queries +.. literalinclude:: edmondsKarp.queries :start-after: -- q51 :end-before: -- q6 @@ -214,7 +214,7 @@ Additional Examples :Example: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_edmondsKarp.queries +.. literalinclude:: edmondsKarp.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/max_flow/pgr_maxCardinalityMatch.rst b/doc/max_flow/pgr_maxCardinalityMatch.rst index f80f641e29c..b27682342f6 100644 --- a/doc/max_flow/pgr_maxCardinalityMatch.rst +++ b/doc/max_flow/pgr_maxCardinalityMatch.rst @@ -89,7 +89,7 @@ Signatures :Example: Using all edges. -.. literalinclude:: doc-pgr_maxCardinalityMatch.queries +.. literalinclude:: maxCardinalityMatch.queries :start-after: -- q2 :end-before: -- q3 diff --git a/doc/max_flow/pgr_maxFlow.rst b/doc/max_flow/pgr_maxFlow.rst index bcdb1cd2f41..2428ff99fb8 100644 --- a/doc/max_flow/pgr_maxFlow.rst +++ b/doc/max_flow/pgr_maxFlow.rst @@ -85,7 +85,7 @@ One to One :Example: From vertex :math:`11` to vertex :math:`12` -.. literalinclude:: doc-pgr_maxFlow.queries +.. literalinclude:: maxFlow.queries :start-after: -- q1 :end-before: -- q2 @@ -104,7 +104,7 @@ One to Many :Example: From vertex :math:`11` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_maxFlow.queries +.. literalinclude:: maxFlow.queries :start-after: -- q2 :end-before: -- q3 @@ -123,7 +123,7 @@ Many to One :Example: From vertices :math:`\{11, 3, 17\}` to vertex :math:`12` -.. literalinclude:: doc-pgr_maxFlow.queries +.. literalinclude:: maxFlow.queries :start-after: -- q3 :end-before: -- q4 @@ -142,7 +142,7 @@ Many to Many :Example: From vertices :math:`\{11, 3, 17\}` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_maxFlow.queries +.. literalinclude:: maxFlow.queries :start-after: -- q4 :end-before: -- q5 @@ -164,13 +164,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_maxFlow.queries +.. literalinclude:: maxFlow.queries :start-after: -- q5 :end-before: -- q51 The query: -.. literalinclude:: doc-pgr_maxFlow.queries +.. literalinclude:: maxFlow.queries :start-after: -- q51 :end-before: -- q6 @@ -212,7 +212,7 @@ Additional Examples :Example: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_maxFlow.queries +.. literalinclude:: maxFlow.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/max_flow/pgr_maxFlowMinCost.rst b/doc/max_flow/pgr_maxFlowMinCost.rst index 1a3f856a4ab..031d016ac0f 100644 --- a/doc/max_flow/pgr_maxFlowMinCost.rst +++ b/doc/max_flow/pgr_maxFlowMinCost.rst @@ -90,7 +90,7 @@ One to One :Example: From vertex :math:`11` to vertex :math:`12` -.. literalinclude:: doc-pgr_maxFlowMinCost.queries +.. literalinclude:: maxFlowMinCost.queries :start-after: -- q1 :end-before: -- q2 @@ -110,7 +110,7 @@ One to Many :Example: From vertex :math:`11` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_maxFlowMinCost.queries +.. literalinclude:: maxFlowMinCost.queries :start-after: -- q2 :end-before: -- q3 @@ -130,7 +130,7 @@ Many to One :Example: From vertices :math:`\{11, 3, 17\}` to vertex :math:`12` -.. literalinclude:: doc-pgr_maxFlowMinCost.queries +.. literalinclude:: maxFlowMinCost.queries :start-after: -- q3 :end-before: -- q4 @@ -150,7 +150,7 @@ Many to Many :Example: From vertices :math:`\{11, 3, 17\}` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_maxFlowMinCost.queries +.. literalinclude:: maxFlowMinCost.queries :start-after: -- q4 :end-before: -- q5 @@ -173,13 +173,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_maxFlowMinCost.queries +.. literalinclude:: maxFlowMinCost.queries :start-after: -- q5 :end-before: -- q51 The query: -.. literalinclude:: doc-pgr_maxFlowMinCost.queries +.. literalinclude:: maxFlowMinCost.queries :start-after: -- q51 :end-before: -- q6 @@ -219,7 +219,7 @@ Additional Examples :Example: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_maxFlowMinCost.queries +.. literalinclude:: maxFlowMinCost.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/max_flow/pgr_maxFlowMinCost_Cost.rst b/doc/max_flow/pgr_maxFlowMinCost_Cost.rst index 73622df2e05..7d39f4d45d7 100644 --- a/doc/max_flow/pgr_maxFlowMinCost_Cost.rst +++ b/doc/max_flow/pgr_maxFlowMinCost_Cost.rst @@ -93,7 +93,7 @@ One to One :Example: From vertex :math:`11` to vertex :math:`12` -.. literalinclude:: doc-pgr_maxFlowMinCost_Cost.queries +.. literalinclude:: maxFlowMinCost_Cost.queries :start-after: -- q1 :end-before: -- q2 @@ -112,7 +112,7 @@ One to Many :Example: From vertex :math:`11` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_maxFlowMinCost_Cost.queries +.. literalinclude:: maxFlowMinCost_Cost.queries :start-after: -- q3 :end-before: -- q4 @@ -131,7 +131,7 @@ Many to One :Example: From vertices :math:`\{11, 3, 17\}` to vertex :math:`12` -.. literalinclude:: doc-pgr_maxFlowMinCost_Cost.queries +.. literalinclude:: maxFlowMinCost_Cost.queries :start-after: -- q2 :end-before: -- q3 @@ -151,7 +151,7 @@ Many to Many :Example: From vertices :math:`\{11, 3, 17\}` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_maxFlowMinCost_Cost.queries +.. literalinclude:: maxFlowMinCost_Cost.queries :start-after: -- q4 :end-before: -- q5 @@ -173,13 +173,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_maxFlowMinCost_Cost.queries +.. literalinclude:: maxFlowMinCost_Cost.queries :start-after: -- q5 :end-before: -- q51 The query: -.. literalinclude:: doc-pgr_maxFlowMinCost_Cost.queries +.. literalinclude:: maxFlowMinCost_Cost.queries :start-after: -- q51 :end-before: -- q6 @@ -221,7 +221,7 @@ Additional Examples :Example: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_maxFlowMinCost_Cost.queries +.. literalinclude:: maxFlowMinCost_Cost.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/max_flow/pgr_pushRelabel.rst b/doc/max_flow/pgr_pushRelabel.rst index 550885366c2..b1a8abc239a 100644 --- a/doc/max_flow/pgr_pushRelabel.rst +++ b/doc/max_flow/pgr_pushRelabel.rst @@ -85,7 +85,7 @@ One to One :Example: From vertex :math:`11` to vertex :math:`12` -.. literalinclude:: doc-pgr_pushRelabel.queries +.. literalinclude:: pushRelabel.queries :start-after: -- q1 :end-before: -- q2 @@ -105,7 +105,7 @@ One to Many :Example: From vertex :math:`11` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_pushRelabel.queries +.. literalinclude:: pushRelabel.queries :start-after: -- q2 :end-before: -- q3 @@ -125,7 +125,7 @@ Many to One :Example: From vertices :math:`\{11, 3, 17\}` to vertex :math:`12` -.. literalinclude:: doc-pgr_pushRelabel.queries +.. literalinclude:: pushRelabel.queries :start-after: -- q3 :end-before: -- q4 @@ -145,7 +145,7 @@ Many to Many :Example: From vertices :math:`\{11, 3, 17\}` to vertices :math:`\{5, 10, 12\}` -.. literalinclude:: doc-pgr_pushRelabel.queries +.. literalinclude:: pushRelabel.queries :start-after: -- q4 :end-before: -- q5 @@ -168,13 +168,13 @@ Combinations The combinations table: -.. literalinclude:: doc-pgr_pushRelabel.queries +.. literalinclude:: pushRelabel.queries :start-after: -- q5 :end-before: -- q51 The query: -.. literalinclude:: doc-pgr_pushRelabel.queries +.. literalinclude:: pushRelabel.queries :start-after: -- q51 :end-before: -- q6 @@ -214,7 +214,7 @@ Additional Examples :Example: Manually assigned vertex combinations. -.. literalinclude:: doc-pgr_pushRelabel.queries +.. literalinclude:: pushRelabel.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/metrics/CMakeLists.txt b/doc/metrics/CMakeLists.txt new file mode 100644 index 00000000000..5adba5a42a6 --- /dev/null +++ b/doc/metrics/CMakeLists.txt @@ -0,0 +1,12 @@ + +SET(LOCAL_FILES + metrics-family.rst + pgr_betweennessCentrality.rst + ) + +foreach (f ${LOCAL_FILES}) + configure_file(${f} "${PGR_DOCUMENTATION_SOURCE_DIR}/${f}") + list(APPEND LOCAL_DOC_FILES ${PGR_DOCUMENTATION_SOURCE_DIR}/${f}) +endforeach() + +set(PROJECT_DOC_FILES ${PROJECT_DOC_FILES} ${LOCAL_DOC_FILES} PARENT_SCOPE) diff --git a/doc/metrics/metrics-family.rst b/doc/metrics/metrics-family.rst new file mode 100644 index 00000000000..66cacabdc67 --- /dev/null +++ b/doc/metrics/metrics-family.rst @@ -0,0 +1,41 @@ +.. + **************************************************************************** + 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/ + **************************************************************************** + +| + + + +Metrics - Family of functions +=============================================================================== + +.. rubric:: Experimental + +.. include:: experimental.rst + :start-after: begin-warn-expr + :end-before: end-warn-expr + +.. index experimental from here + +* :doc:`pgr_betweennessCentrality` - Calculates relative betweenness centrality using Brandes Algorithm + +.. index experimental to here + + +.. toctree:: + :hidden: + + pgr_betweennessCentrality + +See Also +------------------------------------------------------------------------------- + +.. rubric:: Indices and tables + +* :ref:`genindex` +* :ref:`search` diff --git a/doc/metrics/pgr_betweennessCentrality.rst b/doc/metrics/pgr_betweennessCentrality.rst new file mode 100644 index 00000000000..5a92199a7da --- /dev/null +++ b/doc/metrics/pgr_betweennessCentrality.rst @@ -0,0 +1,148 @@ +.. + **************************************************************************** + 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/ + **************************************************************************** + +| + + +``pgr_betweennessCentrality`` +=============================================================================== + +``pgr_betweennessCentrality`` - Calculates the relative betweeness centrality +using Brandes Algorithm + +.. figure:: images/boost-inside.jpeg + :target: https://www.boost.org/doc/libs/1_84_0/libs/graph/doc/betweenness_centrality.html + + Boost Graph Inside + +.. rubric:: Availability + +* Version 3.7.0 + + * New **experimental** function: + + * ``pgr_betweennessCentrality`` + +Description +------------------------------------------------------------------------------- + +The Brandes Algorithm takes advantage of the sparse graphs for evaluating the +betweenness centrality score of all vertices. + + +Betweenness centrality measures the extent to which a vertex lies on the +shortest paths between all other pairs of vertices. Vertices with a high +betweenness centrality score may have considerable influence in a network by the +virtue of their control over the shortest paths passing between them. + +The removal of these vertices will affect the network by disrupting the +it, as most of the shortest paths between vertices pass through them. + +This implementation work for both directed and undirected graphs. + +- Running time: :math:`\Theta(VE)` +- Running space: :math:`\Theta(VE)` +- Throws when there are no edges in the graph + +Signatures +------------------------------------------------------------------------------- + +.. rubric:: Summary + +.. admonition:: \ \ + :class: signatures + + pgr_betweennessCentrality(`Edges SQL`_, [``directed``]) + + | Returns set of ``(vid, centrality)`` + +:Example: For a directed graph with edges :math:`\{1, 2, 3, 4\}`. + +.. literalinclude:: betweennessCentrality.queries + :start-after: -- q1 + :end-before: -- q2 + +.. rubric:: Explanation + +* The betweenness centrality are between parenthesis. +* The leaf vertices have betweenness centrality :math:`0`. +* Betweenness centrality of vertex :math:`6` is higher than of vertex :math:`10`. + + * Removing vertex :math:`6` will create three graph components. + * Removing vertex :math:`10` will create two graph components. + +.. graphviz:: + + digraph G { + 5, 7, 15 [shape=circle;style=filled;width=.5;color=deepskyblue;fontsize=8;fixedsize=true;]; + 6, 10 [shape=circle;style=filled;width=.5;color=green;fontsize=8;fixedsize=true;]; + 5 [pos="0,0!";label="5 (0)"]; + 6 [pos="0,1!"label="6 (0.5)"]; + 7 [pos="0,2!"label="7 (0)"]; + 10 [pos="1,1!"label="10 (0.25)"]; + 15 [pos="2,1!"label="15 (0)"]; + 5 -> 6 [dir=both;label="1 "]; + 6->7 [dir=both;label="4 "]; + 10->6 [label="3"]; + 15->10 [label="4"]; + } + +Parameters +------------------------------------------------------------------------------- + +.. include:: allpairs-family.rst + :start-after: edges_start + :end-before: edges_end + +Optional parameters +............................................................................... + +.. include:: dijkstra-family.rst + :start-after: dijkstra_optionals_start + :end-before: dijkstra_optionals_end + +Inner Queries +------------------------------------------------------------------------------- + +Edges SQL +............................................................................... + +.. include:: pgRouting-concepts.rst + :start-after: no_id_edges_sql_start + :end-before: no_id_edges_sql_end + +Result columns +------------------------------------------------------------------------------- + +.. list-table:: + :width: 81 + :widths: auto + :header-rows: 1 + + * - Column + - Type + - Description + * - ``vid`` + - ``BIGINT`` + - Identifier of the vertex. + * - ``centrality`` + - ``FLOAT`` + - Relative betweenness centrality score of the vertex (will be in range [0,1]) + +See Also +------------------------------------------------------------------------------- + +* Boost's `betweenness_centrality + `_ +* Queries use the :doc:`sampledata` network. + +.. rubric:: Indices and tables + +* :ref:`genindex` +* :ref:`search` diff --git a/doc/mincut/pgr_stoerWagner.rst b/doc/mincut/pgr_stoerWagner.rst index 644543aae3b..a08d0630f30 100644 --- a/doc/mincut/pgr_stoerWagner.rst +++ b/doc/mincut/pgr_stoerWagner.rst @@ -82,7 +82,7 @@ Signatures :Example: min cut of the main subgraph -.. literalinclude:: doc-stoerWagner.queries +.. literalinclude:: stoerWagner.queries :start-after: -- q1 :end-before: -- q2 @@ -122,13 +122,13 @@ Additional Example: :Example: min cut of an edge -.. literalinclude:: doc-stoerWagner.queries +.. literalinclude:: stoerWagner.queries :start-after: -- q2 :end-before: -- q3 :Example: Using :doc:`pgr_connectedComponents` -.. literalinclude:: doc-stoerWagner.queries +.. literalinclude:: stoerWagner.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/pickDeliver/pgr_pickDeliver.rst b/doc/pickDeliver/pgr_pickDeliver.rst index ba339e5ce73..77dc4abb540 100644 --- a/doc/pickDeliver/pgr_pickDeliver.rst +++ b/doc/pickDeliver/pgr_pickDeliver.rst @@ -88,19 +88,19 @@ Signature Given the vehicles: -.. literalinclude:: doc-pickDeliver.queries +.. literalinclude:: pickDeliver.queries :start-after: -- q1 :end-before: -- q2 and the orders: -.. literalinclude:: doc-pickDeliver.queries +.. literalinclude:: pickDeliver.queries :start-after: -- q2 :end-before: -- q3 The query: -.. literalinclude:: doc-pickDeliver.queries +.. literalinclude:: pickDeliver.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/pickDeliver/pgr_pickDeliverEuclidean.rst b/doc/pickDeliver/pgr_pickDeliverEuclidean.rst index a049c5ba8f6..4f0d491dfdc 100644 --- a/doc/pickDeliver/pgr_pickDeliverEuclidean.rst +++ b/doc/pickDeliver/pgr_pickDeliverEuclidean.rst @@ -90,19 +90,19 @@ Signature Given the vehicles: -.. literalinclude:: ./doc-pickDeliverEuclidean.queries +.. literalinclude:: ./pickDeliverEuclidean.queries :start-after: -- q1 :end-before: -- q2 and the orders: -.. literalinclude:: ./doc-pickDeliverEuclidean.queries +.. literalinclude:: ./pickDeliverEuclidean.queries :start-after: -- q2 :end-before: -- q3 The query: -.. literalinclude:: ./doc-pickDeliverEuclidean.queries +.. literalinclude:: ./pickDeliverEuclidean.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/planar/pgr_isPlanar.rst b/doc/planar/pgr_isPlanar.rst index 9b735d5593b..25485a2955a 100644 --- a/doc/planar/pgr_isPlanar.rst +++ b/doc/planar/pgr_isPlanar.rst @@ -64,7 +64,7 @@ Signatures | RETURNS ``BOOLEAN`` -.. literalinclude:: doc-pgr_isPlanar.queries +.. literalinclude:: isPlanar.queries :start-after: -- q1 :end-before: -- q2 @@ -103,7 +103,7 @@ Additional Examples The following edges will make the subgraph with vertices {10, 15, 11, 16, 13} a :math:`K_1` graph. -.. literalinclude:: doc-pgr_isPlanar.queries +.. literalinclude:: isPlanar.queries :start-after: -- q2 :end-before: -- q3 @@ -115,7 +115,7 @@ represent :math:`K_5` subgraph. .. image:: images/nonPlanar.png :scale: 50% -.. literalinclude:: doc-pgr_isPlanar.queries +.. literalinclude:: isPlanar.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/spanningTree/pgr_kruskal.rst b/doc/spanningTree/pgr_kruskal.rst index 7ec6d26825b..35f48b4a3d1 100644 --- a/doc/spanningTree/pgr_kruskal.rst +++ b/doc/spanningTree/pgr_kruskal.rst @@ -59,7 +59,7 @@ Signatures :Example: Minimum spanning forest -.. literalinclude:: doc-pgr_kruskal.queries +.. literalinclude:: kruskal.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/spanningTree/pgr_kruskalBFS.rst b/doc/spanningTree/pgr_kruskalBFS.rst index fc9206e3eb6..5fca24275eb 100644 --- a/doc/spanningTree/pgr_kruskalBFS.rst +++ b/doc/spanningTree/pgr_kruskalBFS.rst @@ -23,10 +23,15 @@ First Search ordering. .. rubric:: Availability -* Version 3.0.0 +:Version 3.7.0: - * New **Official** function +* Standarizing output columns to |result-spantree| + + * Added ``pred`` result columns. +:Version 3.0.0: + + * New **Official** function Description ------------------------------------------------------------------------------- @@ -52,7 +57,7 @@ Signatures | pgr_kruskalBFS(`Edges SQL`_, **root vid**, [``max_depth``]) | pgr_kruskalBFS(`Edges SQL`_, **root vids**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| .. index:: single: kruskalBFS(Single vertex) @@ -65,11 +70,11 @@ Single vertex | pgr_kruskalBFS(`Edges SQL`_, **root vid**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree having as root vertex :math:`6` -.. literalinclude:: doc-pgr_kruskalBFS.queries +.. literalinclude:: kruskalBFS.queries :start-after: -- q1 :end-before: -- q2 @@ -84,21 +89,21 @@ Multiple vertices | pgr_kruskalBFS(`Edges SQL`_, **root vids**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree starting on vertices :math:`\{9, 6\}` with :math:`depth \leq 3` -.. literalinclude:: doc-pgr_kruskalBFS.queries +.. literalinclude:: kruskalBFS.queries :start-after: -- q2 :end-before: -- q3 Parameters ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-params_start - :end-before: mst-bfs-dfs-params_end +.. include:: drivingDistance-category.rst + :start-after: spantree-params_start + :end-before: spantree-params_end BFS optional parameters ............................................................................... @@ -111,7 +116,7 @@ Inner Queries ------------------------------------------------------------------------------- Edges SQL -............................................................................... +.............................................................................. .. include:: pgRouting-concepts.rst :start-after: basic_edges_sql_start @@ -120,9 +125,9 @@ Edges SQL Result columns ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-dd-result-columns-start - :end-before: mst-bfs-dfs-dd-result-columns-end +.. include:: drivingDistance-category.rst + :start-after: spantree-result-columns-start + :end-before: spantree-result-columns-end See Also ------------------------------------------------------------------------------- diff --git a/doc/spanningTree/pgr_kruskalDD.rst b/doc/spanningTree/pgr_kruskalDD.rst index 111f1f3e084..400206a9766 100644 --- a/doc/spanningTree/pgr_kruskalDD.rst +++ b/doc/spanningTree/pgr_kruskalDD.rst @@ -22,7 +22,13 @@ .. rubric:: Availability -* Version 3.0.0 +:Version 3.7.0: + +* Standarizing output columns to |result-spantree| + + * Added ``pred`` result columns. + +:Version 3.0.0: * New **Official** function @@ -55,7 +61,7 @@ Signatures | pgr_kruskalDD(`Edges SQL`_, **root vid**, **distance**) | pgr_kruskalDD(`Edges SQL`_, **root vids**, **distance**) - | Returns set of |result-bfs| + | Returns set of |result-spantree| .. index:: single: kruskalDD(Single vertex) @@ -68,12 +74,12 @@ Single vertex | pgr_kruskalDD(`Edges SQL`_, **root vid**, **distance**) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree starting on vertex :math:`6` with :math:`distance \leq 3.5` -.. literalinclude:: doc-pgr_kruskalDD.queries +.. literalinclude:: kruskalDD.queries :start-after: -- q1 :end-before: -- q2 @@ -88,12 +94,12 @@ Multiple vertices | pgr_kruskalDD(`Edges SQL`_, **root vids**, **distance**) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree starting on vertices :math:`\{9, 6\}` with :math:`distance \leq 3.5` -.. literalinclude:: doc-pgr_kruskalDD.queries +.. literalinclude:: kruskalDD.queries :start-after: -- q2 :end-before: -- q3 @@ -101,8 +107,8 @@ Parameters ------------------------------------------------------------------------------- .. include:: drivingDistance-category.rst - :start-after: mst-dd-params_start - :end-before: mst-dd-params_end + :start-after: spantree-params_start + :end-before: spantree-params_end Inner Queries ------------------------------------------------------------------------------- @@ -117,9 +123,9 @@ Edges SQL Result columns ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-dd-result-columns-start - :end-before: mst-bfs-dfs-dd-result-columns-end +.. include:: drivingDistance-category.rst + :start-after: spantree-result-columns-start + :end-before: spantree-result-columns-end See Also ------------------------------------------------------------------------------- diff --git a/doc/spanningTree/pgr_kruskalDFS.rst b/doc/spanningTree/pgr_kruskalDFS.rst index 1093d1f8a81..616bb96e7eb 100644 --- a/doc/spanningTree/pgr_kruskalDFS.rst +++ b/doc/spanningTree/pgr_kruskalDFS.rst @@ -23,7 +23,13 @@ First Search ordering. .. rubric:: Availability -* Version 3.0.0 +:Version 3.7.0: + +* Standarizing output columns to |result-spantree| + + * Added ``pred`` result columns. + +:Version 3.0.0: * New **Official** function @@ -52,7 +58,7 @@ Signatures | pgr_kruskalDFS(`Edges SQL`_, **root vid**, [``max_depth``]) | pgr_kruskalDFS(`Edges SQL`_, **root vids**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| .. index:: single: kruskalDFS(Single vertex) @@ -65,11 +71,11 @@ Single vertex | pgr_kruskalDFS(`Edges SQL`_, **root vid**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree having as root vertex :math:`6` -.. literalinclude:: doc-pgr_kruskalDFS.queries +.. literalinclude:: kruskalDFS.queries :start-after: -- q1 :end-before: -- q2 @@ -84,21 +90,21 @@ Multiple vertices | pgr_kruskalDFS(`Edges SQL`_, **root vids**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree starting on vertices :math:`\{9, 6\}` with :math:`depth \leq 3` -.. literalinclude:: doc-pgr_kruskalDFS.queries +.. literalinclude:: kruskalDFS.queries :start-after: -- q2 :end-before: -- q3 Parameters ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-params_start - :end-before: mst-bfs-dfs-params_end +.. include:: drivingDistance-category.rst + :start-after: spantree-params_start + :end-before: spantree-params_end DFS optional parameters ............................................................................... @@ -111,7 +117,7 @@ Inner Queries ------------------------------------------------------------------------------- Edges SQL -............................................................................... +.............................................................................. .. include:: pgRouting-concepts.rst :start-after: basic_edges_sql_start @@ -120,9 +126,9 @@ Edges SQL Result columns ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-dd-result-columns-start - :end-before: mst-bfs-dfs-dd-result-columns-end +.. include:: drivingDistance-category.rst + :start-after: spantree-result-columns-start + :end-before: spantree-result-columns-end See Also ------------------------------------------------------------------------------- diff --git a/doc/spanningTree/pgr_prim.rst b/doc/spanningTree/pgr_prim.rst index 9c124330cbe..88f567cfef8 100644 --- a/doc/spanningTree/pgr_prim.rst +++ b/doc/spanningTree/pgr_prim.rst @@ -60,7 +60,7 @@ Signatures :Example: Minimum spanning forest of a subgraph -.. literalinclude:: doc-pgr_prim.queries +.. literalinclude:: prim.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/spanningTree/pgr_primBFS.rst b/doc/spanningTree/pgr_primBFS.rst index 0d049f45c87..b5d799bcc17 100644 --- a/doc/spanningTree/pgr_primBFS.rst +++ b/doc/spanningTree/pgr_primBFS.rst @@ -23,10 +23,15 @@ Search ordering. .. rubric:: Availability -* Version 3.0.0 +:Version 3.7.0: - * New **Official** function +* Standarizing output columns to |result-spantree| + + * Added ``pred`` result columns. +:Version 3.0.0: + + * New **Official** function Description ------------------------------------------------------------------------------- @@ -52,7 +57,7 @@ Signatures | pgr_primBFS(`Edges SQL`_, **root vid**, [``max_depth``]) | pgr_primBFS(`Edges SQL`_, **root vids**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| .. index:: single: primBFS(Single vertex) @@ -65,11 +70,11 @@ Single vertex | pgr_primBFS(`Edges SQL`_, **root vid**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree having as root vertex :math:`6` -.. literalinclude:: doc-pgr_primBFS.queries +.. literalinclude:: primBFS.queries :start-after: -- q1 :end-before: -- q2 @@ -84,21 +89,21 @@ Multiple vertices | pgr_primBFS(`Edges SQL`_, **root vids**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree starting on vertices :math:`\{9, 6\}` with :math:`depth \leq 3` -.. literalinclude:: doc-pgr_primBFS.queries +.. literalinclude:: primBFS.queries :start-after: -- q2 :end-before: -- q3 Parameters ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-params_start - :end-before: mst-bfs-dfs-params_end +.. include:: drivingDistance-category.rst + :start-after: spantree-params_start + :end-before: spantree-params_end BFS optional parameters ............................................................................... @@ -111,18 +116,18 @@ Inner Queries ------------------------------------------------------------------------------- Edges SQL -............................................................................... +.............................................................................. .. include:: pgRouting-concepts.rst - :start-after: basic_edges_sql_start - :end-before: basic_edges_sql_end + :start-after: basic_edges_sql_start + :end-before: basic_edges_sql_end Result columns ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-dd-result-columns-start - :end-before: mst-bfs-dfs-dd-result-columns-end +.. include:: drivingDistance-category.rst + :start-after: spantree-result-columns-start + :end-before: spantree-result-columns-end See Also ------------------------------------------------------------------------------- diff --git a/doc/spanningTree/pgr_primDD.rst b/doc/spanningTree/pgr_primDD.rst index 598197233ea..9e96b287270 100644 --- a/doc/spanningTree/pgr_primDD.rst +++ b/doc/spanningTree/pgr_primDD.rst @@ -22,7 +22,13 @@ .. rubric:: Availability -* Version 3.0.0 +.. rubric:: Version 3.7.0 + +* Standarizing output columns to |result-spantree| + + * Added ``pred`` result columns. + +.. rubric:: Version 3.0.0 * New **Official** function @@ -55,7 +61,7 @@ Signatures | pgr_primDD(`Edges SQL`_, **root vid**, **distance**) | pgr_primDD(`Edges SQL`_, **root vids**, **distance**) - | Returns set of |result-bfs| + | Returns set of |result-spantree| .. index:: single: primDD(Single vertex) @@ -68,12 +74,12 @@ Single vertex | pgr_primDD(`Edges SQL`_, **root vid**, **distance**) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree starting on vertex :math:`6` with :math:`distance \leq 3.5` -.. literalinclude:: doc-pgr_primDD.queries +.. literalinclude:: primDD.queries :start-after: -- q1 :end-before: -- q2 @@ -88,12 +94,12 @@ Multiple vertices | pgr_primDD(`Edges SQL`_, **root vids**, **distance**) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree starting on vertices :math:`\{9, 6\}` with :math:`distance \leq 3.5` -.. literalinclude:: doc-pgr_primDD.queries +.. literalinclude:: primDD.queries :start-after: -- q2 :end-before: -- q3 @@ -101,8 +107,8 @@ Parameters ------------------------------------------------------------------------------- .. include:: drivingDistance-category.rst - :start-after: mst-dd-params_start - :end-before: mst-dd-params_end + :start-after: spantree-params_start + :end-before: spantree-params_end Inner Queries ------------------------------------------------------------------------------- @@ -117,9 +123,9 @@ Edges SQL Result columns ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-dd-result-columns-start - :end-before: mst-bfs-dfs-dd-result-columns-end +.. include:: drivingDistance-category.rst + :start-after: spantree-result-columns-start + :end-before: spantree-result-columns-end See Also ------------------------------------------------------------------------------- @@ -136,4 +142,3 @@ See Also * :ref:`genindex` * :ref:`search` - diff --git a/doc/spanningTree/pgr_primDFS.rst b/doc/spanningTree/pgr_primDFS.rst index c2620719f6e..c2822fb88f0 100644 --- a/doc/spanningTree/pgr_primDFS.rst +++ b/doc/spanningTree/pgr_primDFS.rst @@ -23,10 +23,15 @@ Search ordering. .. rubric:: Availability -* Version 3.0.0 +:Version 3.7.0: - * New **Official** function +* Standarizing output columns to |result-spantree| + + * Added ``pred`` result columns. +:Version 3.0.0: + + * New **Official** function Description ------------------------------------------------------------------------------- @@ -52,7 +57,7 @@ Signatures | pgr_primDFS(`Edges SQL`_, **root vid**, [``max_depth``]) | pgr_primDFS(`Edges SQL`_, **root vids**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| .. index:: single: primDFS(Single vertex) @@ -65,11 +70,11 @@ Single vertex | pgr_primDFS(`Edges SQL`_, **root vid**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree having as root vertex :math:`6` -.. literalinclude:: doc-pgr_primDFS.queries +.. literalinclude:: primDFS.queries :start-after: -- q1 :end-before: -- q2 @@ -84,21 +89,21 @@ Multiple vertices | pgr_primDFS(`Edges SQL`_, **root vids**, [``max_depth``]) - | Returns set of |result-bfs| + | Returns set of |result-spantree| :Example: The Minimum Spanning Tree starting on vertices :math:`\{9, 6\}` with :math:`depth \leq 3` -.. literalinclude:: doc-pgr_primDFS.queries +.. literalinclude:: primDFS.queries :start-after: -- q2 :end-before: -- q3 Parameters ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-params_start - :end-before: mst-bfs-dfs-params_end +.. include:: drivingDistance-category.rst + :start-after: spantree-params_start + :end-before: spantree-params_end DFS optional parameters ............................................................................... @@ -111,7 +116,7 @@ Inner Queries ------------------------------------------------------------------------------- Edges SQL -............................................................................... +.............................................................................. .. include:: pgRouting-concepts.rst :start-after: basic_edges_sql_start @@ -120,9 +125,9 @@ Edges SQL Result columns ------------------------------------------------------------------------------- -.. include:: BFS-category.rst - :start-after: mst-bfs-dfs-dd-result-columns-start - :end-before: mst-bfs-dfs-dd-result-columns-end +.. include:: drivingDistance-category.rst + :start-after: spantree-result-columns-start + :end-before: spantree-result-columns-end See Also ------------------------------------------------------------------------------- diff --git a/doc/src/experimental.rst b/doc/src/experimental.rst index 9a3aace837c..6f054c9324f 100644 --- a/doc/src/experimental.rst +++ b/doc/src/experimental.rst @@ -62,8 +62,8 @@ Experimental Functions :doc:`transformation-family` .. include:: transformation-family.rst - :start-after: index from here - :end-before: index to here + :start-after: index experimental from here + :end-before: index experimental to here :doc:`traversal-family` @@ -83,6 +83,12 @@ Experimental Functions :start-after: index from here :end-before: index to here +:doc:`metrics-family` + +.. include:: metrics-family.rst + :start-after: index experimental from here + :end-before: index experimental to here + :doc:`TRSP-family` .. include:: TRSP-family.rst @@ -96,6 +102,7 @@ Experimental Functions transformation-family components-family ordering-family + metrics-family .. rubric:: categories diff --git a/doc/src/index.rst b/doc/src/index.rst index 9703f31e47e..32579ef430c 100644 --- a/doc/src/index.rst +++ b/doc/src/index.rst @@ -91,9 +91,10 @@ Available Functions but not official pgRouting functions Current release ------------------------------------------------------------------------------- + .. include:: release_notes.rst :start-after: current - :end-before: pgRouting 3.6.1 + :end-before: pgRouting 3.6 All releases ------------------------------------------------------------------------------- diff --git a/doc/src/migration.rst b/doc/src/migration.rst index ce0ebbcab95..072e60275a2 100644 --- a/doc/src/migration.rst +++ b/doc/src/migration.rst @@ -307,6 +307,89 @@ columns: :start-after: --drivingdistance4 :end-before: --drivingdistance5 +Migration of ``pgr_kruskalDD`` / ``pgr_kruskalBFS`` / ``pgr_kruskalDFS`` +------------------------------------------------------------------------------- + +Starting from `v3.7.0 `__ +:doc:`pgr_kruskalDD`, :doc:`pgr_kruskalBFS` and +:doc:`pgr_kruskalDFS` result columns are being standardized. + +:from: |result-bfs| +:to: |result-spantree| + +* ``pgr_kruskalDD`` + + * Single vertex + * Multiple vertices + +* ``pgr_kruskalDFS`` + + * Single vertex + * Multiple vertices + +* ``pgr_kruskalBFS`` + + * Single vertex + * Multiple vertices + + +:Before Migration: + +Output columns were |result-bfs| + +* Single vertex and Multiple vertices + + * Do not have ``pred`` result column. + +:Migration: + +* Be aware of the existence of `pred` result columns. +* If needed filter out the added columns + +Kruskal single vertex +............................................................................... + +Using ``pgr_KruskalDD`` as example. +Migration is similar to al the affected functions. + +Comparing with `this +`__ example. + +Now column ``pred`` exists and contains the predecessor of the ``node``. + +.. literalinclude:: migration.queries + :start-after: --kruskalDD1 + :end-before: --kruskalDD2 + +If needed filter out the added columns, for example, to return the original +columns + +.. literalinclude:: migration.queries + :start-after: --kruskalDD2 + :end-before: --kruskalDD3 + +Kruskal multiple vertices +............................................................................... + +Using ``pgr_KruskalDD`` as example. +Migration is similar to al the affected functions. + +Comparing with `this +`__ +example. + +Now column ``pred`` exists and contains the predecessor of the ``node``. + +.. literalinclude:: migration.queries + :start-after: --kruskalDD3 + :end-before: --kruskalDD4 + +If needed filter out the added columns, for example, to return the original +columns + +.. literalinclude:: migration.queries + :start-after: --kruskalDD4 + :end-before: --kruskalDD5 Migration of ``pgr_KSP`` ------------------------------------------------------------------------------- @@ -406,6 +489,90 @@ Migration is needed, because: :start-after: --maxcard2 :end-before: --maxcard3 +Migration of ``pgr_primDD`` / ``pgr_primBFS`` / ``pgr_primDFS`` +------------------------------------------------------------------------------- + +Starting from `v3.7.0 `__ +:doc:`pgr_primDD`, :doc:`pgr_primBFS` and :doc:`pgr_primDFS` result columns are +being standardized. + +:from: |result-bfs| +:to: |result-spantree| + +* ``pgr_primDD`` + + * Single vertex + * Multiple vertices + +* ``pgr_primDFS`` + + * Single vertex + * Multiple vertices + +* ``pgr_primBFS`` + + * Single vertex + * Multiple vertices + + +:Before Migration: + +Output columns were |result-bfs| + +* Single vertex and Multiple vertices + + * Do not have ``pred`` result column. + +:Migration: + +* Be aware of the existence of `pred` result columns. +* If needed filter out the added columns + +Prim single vertex +............................................................................... + +Using ``pgr_primDD`` as example. +Migration is similar to al the affected functions. + +Comparing with `this +`__ example. + +Now column ``pred`` exists and contains the predecessor of the ``node``. + +.. literalinclude:: migration.queries + :start-after: --primDD1 + :end-before: --primDD2 + +If needed filter out the added columns, for example, to return the original +columns + +.. literalinclude:: migration.queries + :start-after: --primDD2 + :end-before: --primDD3 + +Prim multiple vertices +............................................................................... + +Using ``pgr_primDD`` as example. +Migration is similar to al the affected functions. + +Comparing with `this +`__ +example. + +Now column ``pred`` exists and contains the predecessor of the ``node``. + +.. literalinclude:: migration.queries + :start-after: --primDD3 + :end-before: --primDD4 + +If needed filter out the added columns, for example, to return the original +columns + +.. literalinclude:: migration.queries + :start-after: --primDD4 + :end-before: --primDD5 + Migration of ``pgr_withPointsDD`` ------------------------------------------------------------------------------- diff --git a/doc/src/pgRouting-introduction.rst b/doc/src/pgRouting-introduction.rst index e56bb3fb363..661c38a9e9e 100644 --- a/doc/src/pgRouting-introduction.rst +++ b/doc/src/pgRouting-introduction.rst @@ -63,21 +63,13 @@ Contributors This Release Contributors +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -Individuals in this release (in alphabetical order) +Individuals in this release v3.7.x (in alphabetical order) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Aniket Agarwal, -Aryan Gupta, -Ashish Kumar, -Cayetano Benavent, -Daniel Kastl, -Nitish Chauhan, -Rajat Shinde, +(Alphabetical order) + Regina Obe, -Shobhit Chaurasia, -Swapnil Joshi, -Virginia Vergara, -Yige Huang +Vicky Vergara And all the people that give us a little of their time making comments, finding diff --git a/doc/src/proposed.rst b/doc/src/proposed.rst index 3ee938696bb..b18137967e6 100644 --- a/doc/src/proposed.rst +++ b/doc/src/proposed.rst @@ -60,6 +60,12 @@ Proposed Functions :start-after: topology_proposed_start :end-before: topology_proposed_end +:doc:`transformation-family` + +.. include:: transformation-family.rst + :start-after: index proposed from here + :end-before: index proposed to here + :doc:`coloring-family` .. include:: coloring-family.rst diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index df42e36d579..3fac3199736 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -27,7 +27,7 @@ pgRouting 3 :local: :depth: 1 -pgRouting 3.6 +pgRouting 3.7 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .. contents:: Contents @@ -36,6 +36,71 @@ pgRouting 3.6 .. current +pgRouting 3.7.0 Release Notes +------------------------------------------------------------------------------- + +To see all issues & pull requests closed by this release see the `Git closed +milestone for 3.7.0 +`__ + +.. rubric:: Support + +* `#2656 `__ Stop support of + PostgreSQL12 on pgrouting v3.7 + + * Stopping support of PostgreSQL 12 + * CI does not test for PostgreSQL 12 + +.. rubric:: New experimental functions + +* Metrics + + * pgr_betweennessCentrality + +.. rubric:: Official functions changes + +* `#2605 `__ Standarize + spanning tree functions output + + * Functions: + + * ``pgr_kruskalDD`` + * ``pgr_kruskalDFS`` + * ``pgr_kruskalBFS`` + * ``pgr_primDD`` + * ``pgr_primDFS`` + * ``pgr_primBFS`` + + .. include:: pgr_primDD.rst + :start-after: Version 3.7.0 + :end-before: .. rubric + +.. rubric:: Experimental promoted to proposed. + +* `#2635 `__ pgr_LineGraph + ignores directed flag and use negative values for identifiers. + + * ``pgr_lineGraph`` + + .. include:: pgr_lineGraph.rst + :start-after: Version 3.7.0 + :end-before: Version 2.5.0 + +.. rubric:: Code enhancement + +* `#2599 `__ Driving distance + cleanup +* `#2607 `__ Read postgresql + data on C++ +* `#2614 `__ Clang tidy does + not work + +pgRouting 3.6 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. contents:: Contents + :local: + :depth: 1 pgRouting 3.6.3 Release Notes ------------------------------------------------------------------------------- diff --git a/doc/topologicalSort/pgr_topologicalSort.rst b/doc/topologicalSort/pgr_topologicalSort.rst index 9cc85a80265..3e4bddc70d5 100644 --- a/doc/topologicalSort/pgr_topologicalSort.rst +++ b/doc/topologicalSort/pgr_topologicalSort.rst @@ -69,7 +69,7 @@ Signatures :Example: Topologically sorting the graph -.. literalinclude:: doc-topologicalSort.queries +.. literalinclude:: topologicalSort.queries :start-after: -- q1 :end-before: -- q2 @@ -115,13 +115,13 @@ Additional examples :Example: Topologically sorting the one way segments -.. literalinclude:: doc-topologicalSort.queries +.. literalinclude:: topologicalSort.queries :start-after: -- q2 :end-before: -- q3 :Example: Graph is not a DAG -.. literalinclude:: doc-topologicalSort.queries +.. literalinclude:: topologicalSort.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/topology/pgr_analyzeGraph.rst b/doc/topology/pgr_analyzeGraph.rst index 4b8a4072584..64c68bb56cc 100644 --- a/doc/topology/pgr_analyzeGraph.rst +++ b/doc/topology/pgr_analyzeGraph.rst @@ -106,13 +106,13 @@ Usage when the edge table's columns MATCH the default values: .. rubric:: The simplest way to use pgr_analyzeGraph is: -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q1 :end-before: -- q1.1 .. rubric:: Arguments are given in the order described in the parameters: -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q3 :end-before: -- q3.1 @@ -126,7 +126,7 @@ We get the same result as the simplest way to use the function. is passed to the function as the geometry column, and the geometry column ``the_geom`` is passed to the function as the id column. -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q5 :end-before: -- q5.1 @@ -135,18 +135,18 @@ We get the same result as the simplest way to use the function. The order of the parameters do not matter: -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q6 :end-before: -- q6.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q7 :end-before: -- q7.1 Parameters defined with a default value can be omitted, as long as the value matches the default: -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q8 :end-before: -- q8.1 @@ -155,21 +155,21 @@ matches the default: Selecting rows based on the id. Displays the analysis a the section of the network. -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q9 :end-before: -- q9.1 Selecting the rows where the geometry is near the geometry of row with ``id`` = 5 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q10 :end-before: -- q10.1 Selecting the rows where the geometry is near the geometry of the row with ``gid`` =100 of the table ``othertable``. -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q11 :end-before: -- q11.1 @@ -178,7 +178,7 @@ Usage when the edge table's columns DO NOT MATCH the default values: For the following table -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q12 :end-before: -- q12.1 @@ -186,7 +186,7 @@ For the following table The arguments need to be given in the order described in the parameters: -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q13 :end-before: -- q13.1 @@ -196,7 +196,7 @@ The arguments need to be given in the order described in the parameters: geometry column, and the geometry column ``mygeom`` is passed to the function as the id column. -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q14 :end-before: -- q14.1 @@ -204,11 +204,11 @@ The arguments need to be given in the order described in the parameters: The order of the parameters do not matter: -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q15 :end-before: -- q15.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q16 :end-before: -- q16.1 @@ -219,59 +219,59 @@ values for the column names do not match the column names of the table. Selecting rows based on the id. -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q17 :end-before: -- q17.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q18 :end-before: -- q18.1 Selecting the rows WHERE the geometry is near the geometry of row with ``id`` =5 . -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q19 :end-before: -- q19.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q20 :end-before: -- q20.1 Selecting the rows WHERE the geometry is near the place='myhouse' of the table ``othertable``. (note the use of quote_literal) -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q21 :end-before: -- q21.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q22 :end-before: -- q22.1 Additional Examples ------------------------------------------------------------------------------- -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q23 :end-before: -- q23.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q24 :end-before: -- q24.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q25 :end-before: -- q25.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q26 :end-before: -- q26.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q27 :end-before: -- q27.1 -.. literalinclude:: doc-pgr_analyzeGraph.queries +.. literalinclude:: analyzeGraph.queries :start-after: -- q28 :end-before: -- q28.1 diff --git a/doc/topology/pgr_analyzeOneWay.rst b/doc/topology/pgr_analyzeOneWay.rst index 3b90a579b50..a5dd2c6d183 100644 --- a/doc/topology/pgr_analyzeOneWay.rst +++ b/doc/topology/pgr_analyzeOneWay.rst @@ -128,7 +128,7 @@ The structure of the vertices table is: Additional Examples ------------------------------------------------------------------------------- -.. literalinclude:: doc-pgr_analyzeOneWay.queries +.. literalinclude:: analyzeOneWay.queries :start-after: --q1 :end-before: --q1.1 diff --git a/doc/topology/pgr_createTopology.rst b/doc/topology/pgr_createTopology.rst index 6b552675314..9e4886d9ec6 100644 --- a/doc/topology/pgr_createTopology.rst +++ b/doc/topology/pgr_createTopology.rst @@ -120,7 +120,7 @@ Usage when the edge table's columns MATCH the default values: The simplest way to use pgr_createTopology is: -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q1 :end-before: --q1.1 @@ -129,7 +129,7 @@ The simplest way to use pgr_createTopology is: We get the sameresult as the simplest way to use the function. -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q2 :end-before: --q2.1 @@ -139,7 +139,7 @@ We get the sameresult as the simplest way to use the function. passed to the function as the geometry column, and the geometry column ``the_geom`` is passed to the function as the id column. - .. literalinclude:: doc-pgr_createTopology.queries + .. literalinclude:: createTopology.queries :start-after: --q3 :end-before: --q3.1 @@ -148,15 +148,15 @@ We get the sameresult as the simplest way to use the function. Parameters defined with a default value can be omitted, as long as the value matches the default And The order of the parameters would not matter. -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q4 :end-before: --q4.1 -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q5 :end-before: --q5.1 -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q6 :end-before: --q6.1 @@ -164,21 +164,21 @@ matches the default And The order of the parameters would not matter. Selecting rows based on the id. -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q7 :end-before: --q7.1 Selecting the rows where the geometry is near the geometry of row with ``id = 5``. -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q8 :end-before: --q8.1 Selecting the rows where the geometry is near the geometry of the row with ``gid`` =100 of the table ``othertable``. -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q9 :end-before: --q9.1 @@ -187,7 +187,7 @@ Usage when the edge table's columns DO NOT MATCH the default values: For the following table -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q10 :end-before: --q10.1 @@ -198,7 +198,7 @@ The arguments need to be given in the order described in the parameters. Note that this example uses clean flag. So it recreates the whole vertices table. -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q11 :end-before: --q11.1 @@ -208,7 +208,7 @@ table. to the function AS the geometry column, and the geometry column ``mygeom`` is passed to the function AS the id column. - .. literalinclude:: doc-pgr_createTopology.queries + .. literalinclude:: createTopology.queries :start-after: --q12 :end-before: --q12.1 @@ -218,11 +218,11 @@ In this scenario omitting a parameter would create an error because the default values for the column names do not match the column names of the table. The order of the parameters do not matter: -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q13 :end-before: --q13.1 -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q14 :end-before: --q14.1 @@ -230,14 +230,14 @@ The order of the parameters do not matter: Based on id: -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q15 :end-before: --q15.1 Selecting the rows where the geometry is near the geometry of the row with ``gid`` =100 of the table ``othertable``. -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q16 :end-before: --q16.1 @@ -264,7 +264,7 @@ With full output This example start a clean topology, with 5 edges, and then its incremented to the rest of the edges. -.. literalinclude:: doc-pgr_createTopology.queries +.. literalinclude:: createTopology.queries :start-after: --q17 :end-before: --q17.1 diff --git a/doc/topology/pgr_createVerticesTable.rst b/doc/topology/pgr_createVerticesTable.rst index 69562235a65..b17ad3d10a9 100644 --- a/doc/topology/pgr_createVerticesTable.rst +++ b/doc/topology/pgr_createVerticesTable.rst @@ -104,7 +104,7 @@ The structure of the vertices table is: :Example 1: The simplest way to use pgr_createVerticesTable -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q1 :end-before: --q1.1 @@ -115,7 +115,7 @@ Additional Examples :Example 2: When the arguments are given in the order described in the parameters: -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q2 :end-before: --q2.1 @@ -128,7 +128,7 @@ We get the same result as the simplest way to use the function. ``mytable`` is passed to the function as the geometry column, and the geometry column ``the_geom`` is passed to the function as the source column. - .. literalinclude:: doc-pgr_createVerticesTable.queries + .. literalinclude:: createVerticesTable.queries :start-after: --q2.1 :end-before: --q2.2 @@ -137,13 +137,13 @@ We get the same result as the simplest way to use the function. :Example 3: The order of the parameters do not matter: -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q3.1 :end-before: --q3.2 :Example 4: Using a different ordering -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q4 :end-before: --q4.1 @@ -151,7 +151,7 @@ We get the same result as the simplest way to use the function. :Example 5: Parameters defined with a default value can be omitted, as long as the value matches the default: -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q5 :end-before: --q5.1 @@ -160,7 +160,7 @@ We get the same result as the simplest way to use the function. :Example 6: Selecting rows based on the id. -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q6 :end-before: --q6.1 @@ -168,7 +168,7 @@ We get the same result as the simplest way to use the function. :Example 7: Selecting the rows where the geometry is near the geometry of row with ``id`` =5 . -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q7 :end-before: --q7.1 @@ -176,7 +176,7 @@ We get the same result as the simplest way to use the function. :Example 8: Selecting the rows where the geometry is near the geometry of the row with ``gid`` =100 of the table ``othertable``. -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q8 :end-before: --q8.1 @@ -185,7 +185,7 @@ Usage when the edge table's columns DO NOT MATCH the default values: Using the following table -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --tab1 :end-before: --tab2 @@ -194,7 +194,7 @@ Using the following table :Example 9: The arguments need to be given in the order described in the parameters: -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q9 :end-before: --q9.1 @@ -204,7 +204,7 @@ Using the following table to the function as the geometry column, and the geometry column ``mygeom`` is passed to the function as the source column. - .. literalinclude:: doc-pgr_createVerticesTable.queries + .. literalinclude:: createVerticesTable.queries :start-after: --q9.1 :end-before: --q9.2 @@ -212,7 +212,7 @@ Using the following table :Example 10: The order of the parameters do not matter: -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q10 :end-before: --q10.1 @@ -221,7 +221,7 @@ Using the following table In this scenario omitting a parameter would create an error because the default values for the column names do not match the column names of the table. -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q11 :end-before: --q11.1 @@ -230,44 +230,44 @@ values for the column names do not match the column names of the table. :Example 12: Selecting rows based on the gid. (positional notation) -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q12 :end-before: --q12.1 :Example 13: Selecting rows based on the gid. (named notation) -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q13 :end-before: --q13.1 :Example 14: Selecting the rows where the geometry is near the geometry of row with ``gid`` = 5. -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q14 :end-before: --q14.1 :Example 15: TBD -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q15 :end-before: --q15.1 :Example 16: Selecting the rows where the geometry is near the geometry of the row with ``gid`` =100 of the table ``othertable``. -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q16 :end-before: --q16.1 -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q16.1 :end-before: --q16.2 :Example 17: TBD -.. literalinclude:: doc-pgr_createVerticesTable.queries +.. literalinclude:: createVerticesTable.queries :start-after: --q17 :end-before: --q17.1 diff --git a/doc/topology/pgr_extractVertices.rst b/doc/topology/pgr_extractVertices.rst index b4d58bee7c1..fed52d23afc 100644 --- a/doc/topology/pgr_extractVertices.rst +++ b/doc/topology/pgr_extractVertices.rst @@ -57,7 +57,7 @@ Signatures :Example: Extracting the vertex information -.. literalinclude:: doc-pgr_extractVertices.queries +.. literalinclude:: extractVertices.queries :start-after: --q1 :end-before: --q1.1 @@ -206,7 +206,7 @@ true``. The results can be used as base code to make a refinement based on the backend development needs. -.. literalinclude:: doc-pgr_extractVertices.queries +.. literalinclude:: extractVertices.queries :start-after: --q2 :end-before: --q2.1 @@ -219,14 +219,14 @@ Create a routing topology Make sure the database does not have the ``vertices_table`` +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_extractVertices.queries +.. literalinclude:: extractVertices.queries :start-after: --q3 :end-before: --q3.1 Clean up the columns of the routing topology to be created +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_extractVertices.queries +.. literalinclude:: extractVertices.queries :start-after: --q3.1 :end-before: --q3.2 @@ -239,14 +239,14 @@ Create the vertices table * Create it as ``UNLOGGED`` and * After the table is created ``ALTER TABLE .. SET LOGGED`` -.. literalinclude:: doc-pgr_extractVertices.queries +.. literalinclude:: extractVertices.queries :start-after: --q3.2 :end-before: --q3.3 Inspect the vertices table +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_extractVertices.queries +.. literalinclude:: extractVertices.queries :start-after: --q3.3 :end-before: --q3.4 @@ -255,20 +255,20 @@ Create the routing topology on the edge table Updating the ``source`` information -.. literalinclude:: doc-pgr_extractVertices.queries +.. literalinclude:: extractVertices.queries :start-after: --q3.4 :end-before: --q3.5 Updating the ``target`` information -.. literalinclude:: doc-pgr_extractVertices.queries +.. literalinclude:: extractVertices.queries :start-after: --q3.5 :end-before: --q3.6 Inspect the routing topology +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_extractVertices.queries +.. literalinclude:: extractVertices.queries :start-after: --q3.6 :end-before: --q3.7 diff --git a/doc/topology/pgr_nodeNetwork.rst b/doc/topology/pgr_nodeNetwork.rst index bc321e160b0..239cf548587 100644 --- a/doc/topology/pgr_nodeNetwork.rst +++ b/doc/topology/pgr_nodeNetwork.rst @@ -86,39 +86,39 @@ Examples Let's create the topology for the data in :doc:`sampledata` -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q1 :end-before: --q1.1 Now we can analyze the network. -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q2 :end-before: --q2.1 The analysis tell us that the network has a gap and an intersection. We try to fix the problem using: -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q3 :end-before: --q3.1 Inspecting the generated table, we can see that edges 13,14 and 18 has been segmented -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q4 :end-before: --q4.1 We can create the topology of the new network -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q5 :end-before: --q5.1 Now let's analyze the new topology -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q6 :end-before: --q6.1 @@ -182,27 +182,27 @@ following steps: of the original edge - Insert only the segmented edges, that is, the ones whose max(sub_id) >1 -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q7 :end-before: --q7.1 We recreate the topology: -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q8 :end-before: --q8.1 To get the same analysis results as the topology of edge_table_noded, we do the following query: -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q9 :end-before: --q9.1 To get the same analysis results as the original edge_table, we do the following query: -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q10 :end-before: --q10.1 @@ -210,7 +210,7 @@ Or we can analyze everything because, maybe edge 18 is an overpass, edge 14 is an under pass and there is also a street level juction, and the same happens with edges 17 and 13. -.. literalinclude:: doc-pgr_nodeNetwork.queries +.. literalinclude:: nodeNetwork.queries :start-after: --q11 :end-before: --q11.1 diff --git a/doc/transitiveClosure/pgr_transitiveClosure.rst b/doc/transitiveClosure/pgr_transitiveClosure.rst index 0bf435cf860..0417be5f797 100644 --- a/doc/transitiveClosure/pgr_transitiveClosure.rst +++ b/doc/transitiveClosure/pgr_transitiveClosure.rst @@ -69,7 +69,7 @@ The pgr_transitiveClosure function has the following signature: :Example: Rechability of a subgraph -.. literalinclude:: doc-transitiveClosure.queries +.. literalinclude:: transitiveClosure.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/traversal/pgr_depthFirstSearch.rst b/doc/traversal/pgr_depthFirstSearch.rst index 7e854791001..70560f0d4e8 100644 --- a/doc/traversal/pgr_depthFirstSearch.rst +++ b/doc/traversal/pgr_depthFirstSearch.rst @@ -91,7 +91,7 @@ Single vertex :Example: From root vertex :math:`6` on a **directed** graph with edges in ascending order of ``id`` -.. literalinclude:: doc-pgr_depthFirstSearch.queries +.. literalinclude:: depthFirstSearch.queries :start-after: -- q1 :end-before: -- q2 @@ -112,7 +112,7 @@ Multiple vertices :Example: From root vertices :math:`\{12, 6\}` on an **undirected** graph with **depth** :math:`<= 2` and edges in ascending order of ``id`` -.. literalinclude:: doc-pgr_depthFirstSearch.queries +.. literalinclude:: depthFirstSearch.queries :start-after: -- q2 :end-before: -- q3 @@ -159,7 +159,7 @@ Additional Examples :Example: Same as `Single vertex`_ but with edges in descending order of ``id``. -.. literalinclude:: doc-pgr_depthFirstSearch.queries +.. literalinclude:: depthFirstSearch.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/trsp/pgr_trsp.rst b/doc/trsp/pgr_trsp.rst index 4fe728abbb3..cb979f73226 100644 --- a/doc/trsp/pgr_trsp.rst +++ b/doc/trsp/pgr_trsp.rst @@ -105,7 +105,7 @@ One to One :Example: From vertex :math:`6` to vertex :math:`10` on an undirected graph. -.. literalinclude:: doc-trsp.queries +.. literalinclude:: trsp.queries :start-after: -- q2 :end-before: -- q3 @@ -126,7 +126,7 @@ One to Many :Example: From vertex :math:`6` to vertices :math:`\{10, 1\}` on an undirected graph. -.. literalinclude:: doc-trsp.queries +.. literalinclude:: trsp.queries :start-after: -- q3 :end-before: -- q4 @@ -147,7 +147,7 @@ Many to One :Example: From vertices :math:`\{6, 1\}` to vertex :math:`8` on a directed graph. -.. literalinclude:: doc-trsp.queries +.. literalinclude:: trsp.queries :start-after: -- q4 :end-before: -- q5 @@ -169,7 +169,7 @@ Many to Many :Example: From vertices :math:`\{6, 1\}` to vertices :math:`\{10, 8\}` on an undirected graph. -.. literalinclude:: doc-trsp.queries +.. literalinclude:: trsp.queries :start-after: -- q5 :end-before: -- q6 @@ -189,7 +189,7 @@ Combinations :Example: Using a combinations table on an undirected graph. -.. literalinclude:: doc-trsp.queries +.. literalinclude:: trsp.queries :start-after: -- q6 :end-before: -- q7 diff --git a/doc/trsp/pgr_turnRestrictedPath.rst b/doc/trsp/pgr_turnRestrictedPath.rst index 453b38e7774..59fd8379c9e 100644 --- a/doc/trsp/pgr_turnRestrictedPath.rst +++ b/doc/trsp/pgr_turnRestrictedPath.rst @@ -49,7 +49,7 @@ Signatures :Example: From vertex :math:`3` to vertex :math:`8` on a directed graph -.. literalinclude:: doc-pgr_turnRestrictedPath.queries +.. literalinclude:: turnRestrictedPath.queries :start-after: -- q1 :end-before: -- q2 @@ -130,19 +130,19 @@ Additional Examples No results because the only path available follows a restriction. -.. literalinclude:: doc-pgr_turnRestrictedPath.queries +.. literalinclude:: turnRestrictedPath.queries :start-after: -- q2 :end-before: -- q3 :Example: From vertex :math:`3` to vertex :math:`8` on an undirected graph -.. literalinclude:: doc-pgr_turnRestrictedPath.queries +.. literalinclude:: turnRestrictedPath.queries :start-after: -- q3 :end-before: -- q4 :Example: From vertex :math:`3` to vertex :math:`8` with more alternatives -.. literalinclude:: doc-pgr_turnRestrictedPath.queries +.. literalinclude:: turnRestrictedPath.queries :start-after: -- q4 :end-before: -- q5 diff --git a/doc/tsp/pgr_TSP.rst b/doc/tsp/pgr_TSP.rst index 26aa91fed18..db9db054782 100644 --- a/doc/tsp/pgr_TSP.rst +++ b/doc/tsp/pgr_TSP.rst @@ -126,7 +126,7 @@ Signatures * **Line 4** Vertices :math:`\{2, 4, 13, 14\}` are not included because they are not connected. -.. literalinclude:: doc-pgr_TSP.queries +.. literalinclude:: TSP.queries :start-after: -- q1 :end-before: -- q2 :linenos: @@ -183,7 +183,7 @@ Start from vertex :math:`1` * **Line 6** ``start_vid => 1`` -.. literalinclude:: doc-pgr_TSP.queries +.. literalinclude:: TSP.queries :start-after: -- q2 :end-before: -- q3 :linenos: @@ -205,7 +205,7 @@ To generate an asymmetric matrix: * Triangle inequality might not be satisfied. * ``start_id != 0 AND end_id != 0`` -.. literalinclude:: doc-pgr_TSP.queries +.. literalinclude:: TSP.queries :start-after: -- q3 :end-before: -- q4 :linenos: @@ -215,7 +215,7 @@ Connected incomplete data Using selected edges :math:`\{2, 4, 5, 8, 9, 15\}` the matrix is not complete. -.. literalinclude:: doc-pgr_TSP.queries +.. literalinclude:: TSP.queries :start-after: -- q4 :end-before: -- q5 :linenos: @@ -223,7 +223,7 @@ Using selected edges :math:`\{2, 4, 5, 8, 9, 15\}` the matrix is not complete. Cost value for :math:`17 \rightarrow 10` do not exist on the matrix, but the value used is taken from :math:`10 \rightarrow 17`. -.. literalinclude:: doc-pgr_TSP.queries +.. literalinclude:: TSP.queries :start-after: -- q5 :end-before: -- q6 :linenos: diff --git a/doc/tsp/pgr_TSPeuclidean.rst b/doc/tsp/pgr_TSPeuclidean.rst index a36dacc12ba..0c1e1e4fba2 100644 --- a/doc/tsp/pgr_TSPeuclidean.rst +++ b/doc/tsp/pgr_TSPeuclidean.rst @@ -89,7 +89,7 @@ Signatures :Example: With default values -.. literalinclude:: doc-pgr_TSPeuclidean.queries +.. literalinclude:: TSPeuclidean.queries :start-after: -- q1 :end-before: -- q2 @@ -167,14 +167,14 @@ Total tour cost Getting a total cost of the tour, compare the value with the length of an optimal tour is 27603, given on the dataset -.. literalinclude:: doc-pgr_TSPeuclidean.queries +.. literalinclude:: TSPeuclidean.queries :start-after: -- q2 :end-before: -- q3 Getting a geometry of the tour +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. literalinclude:: doc-pgr_TSPeuclidean.queries +.. literalinclude:: TSPeuclidean.queries :start-after: -- q3 :end-before: -- q4 diff --git a/doc/version/pgr_full_version.rst b/doc/version/pgr_full_version.rst index bfdff43310f..8d32604add4 100644 --- a/doc/version/pgr_full_version.rst +++ b/doc/version/pgr_full_version.rst @@ -43,7 +43,7 @@ Signatures :Example: Information about when this documentation was built -.. literalinclude:: doc-full_version.queries +.. literalinclude:: full_version.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/version/pgr_version.rst b/doc/version/pgr_version.rst index 8e1146cac2e..88807fe1d2f 100644 --- a/doc/version/pgr_version.rst +++ b/doc/version/pgr_version.rst @@ -47,7 +47,7 @@ Signature :Example: pgRouting Version for this documentation -.. literalinclude:: doc-version.queries +.. literalinclude:: version.queries :start-after: -- q1 :end-before: -- q2 diff --git a/doc/vrp_basic/pgr_vrpOneDepot.rst b/doc/vrp_basic/pgr_vrpOneDepot.rst index 9e4fe34d649..5dd273d67d3 100644 --- a/doc/vrp_basic/pgr_vrpOneDepot.rst +++ b/doc/vrp_basic/pgr_vrpOneDepot.rst @@ -55,7 +55,7 @@ Result columns Additional Example: ------------------------------------------------------------------------------- -.. literalinclude:: doc-pgr_vrpOneDepot.queries +.. literalinclude:: vrpOneDepot.queries .. rubric:: Data diff --git a/doc/withPoints/pgr_withPoints.rst b/doc/withPoints/pgr_withPoints.rst index b2d601c9620..3eeb99caa9e 100644 --- a/doc/withPoints/pgr_withPoints.rst +++ b/doc/withPoints/pgr_withPoints.rst @@ -103,7 +103,7 @@ One to One :Example: From point :math:`1` to vertex :math:`10` with details -.. literalinclude:: doc-pgr_withPoints.queries +.. literalinclude:: withPoints.queries :start-after: -- q1 :end-before: -- q2 @@ -125,7 +125,7 @@ One to Many :Example: From point :math:`1` to point :math:`3` and vertex :math:`7` on an undirected graph -.. literalinclude:: doc-pgr_withPoints.queries +.. literalinclude:: withPoints.queries :start-after: -- q2 :end-before: -- q3 @@ -146,7 +146,7 @@ Many to One :Example: From point :math:`1` and vertex :math:`6` to point :math:`3` -.. literalinclude:: doc-pgr_withPoints.queries +.. literalinclude:: withPoints.queries :start-after: -- q3 :end-before: -- q4 @@ -168,7 +168,7 @@ Many to Many :Example: From point :math:`1` and vertex :math:`6` to point :math:`3` and vertex :math:`1` -.. literalinclude:: doc-pgr_withPoints.queries +.. literalinclude:: withPoints.queries :start-after: -- q4 :end-before: -- q5 @@ -192,7 +192,7 @@ Combinations From point :math:`1` to vertex :math:`10`, and from vertex :math:`6` to point :math:`3` with **right** side driving. -.. literalinclude:: doc-pgr_withPoints.queries +.. literalinclude:: withPoints.queries :start-after: -- q5 :end-before: -- q6 @@ -260,7 +260,7 @@ Use :doc:`pgr_findCloseEdges` in the `Points SQL`_. Find the routes from vertex :math:`1` to the two closest locations on the graph of point `(2.9, 1.8)`. -.. literalinclude:: doc-pgr_withPoints.queries +.. literalinclude:: withPoints.queries :start-after: -- q9 :end-before: -- q10 @@ -273,7 +273,7 @@ Usage variations All the examples are about traveling from point :math:`1` and vertex :math:`5` to points :math:`\{2, 3, 6\}` and vertices :math:`\{10, 11\}` -.. literalinclude:: doc-pgr_withPoints.queries +.. literalinclude:: withPoints.queries :start-after: -- q6 :end-before: -- q7 @@ -283,7 +283,7 @@ Passes in front or visits with right side driving. For point :math:`6` and vertex :math:`11`. -.. literalinclude:: doc-pgr_withPoints.queries +.. literalinclude:: withPoints.queries :start-after: -- q7 :end-before: -- q8 @@ -292,7 +292,7 @@ Passes in front or visits with left side driving. For point :math:`6` and vertex :math:`11`. -.. literalinclude:: doc-pgr_withPoints.queries +.. literalinclude:: withPoints.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/withPoints/pgr_withPointsCost.rst b/doc/withPoints/pgr_withPointsCost.rst index 8da74cfc223..59f186a61d3 100644 --- a/doc/withPoints/pgr_withPointsCost.rst +++ b/doc/withPoints/pgr_withPointsCost.rst @@ -125,7 +125,7 @@ One to One :Example: From point :math:`1` to vertex :math:`10` with defaults -.. literalinclude:: doc-pgr_withPointsCost.queries +.. literalinclude:: withPointsCost.queries :start-after: -- q1 :end-before: -- q2 @@ -147,7 +147,7 @@ One to Many :Example: From point :math:`1` to point :math:`3` and vertex :math:`7` on an undirected graph -.. literalinclude:: doc-pgr_withPointsCost.queries +.. literalinclude:: withPointsCost.queries :start-after: -- q2 :end-before: -- q3 @@ -168,7 +168,7 @@ Many to One :Example: From point :math:`1` and vertex :math:`6` to point :math:`3` -.. literalinclude:: doc-pgr_withPointsCost.queries +.. literalinclude:: withPointsCost.queries :start-after: -- q3 :end-before: -- q4 @@ -190,7 +190,7 @@ Many to Many :Example: From point :math:`15` and vertex :math:`6` to point :math:`3` and vertex :math:`1` -.. literalinclude:: doc-pgr_withPointsCost.queries +.. literalinclude:: withPointsCost.queries :start-after: -- q4 :end-before: -- q5 @@ -214,7 +214,7 @@ Combinations From point :math:`1` to vertex :math:`10`, and from vertex :math:`6` to point :math:`3` with **right** side driving. -.. literalinclude:: doc-pgr_withPointsCost.queries +.. literalinclude:: withPointsCost.queries :start-after: -- q5 :end-before: -- q6 @@ -320,7 +320,7 @@ Use :doc:`pgr_findCloseEdges` in the `Points SQL`_. Find the cost of the routes from vertex :math:`1` to the two closest locations on the graph of point `(2.9, 1.8)`. -.. literalinclude:: doc-pgr_withPointsCost.queries +.. literalinclude:: withPointsCost.queries :start-after: -- q9 :end-before: -- q10 @@ -334,7 +334,7 @@ Right side driving topology Traveling from point :math:`1` and vertex :math:`5` to points :math:`\{2, 3, 6\}` and vertices :math:`\{10, 11\}` -.. literalinclude:: doc-pgr_withPointsCost.queries +.. literalinclude:: withPointsCost.queries :start-after: -- q6 :end-before: -- q7 @@ -344,7 +344,7 @@ Left side driving topology Traveling from point :math:`1` and vertex :math:`5` to points :math:`\{2, 3, 6\}` and vertices :math:`\{10, 11\}` -.. literalinclude:: doc-pgr_withPointsCost.queries +.. literalinclude:: withPointsCost.queries :start-after: -- q7 :end-before: -- q8 @@ -354,7 +354,7 @@ Does not matter driving side driving topology Traveling from point :math:`1` and vertex :math:`5` to points :math:`\{2, 3, 6\}` and vertices :math:`\{10, 11\}` -.. literalinclude:: doc-pgr_withPointsCost.queries +.. literalinclude:: withPointsCost.queries :start-after: -- q8 :end-before: -- q9 diff --git a/doc/withPoints/pgr_withPointsCostMatrix.rst b/doc/withPoints/pgr_withPointsCostMatrix.rst index c45584c59d7..b5f434ce440 100644 --- a/doc/withPoints/pgr_withPointsCostMatrix.rst +++ b/doc/withPoints/pgr_withPointsCostMatrix.rst @@ -71,7 +71,7 @@ Signatures * Using the default ``side`` value on the **points_sql** query * Using the default ``driving_side`` value -.. literalinclude:: doc-pgr_withPointsCostMatrix.queries +.. literalinclude:: withPointsCostMatrix.queries :start-after: -- q1 :end-before: -- q2 @@ -136,7 +136,7 @@ Use :doc:`pgr_findCloseEdges` in the `Points SQL`_. Find the matrix cost of the routes from vertex :math:`1` and the two closest locations on the graph of point `(2.9, 1.8)`. -.. literalinclude:: doc-pgr_withPointsCostMatrix.queries +.. literalinclude:: withPointsCostMatrix.queries :start-after: -- q3 :end-before: -- q4 @@ -146,7 +146,7 @@ locations on the graph of point `(2.9, 1.8)`. Use with :doc:`pgr_TSP`. ............................................................................... -.. literalinclude:: doc-pgr_withPointsCostMatrix.queries +.. literalinclude:: withPointsCostMatrix.queries :start-after: -- q2 :end-before: -- q3 diff --git a/doc/withPoints/pgr_withPointsDD.rst b/doc/withPoints/pgr_withPointsDD.rst index dfab10b0326..7988acb3e19 100644 --- a/doc/withPoints/pgr_withPointsDD.rst +++ b/doc/withPoints/pgr_withPointsDD.rst @@ -100,7 +100,7 @@ Single vertex :Example: Right side driving topology, from point :math:`1` within a distance of :math:`3.3` with details. -.. literalinclude:: doc-pgr_withPointsDD.queries +.. literalinclude:: withPointsDD.queries :start-after: -- q2 :end-before: -- q3 @@ -122,7 +122,7 @@ Multiple vertices :Example: From point :math:`1` and vertex :math:`16` within a distance of :math:`3.3` with ``equicost`` on a directed graph -.. literalinclude:: doc-pgr_withPointsDD.queries +.. literalinclude:: withPointsDD.queries :start-after: -- q3 :end-before: -- q4 @@ -244,7 +244,7 @@ Use :doc:`pgr_findCloseEdges` in the `Points SQL`_. Find the driving distance from the two closest locations on the graph of point `(2.9, 1.8)`. -.. literalinclude:: doc-pgr_withPointsDD.queries +.. literalinclude:: withPointsDD.queries :start-after: -- q5 :end-before: -- q6 @@ -257,7 +257,7 @@ Driving side does not matter From point :math:`1` within a distance of :math:`3.3`, does not matter driving side, with details. -.. literalinclude:: doc-pgr_withPointsDD.queries +.. literalinclude:: withPointsDD.queries :start-after: -- q4 :end-before: -- q5 diff --git a/doc/withPoints/pgr_withPointsKSP.rst b/doc/withPoints/pgr_withPointsKSP.rst index 08d0cb782ba..648614dbfb4 100644 --- a/doc/withPoints/pgr_withPointsKSP.rst +++ b/doc/withPoints/pgr_withPointsKSP.rst @@ -98,7 +98,7 @@ One to One * No details are given about distance of other points of the query. * No heap paths are returned. -.. literalinclude:: doc-pgr_withPointsKSP.queries +.. literalinclude:: withPointsKSP.queries :start-after: --q1 :end-before: --q2 @@ -120,7 +120,7 @@ One to Many :Example: Get 2 paths from point :math:`1` to point :math:`3` and vertex :math:`7` on an undirected graph -.. literalinclude:: doc-pgr_withPointsKSP.queries +.. literalinclude:: withPointsKSP.queries :start-after: --q2 :end-before: --q3 @@ -142,7 +142,7 @@ Many to One :Example: Get a path from point :math:`1` and vertex :math:`6` to point :math:`3` on a **directed** graph with **right** side driving and **details** set to **True** -.. literalinclude:: doc-pgr_withPointsKSP.queries +.. literalinclude:: withPointsKSP.queries :start-after: --q3 :end-before: --q4 @@ -164,7 +164,7 @@ Many to Many :Example: Get a path from point :math:`1` and vertex :math:`6` to point :math:`3` and vertex :math:`1` on a **directed** graph with **left** side driving and **heap_paths** set to **True** -.. literalinclude:: doc-pgr_withPointsKSP.queries +.. literalinclude:: withPointsKSP.queries :start-after: --q4 :end-before: --q5 @@ -185,7 +185,7 @@ Combinations :Example: Using a combinations table on an **directed** graph -.. literalinclude:: doc-pgr_withPointsKSP.queries +.. literalinclude:: withPointsKSP.queries :start-after: --q5 :end-before: --q6 @@ -307,7 +307,7 @@ Use :doc:`pgr_findCloseEdges` in the `Points SQL`_. Get :math:`2` paths using left side driving topology, from vertex :math:`1` to the closest location on the graph of point `(2.9, 1.8)`. -.. literalinclude:: doc-pgr_withPointsKSP.queries +.. literalinclude:: withPointsKSP.queries :start-after: --q6 :end-before: --q7 @@ -319,7 +319,7 @@ Left driving side Get :math:`2` paths using left side driving topology, from point :math:`1` to point :math:`3` with details. -.. literalinclude:: doc-pgr_withPointsKSP.queries +.. literalinclude:: withPointsKSP.queries :start-after: --q7 :end-before: --q8 @@ -329,7 +329,7 @@ Right driving side Get :math:`2` paths using right side driving topology from, point :math:`1` to point :math:`2` with heap paths and details. -.. literalinclude:: doc-pgr_withPointsKSP.queries +.. literalinclude:: withPointsKSP.queries :start-after: --q8 :end-before: --q9 diff --git a/docqueries/allpairs/CMakeLists.txt b/docqueries/allpairs/CMakeLists.txt index a4cf2412f73..a1736c9cf96 100644 --- a/docqueries/allpairs/CMakeLists.txt +++ b/docqueries/allpairs/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-floydWarshall - doc-johnson + floydWarshall + johnson ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/allpairs/doc-floydWarshall.test.sql b/docqueries/allpairs/floydWarshall.pg similarity index 100% rename from docqueries/allpairs/doc-floydWarshall.test.sql rename to docqueries/allpairs/floydWarshall.pg diff --git a/docqueries/allpairs/doc-floydWarshall.result b/docqueries/allpairs/floydWarshall.result similarity index 100% rename from docqueries/allpairs/doc-floydWarshall.result rename to docqueries/allpairs/floydWarshall.result diff --git a/docqueries/allpairs/doc-johnson.test.sql b/docqueries/allpairs/johnson.pg similarity index 100% rename from docqueries/allpairs/doc-johnson.test.sql rename to docqueries/allpairs/johnson.pg diff --git a/docqueries/allpairs/doc-johnson.result b/docqueries/allpairs/johnson.result similarity index 100% rename from docqueries/allpairs/doc-johnson.result rename to docqueries/allpairs/johnson.result diff --git a/docqueries/allpairs/test.conf b/docqueries/allpairs/test.conf index 9c7a4149ae5..653707ea54e 100644 --- a/docqueries/allpairs/test.conf +++ b/docqueries/allpairs/test.conf @@ -2,24 +2,11 @@ %main::tests = ( 'any' => { - 'comment' => 'All pairs tests.', - 'data' => [''], - 'tests' => [qw( - doc-johnson - doc-floydWarshall - )], - - 'documentation' => [qw( - doc-johnson - doc-floydWarshall + 'files' => [qw( + johnson.pg + floydWarshall.pg )] }, -# I don't know what this are for or how to use them. -# TODO ask Steve -# 'vpg-vpgis' => {}, # for version specific tests -# '8-1' => {}, # for pg 8.x and postgis 1.x -# '9.2-2.1' => {}, # for pg 9.2 and postgis 2.1 - ); 1; diff --git a/docqueries/alpha_shape/CMakeLists.txt b/docqueries/alpha_shape/CMakeLists.txt index 19b80ec97ed..5f783af7cb7 100644 --- a/docqueries/alpha_shape/CMakeLists.txt +++ b/docqueries/alpha_shape/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_alphashape + alphashape ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/alpha_shape/doc-pgr_alphashape.test.sql b/docqueries/alpha_shape/alphashape.pg similarity index 100% rename from docqueries/alpha_shape/doc-pgr_alphashape.test.sql rename to docqueries/alpha_shape/alphashape.pg diff --git a/docqueries/alpha_shape/doc-pgr_alphashape.result b/docqueries/alpha_shape/alphashape.result similarity index 100% rename from docqueries/alpha_shape/doc-pgr_alphashape.result rename to docqueries/alpha_shape/alphashape.result diff --git a/docqueries/alpha_shape/test.conf b/docqueries/alpha_shape/test.conf index b51e6d9b012..228e355b5af 100644 --- a/docqueries/alpha_shape/test.conf +++ b/docqueries/alpha_shape/test.conf @@ -2,18 +2,10 @@ %main::tests = ( 'any' => { - 'comment' => 'AlphaShape documentation queries', - 'data' => [], - 'tests' => [qw( - doc-pgr_alphashape - )], - 'documentation' => [qw( - doc-pgr_alphashape + 'files' => [qw( + alphashape.pg )] }, - # 'vpg-vpgis' => {}, # for version specific tests - # '8-1' => {}, # for pg 8.x and postgis 1.x - # '9.2-2.1' => {}, # for pg 9.2 and postgis 2.1 ); 1; diff --git a/docqueries/astar/CMakeLists.txt b/docqueries/astar/CMakeLists.txt index 702d34add75..e7a4f595029 100644 --- a/docqueries/astar/CMakeLists.txt +++ b/docqueries/astar/CMakeLists.txt @@ -1,8 +1,8 @@ # Do not use extensions SET(LOCAL_FILES - doc-aStarCostMatrix - doc-aStarCost - doc-astar + aStarCostMatrix + aStarCost + astar ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/astar/doc-aStarCost.test.sql b/docqueries/astar/aStarCost.pg similarity index 100% rename from docqueries/astar/doc-aStarCost.test.sql rename to docqueries/astar/aStarCost.pg diff --git a/docqueries/astar/doc-aStarCost.result b/docqueries/astar/aStarCost.result similarity index 100% rename from docqueries/astar/doc-aStarCost.result rename to docqueries/astar/aStarCost.result diff --git a/docqueries/astar/doc-aStarCostMatrix.test.sql b/docqueries/astar/aStarCostMatrix.pg similarity index 100% rename from docqueries/astar/doc-aStarCostMatrix.test.sql rename to docqueries/astar/aStarCostMatrix.pg diff --git a/docqueries/astar/doc-aStarCostMatrix.result b/docqueries/astar/aStarCostMatrix.result similarity index 100% rename from docqueries/astar/doc-aStarCostMatrix.result rename to docqueries/astar/aStarCostMatrix.result diff --git a/docqueries/astar/doc-astar.test.sql b/docqueries/astar/astar.pg similarity index 100% rename from docqueries/astar/doc-astar.test.sql rename to docqueries/astar/astar.pg diff --git a/docqueries/astar/doc-astar.result b/docqueries/astar/astar.result similarity index 100% rename from docqueries/astar/doc-astar.result rename to docqueries/astar/astar.result diff --git a/docqueries/astar/test.conf b/docqueries/astar/test.conf index 5cab28a16b1..0aacac69f5e 100644 --- a/docqueries/astar/test.conf +++ b/docqueries/astar/test.conf @@ -2,22 +2,12 @@ %main::tests = ( 'any' => { - 'comment' => 'astar test for any versions.', - 'data' => [''], - 'tests' => [qw( - doc-astar - doc-aStarCost - doc-aStarCostMatrix - )], - 'documentation' => [qw( - doc-astar - doc-aStarCost - doc-aStarCostMatrix + 'files' => [qw( + astar.pg + aStarCost.pg + aStarCostMatrix.pg )] }, -# 'vpg-vpgis' => {}, # for version specific tests -# '8-1' => {}, # for pg 8.x and postgis 1.x -# '9.2-2.1' => {}, # for pg 9.2 and postgis 2.1 ); 1; diff --git a/docqueries/bdAstar/CMakeLists.txt b/docqueries/bdAstar/CMakeLists.txt index e2cff1ce028..7800b4f2428 100644 --- a/docqueries/bdAstar/CMakeLists.txt +++ b/docqueries/bdAstar/CMakeLists.txt @@ -1,8 +1,8 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_bdAstarCostMatrix - doc-pgr_bdAstarCost - doc-pgr_bdAstar + bdAstarCostMatrix + bdAstarCost + bdAstar ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/bdAstar/doc-pgr_bdAstar.test.sql b/docqueries/bdAstar/bdAstar.pg similarity index 100% rename from docqueries/bdAstar/doc-pgr_bdAstar.test.sql rename to docqueries/bdAstar/bdAstar.pg diff --git a/docqueries/bdAstar/doc-pgr_bdAstar.result b/docqueries/bdAstar/bdAstar.result similarity index 98% rename from docqueries/bdAstar/doc-pgr_bdAstar.result rename to docqueries/bdAstar/bdAstar.result index 046d1d13b1e..8ab9de8c731 100644 --- a/docqueries/bdAstar/doc-pgr_bdAstar.result +++ b/docqueries/bdAstar/bdAstar.result @@ -71,8 +71,8 @@ SELECT * FROM pgr_bdAstar( 5 | 5 | 6 | 10 | 15 | 3 | 1 | 4 6 | 6 | 6 | 10 | 10 | -1 | 0 | 5 7 | 1 | 6 | 12 | 6 | 4 | 1 | 0 - 8 | 2 | 6 | 12 | 7 | 10 | 1 | 1 - 9 | 3 | 6 | 12 | 8 | 12 | 1 | 2 + 8 | 2 | 6 | 12 | 7 | 8 | 1 | 1 + 9 | 3 | 6 | 12 | 11 | 11 | 1 | 2 10 | 4 | 6 | 12 | 12 | -1 | 0 | 3 11 | 1 | 8 | 10 | 8 | 10 | 1 | 0 12 | 2 | 8 | 10 | 7 | 8 | 1 | 1 diff --git a/docqueries/bdAstar/doc-pgr_bdAstarCost.test.sql b/docqueries/bdAstar/bdAstarCost.pg similarity index 100% rename from docqueries/bdAstar/doc-pgr_bdAstarCost.test.sql rename to docqueries/bdAstar/bdAstarCost.pg diff --git a/docqueries/bdAstar/doc-pgr_bdAstarCost.result b/docqueries/bdAstar/bdAstarCost.result similarity index 100% rename from docqueries/bdAstar/doc-pgr_bdAstarCost.result rename to docqueries/bdAstar/bdAstarCost.result diff --git a/docqueries/bdAstar/doc-pgr_bdAstarCostMatrix.test.sql b/docqueries/bdAstar/bdAstarCostMatrix.pg similarity index 100% rename from docqueries/bdAstar/doc-pgr_bdAstarCostMatrix.test.sql rename to docqueries/bdAstar/bdAstarCostMatrix.pg diff --git a/docqueries/bdAstar/doc-pgr_bdAstarCostMatrix.result b/docqueries/bdAstar/bdAstarCostMatrix.result similarity index 100% rename from docqueries/bdAstar/doc-pgr_bdAstarCostMatrix.result rename to docqueries/bdAstar/bdAstarCostMatrix.result diff --git a/docqueries/bdAstar/test.conf b/docqueries/bdAstar/test.conf index 4225cc76ff3..2338200a7b8 100644 --- a/docqueries/bdAstar/test.conf +++ b/docqueries/bdAstar/test.conf @@ -2,17 +2,10 @@ %main::tests = ( 'any' => { - 'comment' => 'pgr_pdAstar (new signature)', - 'data' => [], - 'tests' => [qw( - doc-pgr_bdAstar - doc-pgr_bdAstarCost - doc-pgr_bdAstarCostMatrix - )], - 'documentation' => [qw( - doc-pgr_bdAstar - doc-pgr_bdAstarCost - doc-pgr_bdAstarCostMatrix + 'files' => [qw( + bdAstar.pg + bdAstarCost.pg + bdAstarCostMatrix.pg )] }, ); diff --git a/docqueries/bdDijkstra/CMakeLists.txt b/docqueries/bdDijkstra/CMakeLists.txt index 21ef9f7895f..33ddab1f9f6 100644 --- a/docqueries/bdDijkstra/CMakeLists.txt +++ b/docqueries/bdDijkstra/CMakeLists.txt @@ -1,8 +1,8 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_bdDijkstraCostMatrix - doc-pgr_bdDijkstraCost - doc-pgr_bdDijkstra + bdDijkstraCostMatrix + bdDijkstraCost + bdDijkstra ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/bdDijkstra/bdDijkstra-large.test.sql b/docqueries/bdDijkstra/bdDijkstra-large.pg similarity index 100% rename from docqueries/bdDijkstra/bdDijkstra-large.test.sql rename to docqueries/bdDijkstra/bdDijkstra-large.pg diff --git a/docqueries/bdDijkstra/doc-pgr_bdDijkstra.test.sql b/docqueries/bdDijkstra/bdDijkstra.pg similarity index 100% rename from docqueries/bdDijkstra/doc-pgr_bdDijkstra.test.sql rename to docqueries/bdDijkstra/bdDijkstra.pg diff --git a/docqueries/bdDijkstra/doc-pgr_bdDijkstra.result b/docqueries/bdDijkstra/bdDijkstra.result similarity index 100% rename from docqueries/bdDijkstra/doc-pgr_bdDijkstra.result rename to docqueries/bdDijkstra/bdDijkstra.result diff --git a/docqueries/bdDijkstra/doc-pgr_bdDijkstraCost.test.sql b/docqueries/bdDijkstra/bdDijkstraCost.pg similarity index 100% rename from docqueries/bdDijkstra/doc-pgr_bdDijkstraCost.test.sql rename to docqueries/bdDijkstra/bdDijkstraCost.pg diff --git a/docqueries/bdDijkstra/doc-pgr_bdDijkstraCost.result b/docqueries/bdDijkstra/bdDijkstraCost.result similarity index 100% rename from docqueries/bdDijkstra/doc-pgr_bdDijkstraCost.result rename to docqueries/bdDijkstra/bdDijkstraCost.result diff --git a/docqueries/bdDijkstra/doc-pgr_bdDijkstraCostMatrix.test.sql b/docqueries/bdDijkstra/bdDijkstraCostMatrix.pg similarity index 100% rename from docqueries/bdDijkstra/doc-pgr_bdDijkstraCostMatrix.test.sql rename to docqueries/bdDijkstra/bdDijkstraCostMatrix.pg diff --git a/docqueries/bdDijkstra/doc-pgr_bdDijkstraCostMatrix.result b/docqueries/bdDijkstra/bdDijkstraCostMatrix.result similarity index 100% rename from docqueries/bdDijkstra/doc-pgr_bdDijkstraCostMatrix.result rename to docqueries/bdDijkstra/bdDijkstraCostMatrix.result diff --git a/docqueries/bdDijkstra/test.conf b/docqueries/bdDijkstra/test.conf index fcba6d74bba..2a713d1c3a7 100644 --- a/docqueries/bdDijkstra/test.conf +++ b/docqueries/bdDijkstra/test.conf @@ -2,18 +2,12 @@ %main::tests = ( 'any' => { - 'comment' => 'pgr_pdDijkstra (new signature) old large test', 'data' => ["large.data" ], - 'tests' => [qw( - bdDijkstra-large - doc-pgr_bdDijkstra - doc-pgr_bdDijkstraCost - doc-pgr_bdDijkstraCostMatrix - )], - 'documentation' => [qw( - doc-pgr_bdDijkstra - doc-pgr_bdDijkstraCost - doc-pgr_bdDijkstraCostMatrix + 'files' => [qw( + bdDijkstra-large.pg + bdDijkstra.pg + bdDijkstraCost.pg + bdDijkstraCostMatrix.pg )] }, ); diff --git a/docqueries/bellman_ford/CMakeLists.txt b/docqueries/bellman_ford/CMakeLists.txt index 54f4caec925..0724ab0309f 100644 --- a/docqueries/bellman_ford/CMakeLists.txt +++ b/docqueries/bellman_ford/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_bellmanFord - doc-pgr_edwardMoore + bellmanFord + edwardMoore ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/bellman_ford/doc-pgr_bellmanFord.test.sql b/docqueries/bellman_ford/bellmanFord.pg similarity index 100% rename from docqueries/bellman_ford/doc-pgr_bellmanFord.test.sql rename to docqueries/bellman_ford/bellmanFord.pg diff --git a/docqueries/bellman_ford/doc-pgr_bellmanFord.result b/docqueries/bellman_ford/bellmanFord.result similarity index 100% rename from docqueries/bellman_ford/doc-pgr_bellmanFord.result rename to docqueries/bellman_ford/bellmanFord.result diff --git a/docqueries/bellman_ford/doc-pgr_edwardMoore.test.sql b/docqueries/bellman_ford/edwardMoore.pg similarity index 100% rename from docqueries/bellman_ford/doc-pgr_edwardMoore.test.sql rename to docqueries/bellman_ford/edwardMoore.pg diff --git a/docqueries/bellman_ford/doc-pgr_edwardMoore.result b/docqueries/bellman_ford/edwardMoore.result similarity index 100% rename from docqueries/bellman_ford/doc-pgr_edwardMoore.result rename to docqueries/bellman_ford/edwardMoore.result diff --git a/docqueries/bellman_ford/test.conf b/docqueries/bellman_ford/test.conf index fb75b984dfa..3b5e0985f96 100644 --- a/docqueries/bellman_ford/test.conf +++ b/docqueries/bellman_ford/test.conf @@ -2,15 +2,9 @@ %main::tests = ( 'any' => { - 'comment' => 'Dijkstra test for any versions.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_bellmanFord - doc-pgr_edwardMoore - )], - 'documentation' => [qw( - doc-pgr_bellmanFord - doc-pgr_edwardMoore + 'files' => [qw( + bellmanFord.pg + edwardMoore.pg )] }, diff --git a/docqueries/breadthFirstSearch/CMakeLists.txt b/docqueries/breadthFirstSearch/CMakeLists.txt index cf1ab25dcd5..02c0b95bf60 100644 --- a/docqueries/breadthFirstSearch/CMakeLists.txt +++ b/docqueries/breadthFirstSearch/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_breadthFirstSearch - doc-pgr_binaryBreadthFirstSearch + breadthFirstSearch + binaryBreadthFirstSearch ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/breadthFirstSearch/doc-pgr_binaryBreadthFirstSearch.test.sql b/docqueries/breadthFirstSearch/binaryBreadthFirstSearch.pg similarity index 100% rename from docqueries/breadthFirstSearch/doc-pgr_binaryBreadthFirstSearch.test.sql rename to docqueries/breadthFirstSearch/binaryBreadthFirstSearch.pg diff --git a/docqueries/breadthFirstSearch/doc-pgr_binaryBreadthFirstSearch.result b/docqueries/breadthFirstSearch/binaryBreadthFirstSearch.result similarity index 100% rename from docqueries/breadthFirstSearch/doc-pgr_binaryBreadthFirstSearch.result rename to docqueries/breadthFirstSearch/binaryBreadthFirstSearch.result diff --git a/docqueries/breadthFirstSearch/doc-pgr_breadthFirstSearch.test.sql b/docqueries/breadthFirstSearch/breadthFirstSearch.pg similarity index 100% rename from docqueries/breadthFirstSearch/doc-pgr_breadthFirstSearch.test.sql rename to docqueries/breadthFirstSearch/breadthFirstSearch.pg diff --git a/docqueries/breadthFirstSearch/doc-pgr_breadthFirstSearch.result b/docqueries/breadthFirstSearch/breadthFirstSearch.result similarity index 100% rename from docqueries/breadthFirstSearch/doc-pgr_breadthFirstSearch.result rename to docqueries/breadthFirstSearch/breadthFirstSearch.result diff --git a/docqueries/breadthFirstSearch/test.conf b/docqueries/breadthFirstSearch/test.conf index bb117b0680e..0e358e5a09d 100644 --- a/docqueries/breadthFirstSearch/test.conf +++ b/docqueries/breadthFirstSearch/test.conf @@ -2,15 +2,9 @@ %main::tests = ( 'any' => { - 'comment' => 'Breadth First Search algorithm tests.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_breadthFirstSearch - doc-pgr_binaryBreadthFirstSearch - )], - 'documentation' => [qw( - doc-pgr_breadthFirstSearch - doc-pgr_binaryBreadthFirstSearch + 'files' => [qw( + breadthFirstSearch.pg + binaryBreadthFirstSearch.pg )] }, diff --git a/docqueries/chinese/CMakeLists.txt b/docqueries/chinese/CMakeLists.txt index e80997468f4..9c187a96f19 100644 --- a/docqueries/chinese/CMakeLists.txt +++ b/docqueries/chinese/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_chinesePostmanCost - doc-pgr_chinesePostman + chinesePostmanCost + chinesePostman ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/chinese/doc-pgr_chinesePostman.test.sql b/docqueries/chinese/chinesePostman.pg similarity index 100% rename from docqueries/chinese/doc-pgr_chinesePostman.test.sql rename to docqueries/chinese/chinesePostman.pg diff --git a/docqueries/chinese/doc-pgr_chinesePostman.result b/docqueries/chinese/chinesePostman.result similarity index 100% rename from docqueries/chinese/doc-pgr_chinesePostman.result rename to docqueries/chinese/chinesePostman.result diff --git a/docqueries/chinese/doc-pgr_chinesePostmanCost.test.sql b/docqueries/chinese/chinesePostmanCost.pg similarity index 100% rename from docqueries/chinese/doc-pgr_chinesePostmanCost.test.sql rename to docqueries/chinese/chinesePostmanCost.pg diff --git a/docqueries/chinese/doc-pgr_chinesePostmanCost.result b/docqueries/chinese/chinesePostmanCost.result similarity index 100% rename from docqueries/chinese/doc-pgr_chinesePostmanCost.result rename to docqueries/chinese/chinesePostmanCost.result diff --git a/docqueries/chinese/test.conf b/docqueries/chinese/test.conf index 3f839367c4e..2f6b622a668 100644 --- a/docqueries/chinese/test.conf +++ b/docqueries/chinese/test.conf @@ -2,15 +2,9 @@ %main::tests = ( 'any' => { - 'comment' => 'Directed Chinese Postman Problem test for any versions.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_chinesePostman - doc-pgr_chinesePostmanCost - )], - 'documentation' => [qw( - doc-pgr_chinesePostman - doc-pgr_chinesePostmanCost + 'files' => [qw( + chinesePostman.pg + chinesePostmanCost.pg )] }, diff --git a/docqueries/circuits/hawickCircuits.test.sql b/docqueries/circuits/hawickCircuits.pg similarity index 100% rename from docqueries/circuits/hawickCircuits.test.sql rename to docqueries/circuits/hawickCircuits.pg diff --git a/docqueries/circuits/test.conf b/docqueries/circuits/test.conf index 8d5c0d4e5ff..a128ab4ca6e 100644 --- a/docqueries/circuits/test.conf +++ b/docqueries/circuits/test.conf @@ -2,13 +2,8 @@ %main::tests = ( 'any' => { - 'comment' => 'pgr_hawickCircuits algorithm tests', - 'data' => ["" ], - 'tests' => [qw( - hawickCircuits - )], - 'documentation' => [qw( - hawickCircuits + 'files' => [qw( + hawickCircuits.pg )] }, ); diff --git a/docqueries/coloring/CMakeLists.txt b/docqueries/coloring/CMakeLists.txt index 0fa79dfa0bd..4e67b0b2f4e 100644 --- a/docqueries/coloring/CMakeLists.txt +++ b/docqueries/coloring/CMakeLists.txt @@ -1,8 +1,8 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_sequentialVertexColoring - doc-bipartite - doc-edgeColoring + sequentialVertexColoring + bipartite + edgeColoring ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/coloring/doc-bipartite.test.sql b/docqueries/coloring/bipartite.pg similarity index 100% rename from docqueries/coloring/doc-bipartite.test.sql rename to docqueries/coloring/bipartite.pg diff --git a/docqueries/coloring/doc-bipartite.result b/docqueries/coloring/bipartite.result similarity index 100% rename from docqueries/coloring/doc-bipartite.result rename to docqueries/coloring/bipartite.result diff --git a/docqueries/coloring/doc-edgeColoring.test.sql b/docqueries/coloring/edgeColoring.pg similarity index 100% rename from docqueries/coloring/doc-edgeColoring.test.sql rename to docqueries/coloring/edgeColoring.pg diff --git a/docqueries/coloring/doc-edgeColoring.result b/docqueries/coloring/edgeColoring.result similarity index 100% rename from docqueries/coloring/doc-edgeColoring.result rename to docqueries/coloring/edgeColoring.result diff --git a/docqueries/coloring/doc-pgr_sequentialVertexColoring.test.sql b/docqueries/coloring/sequentialVertexColoring.pg similarity index 100% rename from docqueries/coloring/doc-pgr_sequentialVertexColoring.test.sql rename to docqueries/coloring/sequentialVertexColoring.pg diff --git a/docqueries/coloring/doc-pgr_sequentialVertexColoring.result b/docqueries/coloring/sequentialVertexColoring.result similarity index 100% rename from docqueries/coloring/doc-pgr_sequentialVertexColoring.result rename to docqueries/coloring/sequentialVertexColoring.result diff --git a/docqueries/coloring/test.conf b/docqueries/coloring/test.conf index 4fdc3150e82..f2991ead563 100644 --- a/docqueries/coloring/test.conf +++ b/docqueries/coloring/test.conf @@ -2,17 +2,10 @@ %main::tests = ( 'any' => { - 'comment' => 'Coloring algorithm tests.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_sequentialVertexColoring - doc-bipartite - doc-edgeColoring - )], - 'documentation' => [qw( - doc-pgr_sequentialVertexColoring - doc-bipartite - doc-edgeColoring + 'files' => [qw( + sequentialVertexColoring.pg + bipartite.pg + edgeColoring.pg )] }, diff --git a/docqueries/common/test.conf b/docqueries/common/test.conf index ae4ad12deb6..7eb6a08025f 100644 --- a/docqueries/common/test.conf +++ b/docqueries/common/test.conf @@ -2,22 +2,11 @@ %main::tests = ( 'any' => { - 'comment' => 'pgr_createTopology, pgr_analyzegraph, and pgr_analyzeOneway tests for any versions.', 'data' => ['sampledata.data'], - 'tests' => [qw( - versionless-any-01 + 'files' => [qw( + versionless-any-01.pg )], - - 'documentation' => [qw( - )], - - 'dummyStorage' => [qw( - )] - }, -# 'vpg-vpgis' => {}, # for version specific tests -# '8-1' => {}, # for pg 8.x and postgis 1.x -# '9.2-2.1' => {}, # for pg 9.2 and postgis 2.1 ); 1; diff --git a/docqueries/common/versionless-any-01.test.sql b/docqueries/common/versionless-any-01.pg similarity index 100% rename from docqueries/common/versionless-any-01.test.sql rename to docqueries/common/versionless-any-01.pg diff --git a/docqueries/components/CMakeLists.txt b/docqueries/components/CMakeLists.txt index 52dbe38f146..d21c494aa1b 100644 --- a/docqueries/components/CMakeLists.txt +++ b/docqueries/components/CMakeLists.txt @@ -1,11 +1,11 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_articulationPoints - doc-pgr_biconnectedComponents - doc-pgr_bridges - doc-pgr_connectedComponents - doc-pgr_strongComponents - doc-pgr_makeConnected + articulationPoints + biconnectedComponents + bridges + connectedComponents + strongComponents + makeConnected ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/components/doc-pgr_articulationPoints.test.sql b/docqueries/components/articulationPoints.pg similarity index 100% rename from docqueries/components/doc-pgr_articulationPoints.test.sql rename to docqueries/components/articulationPoints.pg diff --git a/docqueries/components/doc-pgr_articulationPoints.result b/docqueries/components/articulationPoints.result similarity index 100% rename from docqueries/components/doc-pgr_articulationPoints.result rename to docqueries/components/articulationPoints.result diff --git a/docqueries/components/doc-pgr_biconnectedComponents.test.sql b/docqueries/components/biconnectedComponents.pg similarity index 100% rename from docqueries/components/doc-pgr_biconnectedComponents.test.sql rename to docqueries/components/biconnectedComponents.pg diff --git a/docqueries/components/doc-pgr_biconnectedComponents.result b/docqueries/components/biconnectedComponents.result similarity index 100% rename from docqueries/components/doc-pgr_biconnectedComponents.result rename to docqueries/components/biconnectedComponents.result diff --git a/docqueries/components/doc-pgr_bridges.test.sql b/docqueries/components/bridges.pg similarity index 100% rename from docqueries/components/doc-pgr_bridges.test.sql rename to docqueries/components/bridges.pg diff --git a/docqueries/components/doc-pgr_bridges.result b/docqueries/components/bridges.result similarity index 100% rename from docqueries/components/doc-pgr_bridges.result rename to docqueries/components/bridges.result diff --git a/docqueries/components/doc-pgr_connectedComponents.test.sql b/docqueries/components/connectedComponents.pg similarity index 100% rename from docqueries/components/doc-pgr_connectedComponents.test.sql rename to docqueries/components/connectedComponents.pg diff --git a/docqueries/components/doc-pgr_connectedComponents.result b/docqueries/components/connectedComponents.result similarity index 100% rename from docqueries/components/doc-pgr_connectedComponents.result rename to docqueries/components/connectedComponents.result diff --git a/docqueries/components/doc-pgr_makeConnected.test.sql b/docqueries/components/makeConnected.pg similarity index 100% rename from docqueries/components/doc-pgr_makeConnected.test.sql rename to docqueries/components/makeConnected.pg diff --git a/docqueries/components/doc-pgr_makeConnected.result b/docqueries/components/makeConnected.result similarity index 100% rename from docqueries/components/doc-pgr_makeConnected.result rename to docqueries/components/makeConnected.result diff --git a/docqueries/components/doc-pgr_strongComponents.test.sql b/docqueries/components/strongComponents.pg similarity index 100% rename from docqueries/components/doc-pgr_strongComponents.test.sql rename to docqueries/components/strongComponents.pg diff --git a/docqueries/components/doc-pgr_strongComponents.result b/docqueries/components/strongComponents.result similarity index 100% rename from docqueries/components/doc-pgr_strongComponents.result rename to docqueries/components/strongComponents.result diff --git a/docqueries/components/test.conf b/docqueries/components/test.conf index 287a4862f15..cb3b31a57ae 100644 --- a/docqueries/components/test.conf +++ b/docqueries/components/test.conf @@ -2,23 +2,13 @@ %main::tests = ( 'any' => { - 'comment' => 'Components test for any versions.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_connectedComponents - doc-pgr_strongComponents - doc-pgr_biconnectedComponents - doc-pgr_articulationPoints - doc-pgr_bridges - doc-pgr_makeConnected - )], - 'documentation' => [qw( - doc-pgr_connectedComponents - doc-pgr_strongComponents - doc-pgr_biconnectedComponents - doc-pgr_articulationPoints - doc-pgr_bridges - doc-pgr_makeConnected + 'files' => [qw( + connectedComponents.pg + strongComponents.pg + biconnectedComponents.pg + articulationPoints.pg + bridges.pg + makeConnected.pg )] }, diff --git a/docqueries/contraction/CMakeLists.txt b/docqueries/contraction/CMakeLists.txt index 9ba4b3e2457..d640c0ea807 100644 --- a/docqueries/contraction/CMakeLists.txt +++ b/docqueries/contraction/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-contraction-family - doc-pgr_contraction + contraction-family + contraction ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/contraction/doc-contraction-family.test.sql b/docqueries/contraction/contraction-family.pg similarity index 100% rename from docqueries/contraction/doc-contraction-family.test.sql rename to docqueries/contraction/contraction-family.pg diff --git a/docqueries/contraction/doc-contraction-family.result b/docqueries/contraction/contraction-family.result similarity index 100% rename from docqueries/contraction/doc-contraction-family.result rename to docqueries/contraction/contraction-family.result diff --git a/docqueries/contraction/doc-pgr_contraction.test.sql b/docqueries/contraction/contraction.pg similarity index 100% rename from docqueries/contraction/doc-pgr_contraction.test.sql rename to docqueries/contraction/contraction.pg diff --git a/docqueries/contraction/doc-pgr_contraction.result b/docqueries/contraction/contraction.result similarity index 100% rename from docqueries/contraction/doc-pgr_contraction.result rename to docqueries/contraction/contraction.result diff --git a/docqueries/contraction/test.conf b/docqueries/contraction/test.conf index b2aaf02ff3e..bd08f892df0 100644 --- a/docqueries/contraction/test.conf +++ b/docqueries/contraction/test.conf @@ -2,16 +2,9 @@ %main::tests = ( 'any' => { - 'comment' => 'Contraction', - 'data' => [ ], - 'tests' => [qw( - doc-contraction-family - doc-pgr_contraction - )], - - 'documentation' => [qw( - doc-contraction-family - doc-pgr_contraction + 'files' => [qw( + contraction-family.pg + contraction.pg )] }, diff --git a/docqueries/dagShortestPath/CMakeLists.txt b/docqueries/dagShortestPath/CMakeLists.txt index e8a3efdd129..3c14948b6e0 100644 --- a/docqueries/dagShortestPath/CMakeLists.txt +++ b/docqueries/dagShortestPath/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_dagShortestPath + dagShortestPath ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/dagShortestPath/doc-pgr_dagShortestPath.test.sql b/docqueries/dagShortestPath/dagShortestPath.pg similarity index 100% rename from docqueries/dagShortestPath/doc-pgr_dagShortestPath.test.sql rename to docqueries/dagShortestPath/dagShortestPath.pg diff --git a/docqueries/dagShortestPath/doc-pgr_dagShortestPath.result b/docqueries/dagShortestPath/dagShortestPath.result similarity index 100% rename from docqueries/dagShortestPath/doc-pgr_dagShortestPath.result rename to docqueries/dagShortestPath/dagShortestPath.result diff --git a/docqueries/dagShortestPath/test.conf b/docqueries/dagShortestPath/test.conf index 74bcbc9987a..1182f9cfb88 100644 --- a/docqueries/dagShortestPath/test.conf +++ b/docqueries/dagShortestPath/test.conf @@ -2,13 +2,8 @@ %main::tests = ( 'any' => { - 'comment' => 'pgr_dagShortestPath', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_dagShortestPath - )], - 'documentation' => [qw( - doc-pgr_dagShortestPath + 'files' => [qw( + dagShortestPath.pg )] }, diff --git a/docqueries/dijkstra/CMakeLists.txt b/docqueries/dijkstra/CMakeLists.txt index b32b909c252..90b64c6c333 100644 --- a/docqueries/dijkstra/CMakeLists.txt +++ b/docqueries/dijkstra/CMakeLists.txt @@ -1,11 +1,11 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_dijkstraCostMatrix - doc-pgr_dijkstraCost - doc-pgr_dijkstra - doc-pgr_dijkstraVia - doc-pgr_dijkstraNear - doc-pgr_dijkstraNearCost + dijkstraCostMatrix + dijkstraCost + dijkstra + dijkstraVia + dijkstraNear + dijkstraNearCost ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/dijkstra/doc-pgr_dijkstra.test.sql b/docqueries/dijkstra/dijkstra.pg similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstra.test.sql rename to docqueries/dijkstra/dijkstra.pg diff --git a/docqueries/dijkstra/doc-pgr_dijkstra.result b/docqueries/dijkstra/dijkstra.result similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstra.result rename to docqueries/dijkstra/dijkstra.result diff --git a/docqueries/dijkstra/doc-pgr_dijkstraCost.test.sql b/docqueries/dijkstra/dijkstraCost.pg similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraCost.test.sql rename to docqueries/dijkstra/dijkstraCost.pg diff --git a/docqueries/dijkstra/doc-pgr_dijkstraCost.result b/docqueries/dijkstra/dijkstraCost.result similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraCost.result rename to docqueries/dijkstra/dijkstraCost.result diff --git a/docqueries/dijkstra/doc-pgr_dijkstraCostMatrix.test.sql b/docqueries/dijkstra/dijkstraCostMatrix.pg similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraCostMatrix.test.sql rename to docqueries/dijkstra/dijkstraCostMatrix.pg diff --git a/docqueries/dijkstra/doc-pgr_dijkstraCostMatrix.result b/docqueries/dijkstra/dijkstraCostMatrix.result similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraCostMatrix.result rename to docqueries/dijkstra/dijkstraCostMatrix.result diff --git a/docqueries/dijkstra/doc-pgr_dijkstraNear.test.sql b/docqueries/dijkstra/dijkstraNear.pg similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraNear.test.sql rename to docqueries/dijkstra/dijkstraNear.pg diff --git a/docqueries/dijkstra/doc-pgr_dijkstraNear.result b/docqueries/dijkstra/dijkstraNear.result similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraNear.result rename to docqueries/dijkstra/dijkstraNear.result diff --git a/docqueries/dijkstra/doc-pgr_dijkstraNearCost.test.sql b/docqueries/dijkstra/dijkstraNearCost.pg similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraNearCost.test.sql rename to docqueries/dijkstra/dijkstraNearCost.pg diff --git a/docqueries/dijkstra/doc-pgr_dijkstraNearCost.result b/docqueries/dijkstra/dijkstraNearCost.result similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraNearCost.result rename to docqueries/dijkstra/dijkstraNearCost.result diff --git a/docqueries/dijkstra/doc-pgr_dijkstraVia.test.sql b/docqueries/dijkstra/dijkstraVia.pg similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraVia.test.sql rename to docqueries/dijkstra/dijkstraVia.pg diff --git a/docqueries/dijkstra/doc-pgr_dijkstraVia.result b/docqueries/dijkstra/dijkstraVia.result similarity index 100% rename from docqueries/dijkstra/doc-pgr_dijkstraVia.result rename to docqueries/dijkstra/dijkstraVia.result diff --git a/docqueries/dijkstra/test.conf b/docqueries/dijkstra/test.conf index 16222ee3588..9a020d62032 100644 --- a/docqueries/dijkstra/test.conf +++ b/docqueries/dijkstra/test.conf @@ -2,25 +2,13 @@ %main::tests = ( 'any' => { - 'comment' => 'Dijkstra test for any versions.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_dijkstra - doc-pgr_dijkstraVia - doc-pgr_dijkstraCost - doc-pgr_dijkstraCostMatrix - doc-pgr_dijkstraNear - doc-pgr_dijkstraNearCost - )], - 'documentation' => [qw( - doc-pgr_dijkstra - doc-pgr_dijkstraVia - doc-pgr_dijkstraCost - doc-pgr_dijkstraCostMatrix - doc-pgr_dijkstraNear - doc-pgr_dijkstraNearCost - )] - ,'notests' => [qw( + 'files' => [qw( + dijkstra.pg + dijkstraVia.pg + dijkstraCost.pg + dijkstraCostMatrix.pg + dijkstraNear.pg + dijkstraNearCost.pg )] }, ); diff --git a/docqueries/dominator/CMakeLists.txt b/docqueries/dominator/CMakeLists.txt index e8a7f6e4ec2..9def4ce4bcd 100644 --- a/docqueries/dominator/CMakeLists.txt +++ b/docqueries/dominator/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - doc-lengauerTarjanDominatorTree + lengauerTarjanDominatorTree ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/dominator/doc-lengauerTarjanDominatorTree.test.sql b/docqueries/dominator/lengauerTarjanDominatorTree.pg similarity index 100% rename from docqueries/dominator/doc-lengauerTarjanDominatorTree.test.sql rename to docqueries/dominator/lengauerTarjanDominatorTree.pg diff --git a/docqueries/dominator/doc-lengauerTarjanDominatorTree.result b/docqueries/dominator/lengauerTarjanDominatorTree.result similarity index 100% rename from docqueries/dominator/doc-lengauerTarjanDominatorTree.result rename to docqueries/dominator/lengauerTarjanDominatorTree.result diff --git a/docqueries/dominator/test.conf b/docqueries/dominator/test.conf index 79b4135f1dc..4553a9865e6 100644 --- a/docqueries/dominator/test.conf +++ b/docqueries/dominator/test.conf @@ -2,13 +2,8 @@ %main::tests = ( 'any' => { - 'comment' => 'dominator algorithm tests', - 'data' => [ ], - 'tests' => [qw( - doc-lengauerTarjanDominatorTree - )], - 'documentation' => [qw( - doc-lengauerTarjanDominatorTree + 'files' => [qw( + lengauerTarjanDominatorTree.pg )] }, diff --git a/docqueries/driving_distance/CMakeLists.txt b/docqueries/driving_distance/CMakeLists.txt index bc221d84afc..a570865c484 100644 --- a/docqueries/driving_distance/CMakeLists.txt +++ b/docqueries/driving_distance/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - pgr_drivingDistance + drivingDistance ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/driving_distance/dijksraDD-issue729.test.sql b/docqueries/driving_distance/dijksraDD-issue729.pg similarity index 100% rename from docqueries/driving_distance/dijksraDD-issue729.test.sql rename to docqueries/driving_distance/dijksraDD-issue729.pg diff --git a/docqueries/driving_distance/pgr_drivingDistance.test.sql b/docqueries/driving_distance/drivingDistance.pg similarity index 100% rename from docqueries/driving_distance/pgr_drivingDistance.test.sql rename to docqueries/driving_distance/drivingDistance.pg diff --git a/docqueries/driving_distance/pgr_drivingDistance.result b/docqueries/driving_distance/drivingDistance.result similarity index 100% rename from docqueries/driving_distance/pgr_drivingDistance.result rename to docqueries/driving_distance/drivingDistance.result diff --git a/docqueries/driving_distance/test.conf b/docqueries/driving_distance/test.conf index 121bb24a9e6..b9770391bd4 100644 --- a/docqueries/driving_distance/test.conf +++ b/docqueries/driving_distance/test.conf @@ -2,19 +2,11 @@ %main::tests = ( 'any' => { - 'comment' => 'Driving Distance test for any versions.', - 'data' => [], - 'tests' => [qw( - pgr_drivingDistance - dijksraDD-issue729 - )], - 'documentation' => [qw( - pgr_drivingDistance + 'files' => [qw( + drivingDistance.pg + dijksraDD-issue729.pg )] }, -# 'vpg-vpgis' => {}, # for version specific tests -# '8-1' => {}, # for pg 8.x and postgis 1.x -# '9.2-2.1' => {}, # for pg 9.2 and postgis 2.1 ); 1; diff --git a/docqueries/ksp/CMakeLists.txt b/docqueries/ksp/CMakeLists.txt index 94d9b6aa789..3922d10d594 100644 --- a/docqueries/ksp/CMakeLists.txt +++ b/docqueries/ksp/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-ksp - doc-pgr_turnRestrictedPath + ksp + turnRestrictedPath ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/ksp/doc-ksp.test.sql b/docqueries/ksp/ksp.pg similarity index 100% rename from docqueries/ksp/doc-ksp.test.sql rename to docqueries/ksp/ksp.pg diff --git a/docqueries/ksp/doc-ksp.result b/docqueries/ksp/ksp.result similarity index 100% rename from docqueries/ksp/doc-ksp.result rename to docqueries/ksp/ksp.result diff --git a/docqueries/ksp/test.conf b/docqueries/ksp/test.conf index f4cbb10ed19..a7597f52103 100644 --- a/docqueries/ksp/test.conf +++ b/docqueries/ksp/test.conf @@ -2,15 +2,9 @@ %main::tests = ( 'any' => { - 'comment' => 'KSP', - 'data' => [''], - 'tests' => [qw( - doc-ksp - doc-pgr_turnRestrictedPath - )], - 'documentation' => [qw( - doc-ksp - doc-pgr_turnRestrictedPath + 'files' => [qw( + ksp.pg + turnRestrictedPath.pg )] }, diff --git a/docqueries/ksp/doc-pgr_turnRestrictedPath.test.sql b/docqueries/ksp/turnRestrictedPath.pg similarity index 100% rename from docqueries/ksp/doc-pgr_turnRestrictedPath.test.sql rename to docqueries/ksp/turnRestrictedPath.pg diff --git a/docqueries/ksp/doc-pgr_turnRestrictedPath.result b/docqueries/ksp/turnRestrictedPath.result similarity index 100% rename from docqueries/ksp/doc-pgr_turnRestrictedPath.result rename to docqueries/ksp/turnRestrictedPath.result diff --git a/docqueries/lineGraph/CMakeLists.txt b/docqueries/lineGraph/CMakeLists.txt index 49d3d58ac9b..1e52b109cc0 100644 --- a/docqueries/lineGraph/CMakeLists.txt +++ b/docqueries/lineGraph/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_lineGraphFull - doc-pgr_lineGraph + lineGraphFull + lineGraph ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/lineGraph/doc-pgr_lineGraph.result b/docqueries/lineGraph/doc-pgr_lineGraph.result deleted file mode 100644 index 6093f485d5d..00000000000 --- a/docqueries/lineGraph/doc-pgr_lineGraph.result +++ /dev/null @@ -1,55 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -/* -- q1 */ -SELECT * FROM pgr_lineGraph( - 'SELECT id, source, target, cost, reverse_cost FROM edges' -); - seq | source | target | cost | reverse_cost ------+--------+--------+------+-------------- - 1 | -18 | 18 | 1 | 1 - 2 | -17 | 17 | 1 | 1 - 3 | -16 | -3 | 1 | -1 - 4 | -14 | -10 | 1 | 1 - 5 | -14 | 12 | 1 | -1 - 6 | -14 | 14 | 1 | 1 - 7 | -10 | -7 | 1 | 1 - 8 | -10 | -4 | 1 | 1 - 9 | -10 | 8 | 1 | 1 - 10 | -10 | 10 | 1 | 1 - 11 | -9 | -8 | 1 | 1 - 12 | -9 | 9 | 1 | 1 - 13 | -9 | 11 | 1 | -1 - 14 | -8 | -7 | 1 | 1 - 15 | -8 | -4 | 1 | 1 - 16 | -8 | 8 | 1 | 1 - 17 | -7 | -6 | 1 | 1 - 18 | -7 | 7 | 1 | 1 - 19 | -6 | 6 | 1 | 1 - 20 | -3 | -2 | 1 | -1 - 21 | -3 | 5 | 1 | -1 - 22 | -2 | -1 | 1 | -1 - 23 | -2 | 4 | 1 | -1 - 24 | 1 | -1 | 1 | 1 - 25 | 1 | 4 | 1 | 1 - 26 | 4 | -7 | 1 | 1 - 27 | 4 | -4 | 1 | 1 - 28 | 5 | -8 | 1 | -1 - 29 | 5 | 9 | 1 | -1 - 30 | 5 | 11 | 1 | -1 - 31 | 8 | 11 | 1 | -1 - 32 | 9 | -16 | 1 | 1 - 33 | 9 | 15 | 1 | 1 - 34 | 10 | 12 | 1 | -1 - 35 | 11 | 13 | 1 | -1 - 36 | 12 | 13 | 1 | -1 - 37 | 13 | -15 | 1 | -1 - 38 | 15 | -15 | 1 | 1 - 39 | 16 | -16 | 1 | 1 - 40 | 16 | 15 | 1 | 1 -(40 rows) - -/* -- q2 */ -ROLLBACK; -ROLLBACK diff --git a/docqueries/lineGraph/lineGraph.pg b/docqueries/lineGraph/lineGraph.pg new file mode 100644 index 00000000000..551382e7c51 --- /dev/null +++ b/docqueries/lineGraph/lineGraph.pg @@ -0,0 +1,51 @@ +-- CopyRight(c) pgRouting developers +-- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/ +/* -- q1 */ +SELECT * FROM pgr_lineGraph( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id IN (2,4,5,8)', + false); +/* -- q2 */ +CREATE TABLE edges_shared ( + id BIGINT, + source BIGINT, + target BIGINT, + cost FLOAT, + reverse_cost FLOAT, + geom geometry +); + +INSERT INTO edges_shared (id, source, target, cost, reverse_cost, geom) VALUES + (102, 1, 2, 1, -1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(2, 2))), + (104, 1, 4, 1, -1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(0, 0))), + (301, 3, 1, 1, -1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 2))), + (203, 2, 3, 1, 1, ST_MakeLine(ST_POINT(2, 2), ST_POINT(2, 0))), + (304, 3, 4, 1, 1, ST_MakeLine(ST_POINT(0, 0), ST_POINT(2, 0))); + +SELECT seq, source, target, cost, reverse_cost +FROM pgr_lineGraph( + 'SELECT id, source, target, cost, reverse_cost FROM edges_shared', + true); +/* -- q3 */ +CREATE TABLE edges_unique ( + id BIGINT, + source BIGINT, + target BIGINT, + cost FLOAT, + geom geometry +); + +INSERT INTO edges_unique (id, source, target, cost, geom) VALUES + (102, 1, 2, 1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(2, 2))), + (104, 1, 4, 1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(0, 0))), + (301, 3, 1, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 2))), + (203, 2, 3, 1, ST_MakeLine(ST_POINT(2, 2), ST_POINT(2, 0))), + (304, 3, 4, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 0))), + (302, 3, 2, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(2, 2))), + (403, 4, 3, 1, ST_MakeLine(ST_POINT(0, 0), ST_POINT(2, 0))); + +SELECT seq, source, target, cost, reverse_cost +FROM pgr_lineGraph( + 'SELECT id, source, target, cost FROM edges_unique', + true); +/* -- q4 */ diff --git a/docqueries/lineGraph/lineGraph.result b/docqueries/lineGraph/lineGraph.result new file mode 100644 index 00000000000..ff183405aef --- /dev/null +++ b/docqueries/lineGraph/lineGraph.result @@ -0,0 +1,90 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * FROM pgr_lineGraph( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id IN (2,4,5,8)', + false); + seq | source | target | cost | reverse_cost +-----+--------+--------+------+-------------- + 1 | 2 | 4 | 1 | -1 + 2 | 2 | 5 | 1 | -1 + 3 | 4 | 8 | 1 | -1 + 4 | 5 | 8 | 1 | -1 +(4 rows) + +/* -- q2 */ +CREATE TABLE edges_shared ( + id BIGINT, + source BIGINT, + target BIGINT, + cost FLOAT, + reverse_cost FLOAT, + geom geometry +); +CREATE TABLE +INSERT INTO edges_shared (id, source, target, cost, reverse_cost, geom) VALUES + (102, 1, 2, 1, -1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(2, 2))), + (104, 1, 4, 1, -1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(0, 0))), + (301, 3, 1, 1, -1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 2))), + (203, 2, 3, 1, 1, ST_MakeLine(ST_POINT(2, 2), ST_POINT(2, 0))), + (304, 3, 4, 1, 1, ST_MakeLine(ST_POINT(0, 0), ST_POINT(2, 0))); +INSERT 0 5 +SELECT seq, source, target, cost, reverse_cost +FROM pgr_lineGraph( + 'SELECT id, source, target, cost, reverse_cost FROM edges_shared', + true); + seq | source | target | cost | reverse_cost +-----+--------+--------+------+-------------- + 1 | 102 | 203 | 1 | -1 + 2 | 104 | 304 | 1 | -1 + 3 | 203 | 203 | 1 | 1 + 4 | 203 | 301 | 1 | -1 + 5 | 203 | 304 | 1 | 1 + 6 | 301 | 102 | 1 | -1 + 7 | 301 | 104 | 1 | -1 + 8 | 304 | 301 | 1 | -1 + 9 | 304 | 304 | 1 | 1 +(9 rows) + +/* -- q3 */ +CREATE TABLE edges_unique ( + id BIGINT, + source BIGINT, + target BIGINT, + cost FLOAT, + geom geometry +); +CREATE TABLE +INSERT INTO edges_unique (id, source, target, cost, geom) VALUES + (102, 1, 2, 1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(2, 2))), + (104, 1, 4, 1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(0, 0))), + (301, 3, 1, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 2))), + (203, 2, 3, 1, ST_MakeLine(ST_POINT(2, 2), ST_POINT(2, 0))), + (304, 3, 4, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 0))), + (302, 3, 2, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(2, 2))), + (403, 4, 3, 1, ST_MakeLine(ST_POINT(0, 0), ST_POINT(2, 0))); +INSERT 0 7 +SELECT seq, source, target, cost, reverse_cost +FROM pgr_lineGraph( + 'SELECT id, source, target, cost FROM edges_unique', + true); + seq | source | target | cost | reverse_cost +-----+--------+--------+------+-------------- + 1 | 102 | 203 | 1 | -1 + 2 | 104 | 403 | 1 | -1 + 3 | 203 | 301 | 1 | -1 + 4 | 203 | 304 | 1 | -1 + 5 | 301 | 102 | 1 | -1 + 6 | 301 | 104 | 1 | -1 + 7 | 302 | 203 | 1 | 1 + 8 | 304 | 403 | 1 | 1 + 9 | 403 | 301 | 1 | -1 + 10 | 403 | 302 | 1 | -1 +(10 rows) + +/* -- q4 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/lineGraph/doc-pgr_lineGraphFull.test.sql b/docqueries/lineGraph/lineGraphFull.pg similarity index 100% rename from docqueries/lineGraph/doc-pgr_lineGraphFull.test.sql rename to docqueries/lineGraph/lineGraphFull.pg diff --git a/docqueries/lineGraph/doc-pgr_lineGraphFull.result b/docqueries/lineGraph/lineGraphFull.result similarity index 100% rename from docqueries/lineGraph/doc-pgr_lineGraphFull.result rename to docqueries/lineGraph/lineGraphFull.result diff --git a/docqueries/lineGraph/pgtap_design.result b/docqueries/lineGraph/pgtap_design.result deleted file mode 100644 index 2f8d738698e..00000000000 --- a/docqueries/lineGraph/pgtap_design.result +++ /dev/null @@ -1,58 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -/* -- one edge graph */ -SELECT * FROM pgr_lineGraph( - 'SELECT id, source, target, cost FROM edges WHERE id = 1' -); -NOTICE: Only vertices graph -HINT: 0: out_edges_of(5): 1=(5, 6) = 1 -1: out_edges_of(6): - - - seq | source | target | cost | reverse_cost ------+--------+--------+------+-------------- -(0 rows) - -/* -- two edge graphs */ -SELECT * FROM pgr_lineGraph($$ - SELECT -id AS id, target, source, reverse_cost AS cost FROM edges WHERE id = 1 - UNION - SELECT id, source, target, cost FROM edges WHERE id = 1 - $$ -); - seq | source | target | cost | reverse_cost ------+--------+--------+------+-------------- - 1 | 1 | -1 | 1 | 1 -(1 row) - -SELECT * FROM pgr_lineGraph($$ - SELECT id, target, source, reverse_cost AS cost FROM edges WHERE id = 1 - UNION - SELECT -id AS id, source, target, cost FROM edges WHERE id = 1 - $$ -); - seq | source | target | cost | reverse_cost ------+--------+--------+------+-------------- - 1 | 1 | -1 | 1 | 1 -(1 row) - -SELECT * FROM pgr_lineGraph( - 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id = 1' -); - seq | source | target | cost | reverse_cost ------+--------+--------+------+-------------- - 1 | -1 | 1 | 1 | 1 -(1 row) - -SELECT * FROM pgr_lineGraph( - 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id = 17' -); - seq | source | target | cost | reverse_cost ------+--------+--------+------+-------------- - 1 | -17 | 17 | 1 | 1 -(1 row) - -ROLLBACK; -ROLLBACK diff --git a/docqueries/lineGraph/pgtap_design.test.sql b/docqueries/lineGraph/pgtap_design.test.sql deleted file mode 100644 index 923163d590d..00000000000 --- a/docqueries/lineGraph/pgtap_design.test.sql +++ /dev/null @@ -1,29 +0,0 @@ --- CopyRight(c) pgRouting developers --- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/ --- TODO move to pgtap - -/* -- one edge graph */ -SELECT * FROM pgr_lineGraph( - 'SELECT id, source, target, cost FROM edges WHERE id = 1' -); - -/* -- two edge graphs */ -SELECT * FROM pgr_lineGraph($$ - SELECT -id AS id, target, source, reverse_cost AS cost FROM edges WHERE id = 1 - UNION - SELECT id, source, target, cost FROM edges WHERE id = 1 - $$ -); -SELECT * FROM pgr_lineGraph($$ - SELECT id, target, source, reverse_cost AS cost FROM edges WHERE id = 1 - UNION - SELECT -id AS id, source, target, cost FROM edges WHERE id = 1 - $$ -); -SELECT * FROM pgr_lineGraph( - 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id = 1' -); -SELECT * FROM pgr_lineGraph( - 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id = 17' -); - diff --git a/docqueries/lineGraph/pgtap_design_lineGraphFull.test.sql b/docqueries/lineGraph/pgtap_design_lineGraphFull.pg similarity index 100% rename from docqueries/lineGraph/pgtap_design_lineGraphFull.test.sql rename to docqueries/lineGraph/pgtap_design_lineGraphFull.pg diff --git a/docqueries/lineGraph/pgtap_design_lineGraphFull.result b/docqueries/lineGraph/pgtap_design_lineGraphFull.result index 8041fb4d26a..0085f595f0f 100644 --- a/docqueries/lineGraph/pgtap_design_lineGraphFull.result +++ b/docqueries/lineGraph/pgtap_design_lineGraphFull.result @@ -54,6 +54,8 @@ SELECT id FROM vertices; SELECT * FROM pgr_lineGraphFull( $$SELECT id, source, target, cost FROM edges WHERE id = 1$$ ); +NOTICE: No edges found +HINT: SELECT id, source, target, cost FROM edges WHERE id = 1 seq | source | target | cost | edge -----+--------+--------+------+------ (0 rows) diff --git a/docqueries/lineGraph/proofOfConcept1.test.sql b/docqueries/lineGraph/proofOfConcept1.pg similarity index 100% rename from docqueries/lineGraph/proofOfConcept1.test.sql rename to docqueries/lineGraph/proofOfConcept1.pg diff --git a/docqueries/lineGraph/proofOfConcept2.test.sql b/docqueries/lineGraph/proofOfConcept2.pg similarity index 100% rename from docqueries/lineGraph/proofOfConcept2.test.sql rename to docqueries/lineGraph/proofOfConcept2.pg diff --git a/docqueries/lineGraph/test.conf b/docqueries/lineGraph/test.conf index e587df42583..6f7757901d6 100644 --- a/docqueries/lineGraph/test.conf +++ b/docqueries/lineGraph/test.conf @@ -2,22 +2,14 @@ %main::tests = ( 'any' => { - 'comment' => 'LineGrpah test for any versions.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_lineGraphFull - doc-pgr_lineGraph - pgtap_design_lineGraphFull - pgtap_design - proofOfConcept1 - proofOfConcept2 + 'files' => [qw( + lineGraphFull.pg + lineGraph.pg + pgtap_design_lineGraphFull.pg + proofOfConcept1.pg + proofOfConcept2.pg )], - 'documentation' => [qw( - doc-pgr_lineGraphFull - doc-pgr_lineGraph - )] }, - ); 1; diff --git a/docqueries/max_flow/CMakeLists.txt b/docqueries/max_flow/CMakeLists.txt index c105b3fc238..ac285200d07 100644 --- a/docqueries/max_flow/CMakeLists.txt +++ b/docqueries/max_flow/CMakeLists.txt @@ -1,13 +1,13 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_boykovKolmogorov - doc-pgr_edgeDisjointPaths - doc-pgr_edmondsKarp - doc-pgr_maxCardinalityMatch - doc-pgr_maxFlow - doc-pgr_pushRelabel - doc-pgr_maxFlowMinCost - doc-pgr_maxFlowMinCost_Cost + boykovKolmogorov + edgeDisjointPaths + edmondsKarp + maxCardinalityMatch + maxFlow + pushRelabel + maxFlowMinCost + maxFlowMinCost_Cost ) diff --git a/docqueries/max_flow/doc-pgr_boykovKolmogorov.test.sql b/docqueries/max_flow/boykovKolmogorov.pg similarity index 100% rename from docqueries/max_flow/doc-pgr_boykovKolmogorov.test.sql rename to docqueries/max_flow/boykovKolmogorov.pg diff --git a/docqueries/max_flow/doc-pgr_boykovKolmogorov.result b/docqueries/max_flow/boykovKolmogorov.result similarity index 100% rename from docqueries/max_flow/doc-pgr_boykovKolmogorov.result rename to docqueries/max_flow/boykovKolmogorov.result diff --git a/docqueries/max_flow/doc-pgr_edgeDisjointPaths.test.sql b/docqueries/max_flow/edgeDisjointPaths.pg similarity index 100% rename from docqueries/max_flow/doc-pgr_edgeDisjointPaths.test.sql rename to docqueries/max_flow/edgeDisjointPaths.pg diff --git a/docqueries/max_flow/doc-pgr_edgeDisjointPaths.result b/docqueries/max_flow/edgeDisjointPaths.result similarity index 87% rename from docqueries/max_flow/doc-pgr_edgeDisjointPaths.result rename to docqueries/max_flow/edgeDisjointPaths.result index 520a08a30a2..7fbb762a495 100644 --- a/docqueries/max_flow/doc-pgr_edgeDisjointPaths.result +++ b/docqueries/max_flow/edgeDisjointPaths.result @@ -9,12 +9,12 @@ SELECT * FROM pgr_edgeDisjointPaths( 11, 12); seq | path_id | path_seq | node | edge | cost | agg_cost -----+---------+----------+------+------+------+---------- - 1 | 1 | 1 | 11 | 8 | 1 | 1 - 2 | 1 | 2 | 7 | 10 | 1 | 2 - 3 | 1 | 3 | 8 | 12 | 1 | 3 - 4 | 1 | 4 | 12 | -1 | 0 | 4 - 5 | 2 | 1 | 11 | 11 | 1 | 4 - 6 | 2 | 2 | 12 | -1 | 0 | 5 + 1 | 1 | 1 | 11 | 8 | 1 | 0 + 2 | 1 | 2 | 7 | 10 | 1 | 1 + 3 | 1 | 3 | 8 | 12 | 1 | 2 + 4 | 1 | 4 | 12 | -1 | 0 | 3 + 5 | 2 | 1 | 11 | 11 | 1 | 0 + 6 | 2 | 2 | 12 | -1 | 0 | 1 (6 rows) /* -- q2 */ @@ -24,20 +24,20 @@ SELECT * FROM pgr_edgeDisjointPaths( 11, ARRAY[5, 10, 12]); seq | path_id | path_seq | end_vid | node | edge | cost | agg_cost -----+---------+----------+---------+------+------+------+---------- - 1 | 1 | 1 | 5 | 11 | 8 | 1 | 1 - 2 | 1 | 2 | 5 | 7 | 4 | 1 | 2 - 3 | 1 | 3 | 5 | 6 | 1 | 1 | 3 - 4 | 1 | 4 | 5 | 5 | -1 | 0 | 4 - 5 | 2 | 1 | 10 | 11 | 9 | 1 | 4 - 6 | 2 | 2 | 10 | 16 | 16 | 1 | 5 - 7 | 2 | 3 | 10 | 15 | 3 | 1 | 6 - 8 | 2 | 4 | 10 | 10 | -1 | 0 | 7 - 9 | 3 | 1 | 12 | 11 | 8 | 1 | 7 - 10 | 3 | 2 | 12 | 7 | 10 | 1 | 8 - 11 | 3 | 3 | 12 | 8 | 12 | 1 | 9 - 12 | 3 | 4 | 12 | 12 | -1 | 0 | 10 - 13 | 4 | 1 | 12 | 11 | 11 | 1 | 10 - 14 | 4 | 2 | 12 | 12 | -1 | 0 | 11 + 1 | 1 | 1 | 5 | 11 | 8 | 1 | 0 + 2 | 1 | 2 | 5 | 7 | 4 | 1 | 1 + 3 | 1 | 3 | 5 | 6 | 1 | 1 | 2 + 4 | 1 | 4 | 5 | 5 | -1 | 0 | 3 + 5 | 2 | 1 | 10 | 11 | 9 | 1 | 0 + 6 | 2 | 2 | 10 | 16 | 16 | 1 | 1 + 7 | 2 | 3 | 10 | 15 | 3 | 1 | 2 + 8 | 2 | 4 | 10 | 10 | -1 | 0 | 3 + 9 | 3 | 1 | 12 | 11 | 8 | 1 | 0 + 10 | 3 | 2 | 12 | 7 | 10 | 1 | 1 + 11 | 3 | 3 | 12 | 8 | 12 | 1 | 2 + 12 | 3 | 4 | 12 | 12 | -1 | 0 | 3 + 13 | 4 | 1 | 12 | 11 | 11 | 1 | 0 + 14 | 4 | 2 | 12 | 12 | -1 | 0 | 1 (14 rows) /* -- q3 */ @@ -47,20 +47,20 @@ SELECT * FROM pgr_edgeDisjointPaths( ARRAY[11, 3, 17], 12); seq | path_id | path_seq | start_vid | node | edge | cost | agg_cost -----+---------+----------+-----------+------+------+------+---------- - 1 | 1 | 1 | 3 | 3 | 7 | 1 | 1 - 2 | 1 | 2 | 3 | 7 | 8 | 1 | 2 - 3 | 1 | 3 | 3 | 11 | 11 | 1 | 3 - 4 | 1 | 4 | 3 | 12 | -1 | 0 | 4 - 5 | 2 | 1 | 11 | 11 | 8 | 1 | 4 - 6 | 2 | 2 | 11 | 7 | 10 | 1 | 5 - 7 | 2 | 3 | 11 | 8 | 12 | 1 | 6 - 8 | 2 | 4 | 11 | 12 | -1 | 0 | 7 - 9 | 3 | 1 | 11 | 11 | 11 | 1 | 7 - 10 | 3 | 2 | 11 | 12 | -1 | 0 | 8 - 11 | 4 | 1 | 17 | 17 | 15 | 1 | 8 - 12 | 4 | 2 | 17 | 16 | 9 | 1 | 9 - 13 | 4 | 3 | 17 | 11 | 11 | 1 | 10 - 14 | 4 | 4 | 17 | 12 | -1 | 0 | 11 + 1 | 1 | 1 | 3 | 3 | 7 | 1 | 0 + 2 | 1 | 2 | 3 | 7 | 8 | 1 | 1 + 3 | 1 | 3 | 3 | 11 | 11 | 1 | 2 + 4 | 1 | 4 | 3 | 12 | -1 | 0 | 3 + 5 | 2 | 1 | 11 | 11 | 8 | 1 | 0 + 6 | 2 | 2 | 11 | 7 | 10 | 1 | 1 + 7 | 2 | 3 | 11 | 8 | 12 | 1 | 2 + 8 | 2 | 4 | 11 | 12 | -1 | 0 | 3 + 9 | 3 | 1 | 11 | 11 | 11 | 1 | 0 + 10 | 3 | 2 | 11 | 12 | -1 | 0 | 1 + 11 | 4 | 1 | 17 | 17 | 15 | 1 | 0 + 12 | 4 | 2 | 17 | 16 | 9 | 1 | 1 + 13 | 4 | 3 | 17 | 11 | 11 | 1 | 2 + 14 | 4 | 4 | 17 | 12 | -1 | 0 | 3 (14 rows) /* -- q4 */ @@ -70,48 +70,48 @@ SELECT * FROM pgr_edgeDisjointPaths( ARRAY[11, 3, 17], ARRAY[5, 10, 12]); seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost -----+---------+----------+-----------+---------+------+------+------+---------- - 1 | 1 | 1 | 3 | 5 | 3 | 7 | 1 | 1 - 2 | 1 | 2 | 3 | 5 | 7 | 4 | 1 | 2 - 3 | 1 | 3 | 3 | 5 | 6 | 1 | 1 | 3 - 4 | 1 | 4 | 3 | 5 | 5 | -1 | 0 | 4 - 5 | 2 | 1 | 3 | 10 | 3 | 7 | 1 | 4 - 6 | 2 | 2 | 3 | 10 | 7 | 8 | 1 | 5 - 7 | 2 | 3 | 3 | 10 | 11 | 9 | 1 | 6 - 8 | 2 | 4 | 3 | 10 | 16 | 16 | 1 | 7 - 9 | 2 | 5 | 3 | 10 | 15 | 3 | 1 | 8 - 10 | 2 | 6 | 3 | 10 | 10 | -1 | 0 | 9 - 11 | 3 | 1 | 3 | 12 | 3 | 7 | 1 | 9 - 12 | 3 | 2 | 3 | 12 | 7 | 8 | 1 | 10 - 13 | 3 | 3 | 3 | 12 | 11 | 11 | 1 | 11 - 14 | 3 | 4 | 3 | 12 | 12 | -1 | 0 | 12 - 15 | 4 | 1 | 11 | 5 | 11 | 8 | 1 | 12 - 16 | 4 | 2 | 11 | 5 | 7 | 4 | 1 | 13 - 17 | 4 | 3 | 11 | 5 | 6 | 1 | 1 | 14 - 18 | 4 | 4 | 11 | 5 | 5 | -1 | 0 | 15 - 19 | 5 | 1 | 11 | 10 | 11 | 9 | 1 | 15 - 20 | 5 | 2 | 11 | 10 | 16 | 16 | 1 | 16 - 21 | 5 | 3 | 11 | 10 | 15 | 3 | 1 | 17 - 22 | 5 | 4 | 11 | 10 | 10 | -1 | 0 | 18 - 23 | 6 | 1 | 11 | 12 | 11 | 8 | 1 | 18 - 24 | 6 | 2 | 11 | 12 | 7 | 10 | 1 | 19 - 25 | 6 | 3 | 11 | 12 | 8 | 12 | 1 | 20 - 26 | 6 | 4 | 11 | 12 | 12 | -1 | 0 | 21 - 27 | 7 | 1 | 11 | 12 | 11 | 11 | 1 | 21 - 28 | 7 | 2 | 11 | 12 | 12 | -1 | 0 | 22 - 29 | 8 | 1 | 17 | 5 | 17 | 15 | 1 | 22 - 30 | 8 | 2 | 17 | 5 | 16 | 16 | 1 | 23 - 31 | 8 | 3 | 17 | 5 | 15 | 3 | 1 | 24 - 32 | 8 | 4 | 17 | 5 | 10 | 2 | 1 | 25 - 33 | 8 | 5 | 17 | 5 | 6 | 1 | 1 | 26 - 34 | 8 | 6 | 17 | 5 | 5 | -1 | 0 | 27 - 35 | 9 | 1 | 17 | 10 | 17 | 15 | 1 | 27 - 36 | 9 | 2 | 17 | 10 | 16 | 16 | 1 | 28 - 37 | 9 | 3 | 17 | 10 | 15 | 3 | 1 | 29 - 38 | 9 | 4 | 17 | 10 | 10 | -1 | 0 | 30 - 39 | 10 | 1 | 17 | 12 | 17 | 15 | 1 | 30 - 40 | 10 | 2 | 17 | 12 | 16 | 9 | 1 | 31 - 41 | 10 | 3 | 17 | 12 | 11 | 11 | 1 | 32 - 42 | 10 | 4 | 17 | 12 | 12 | -1 | 0 | 33 + 1 | 1 | 1 | 3 | 5 | 3 | 7 | 1 | 0 + 2 | 1 | 2 | 3 | 5 | 7 | 4 | 1 | 1 + 3 | 1 | 3 | 3 | 5 | 6 | 1 | 1 | 2 + 4 | 1 | 4 | 3 | 5 | 5 | -1 | 0 | 3 + 5 | 2 | 1 | 3 | 10 | 3 | 7 | 1 | 0 + 6 | 2 | 2 | 3 | 10 | 7 | 8 | 1 | 1 + 7 | 2 | 3 | 3 | 10 | 11 | 9 | 1 | 2 + 8 | 2 | 4 | 3 | 10 | 16 | 16 | 1 | 3 + 9 | 2 | 5 | 3 | 10 | 15 | 3 | 1 | 4 + 10 | 2 | 6 | 3 | 10 | 10 | -1 | 0 | 5 + 11 | 3 | 1 | 3 | 12 | 3 | 7 | 1 | 0 + 12 | 3 | 2 | 3 | 12 | 7 | 8 | 1 | 1 + 13 | 3 | 3 | 3 | 12 | 11 | 11 | 1 | 2 + 14 | 3 | 4 | 3 | 12 | 12 | -1 | 0 | 3 + 15 | 4 | 1 | 11 | 5 | 11 | 8 | 1 | 0 + 16 | 4 | 2 | 11 | 5 | 7 | 4 | 1 | 1 + 17 | 4 | 3 | 11 | 5 | 6 | 1 | 1 | 2 + 18 | 4 | 4 | 11 | 5 | 5 | -1 | 0 | 3 + 19 | 5 | 1 | 11 | 10 | 11 | 9 | 1 | 0 + 20 | 5 | 2 | 11 | 10 | 16 | 16 | 1 | 1 + 21 | 5 | 3 | 11 | 10 | 15 | 3 | 1 | 2 + 22 | 5 | 4 | 11 | 10 | 10 | -1 | 0 | 3 + 23 | 6 | 1 | 11 | 12 | 11 | 8 | 1 | 0 + 24 | 6 | 2 | 11 | 12 | 7 | 10 | 1 | 1 + 25 | 6 | 3 | 11 | 12 | 8 | 12 | 1 | 2 + 26 | 6 | 4 | 11 | 12 | 12 | -1 | 0 | 3 + 27 | 7 | 1 | 11 | 12 | 11 | 11 | 1 | 0 + 28 | 7 | 2 | 11 | 12 | 12 | -1 | 0 | 1 + 29 | 8 | 1 | 17 | 5 | 17 | 15 | 1 | 0 + 30 | 8 | 2 | 17 | 5 | 16 | 16 | 1 | 1 + 31 | 8 | 3 | 17 | 5 | 15 | 3 | 1 | 2 + 32 | 8 | 4 | 17 | 5 | 10 | 2 | 1 | 3 + 33 | 8 | 5 | 17 | 5 | 6 | 1 | 1 | 4 + 34 | 8 | 6 | 17 | 5 | 5 | -1 | 0 | 5 + 35 | 9 | 1 | 17 | 10 | 17 | 15 | 1 | 0 + 36 | 9 | 2 | 17 | 10 | 16 | 16 | 1 | 1 + 37 | 9 | 3 | 17 | 10 | 15 | 3 | 1 | 2 + 38 | 9 | 4 | 17 | 10 | 10 | -1 | 0 | 3 + 39 | 10 | 1 | 17 | 12 | 17 | 15 | 1 | 0 + 40 | 10 | 2 | 17 | 12 | 16 | 9 | 1 | 1 + 41 | 10 | 3 | 17 | 12 | 11 | 11 | 1 | 2 + 42 | 10 | 4 | 17 | 12 | 12 | -1 | 0 | 3 (42 rows) /* -- q5 */ @@ -132,17 +132,17 @@ SELECT * FROM pgr_edgeDisjointPaths( directed => false); seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost -----+---------+----------+-----------+---------+------+------+------+---------- - 1 | 1 | 1 | 5 | 10 | 5 | 1 | 1 | 1 - 2 | 1 | 2 | 5 | 10 | 6 | 2 | -1 | 2 - 3 | 1 | 3 | 5 | 10 | 10 | -1 | 0 | 1 - 4 | 2 | 1 | 6 | 15 | 6 | 4 | 1 | 1 - 5 | 2 | 2 | 6 | 15 | 7 | 8 | 1 | 2 - 6 | 2 | 3 | 6 | 15 | 11 | 9 | 1 | 3 - 7 | 2 | 4 | 6 | 15 | 16 | 16 | 1 | 4 - 8 | 2 | 5 | 6 | 15 | 15 | -1 | 0 | 5 - 9 | 3 | 1 | 6 | 15 | 6 | 2 | -1 | 5 - 10 | 3 | 2 | 6 | 15 | 10 | 3 | -1 | 4 - 11 | 3 | 3 | 6 | 15 | 15 | -1 | 0 | 3 + 1 | 1 | 1 | 5 | 10 | 5 | 1 | 1 | 0 + 2 | 1 | 2 | 5 | 10 | 6 | 2 | -1 | 1 + 3 | 1 | 3 | 5 | 10 | 10 | -1 | 0 | 0 + 4 | 2 | 1 | 6 | 15 | 6 | 4 | 1 | 0 + 5 | 2 | 2 | 6 | 15 | 7 | 8 | 1 | 1 + 6 | 2 | 3 | 6 | 15 | 11 | 9 | 1 | 2 + 7 | 2 | 4 | 6 | 15 | 16 | 16 | 1 | 3 + 8 | 2 | 5 | 6 | 15 | 15 | -1 | 0 | 4 + 9 | 3 | 1 | 6 | 15 | 6 | 2 | -1 | 0 + 10 | 3 | 2 | 6 | 15 | 10 | 3 | -1 | -1 + 11 | 3 | 3 | 6 | 15 | 15 | -1 | 0 | -2 (11 rows) /* -- q6 */ @@ -153,17 +153,17 @@ SELECT * FROM pgr_edgeDisjointPaths( directed => false); seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost -----+---------+----------+-----------+---------+------+------+------+---------- - 1 | 1 | 1 | 5 | 10 | 5 | 1 | 1 | 1 - 2 | 1 | 2 | 5 | 10 | 6 | 2 | -1 | 2 - 3 | 1 | 3 | 5 | 10 | 10 | -1 | 0 | 1 - 4 | 2 | 1 | 6 | 15 | 6 | 4 | 1 | 1 - 5 | 2 | 2 | 6 | 15 | 7 | 8 | 1 | 2 - 6 | 2 | 3 | 6 | 15 | 11 | 9 | 1 | 3 - 7 | 2 | 4 | 6 | 15 | 16 | 16 | 1 | 4 - 8 | 2 | 5 | 6 | 15 | 15 | -1 | 0 | 5 - 9 | 3 | 1 | 6 | 15 | 6 | 2 | -1 | 5 - 10 | 3 | 2 | 6 | 15 | 10 | 3 | -1 | 4 - 11 | 3 | 3 | 6 | 15 | 15 | -1 | 0 | 3 + 1 | 1 | 1 | 5 | 10 | 5 | 1 | 1 | 0 + 2 | 1 | 2 | 5 | 10 | 6 | 2 | -1 | 1 + 3 | 1 | 3 | 5 | 10 | 10 | -1 | 0 | 0 + 4 | 2 | 1 | 6 | 15 | 6 | 4 | 1 | 0 + 5 | 2 | 2 | 6 | 15 | 7 | 8 | 1 | 1 + 6 | 2 | 3 | 6 | 15 | 11 | 9 | 1 | 2 + 7 | 2 | 4 | 6 | 15 | 16 | 16 | 1 | 3 + 8 | 2 | 5 | 6 | 15 | 15 | -1 | 0 | 4 + 9 | 3 | 1 | 6 | 15 | 6 | 2 | -1 | 0 + 10 | 3 | 2 | 6 | 15 | 10 | 3 | -1 | -1 + 11 | 3 | 3 | 6 | 15 | 15 | -1 | 0 | -2 (11 rows) /* -- q7 */ diff --git a/docqueries/max_flow/doc-pgr_edmondsKarp.test.sql b/docqueries/max_flow/edmondsKarp.pg similarity index 100% rename from docqueries/max_flow/doc-pgr_edmondsKarp.test.sql rename to docqueries/max_flow/edmondsKarp.pg diff --git a/docqueries/max_flow/doc-pgr_edmondsKarp.result b/docqueries/max_flow/edmondsKarp.result similarity index 100% rename from docqueries/max_flow/doc-pgr_edmondsKarp.result rename to docqueries/max_flow/edmondsKarp.result diff --git a/docqueries/max_flow/doc-pgr_maxCardinalityMatch.test.sql b/docqueries/max_flow/maxCardinalityMatch.pg similarity index 100% rename from docqueries/max_flow/doc-pgr_maxCardinalityMatch.test.sql rename to docqueries/max_flow/maxCardinalityMatch.pg diff --git a/docqueries/max_flow/doc-pgr_maxCardinalityMatch.result b/docqueries/max_flow/maxCardinalityMatch.result similarity index 100% rename from docqueries/max_flow/doc-pgr_maxCardinalityMatch.result rename to docqueries/max_flow/maxCardinalityMatch.result diff --git a/docqueries/max_flow/doc-pgr_maxFlow.test.sql b/docqueries/max_flow/maxFlow.pg similarity index 100% rename from docqueries/max_flow/doc-pgr_maxFlow.test.sql rename to docqueries/max_flow/maxFlow.pg diff --git a/docqueries/max_flow/doc-pgr_maxFlow.result b/docqueries/max_flow/maxFlow.result similarity index 100% rename from docqueries/max_flow/doc-pgr_maxFlow.result rename to docqueries/max_flow/maxFlow.result diff --git a/docqueries/max_flow/doc-pgr_maxFlowMinCost.test.sql b/docqueries/max_flow/maxFlowMinCost.pg similarity index 100% rename from docqueries/max_flow/doc-pgr_maxFlowMinCost.test.sql rename to docqueries/max_flow/maxFlowMinCost.pg diff --git a/docqueries/max_flow/doc-pgr_maxFlowMinCost.result b/docqueries/max_flow/maxFlowMinCost.result similarity index 100% rename from docqueries/max_flow/doc-pgr_maxFlowMinCost.result rename to docqueries/max_flow/maxFlowMinCost.result diff --git a/docqueries/max_flow/doc-pgr_maxFlowMinCost_Cost.test.sql b/docqueries/max_flow/maxFlowMinCost_Cost.pg similarity index 100% rename from docqueries/max_flow/doc-pgr_maxFlowMinCost_Cost.test.sql rename to docqueries/max_flow/maxFlowMinCost_Cost.pg diff --git a/docqueries/max_flow/doc-pgr_maxFlowMinCost_Cost.result b/docqueries/max_flow/maxFlowMinCost_Cost.result similarity index 100% rename from docqueries/max_flow/doc-pgr_maxFlowMinCost_Cost.result rename to docqueries/max_flow/maxFlowMinCost_Cost.result diff --git a/docqueries/max_flow/doc-pgr_pushRelabel.test.sql b/docqueries/max_flow/pushRelabel.pg similarity index 100% rename from docqueries/max_flow/doc-pgr_pushRelabel.test.sql rename to docqueries/max_flow/pushRelabel.pg diff --git a/docqueries/max_flow/doc-pgr_pushRelabel.result b/docqueries/max_flow/pushRelabel.result similarity index 100% rename from docqueries/max_flow/doc-pgr_pushRelabel.result rename to docqueries/max_flow/pushRelabel.result diff --git a/docqueries/max_flow/test.conf b/docqueries/max_flow/test.conf index 1b2e6c14072..46a87da8966 100644 --- a/docqueries/max_flow/test.conf +++ b/docqueries/max_flow/test.conf @@ -2,28 +2,15 @@ %main::tests = ( 'any' => { - 'comment' => 'Max flow and applications test for any versions.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_maxFlow - doc-pgr_boykovKolmogorov - doc-pgr_pushRelabel - doc-pgr_edmondsKarp - doc-pgr_maxCardinalityMatch - doc-pgr_edgeDisjointPaths - doc-pgr_maxFlowMinCost - doc-pgr_maxFlowMinCost_Cost - - )], - 'documentation' => [qw( - doc-pgr_maxFlow - doc-pgr_boykovKolmogorov - doc-pgr_pushRelabel - doc-pgr_edmondsKarp - doc-pgr_maxCardinalityMatch - doc-pgr_edgeDisjointPaths - doc-pgr_maxFlowMinCost - doc-pgr_maxFlowMinCost_Cost + 'files' => [qw( + maxFlow.pg + boykovKolmogorov.pg + pushRelabel.pg + edmondsKarp.pg + maxCardinalityMatch.pg + edgeDisjointPaths.pg + maxFlowMinCost.pg + maxFlowMinCost_Cost.pg )] }, ); diff --git a/docqueries/metrics/CMakeLists.txt b/docqueries/metrics/CMakeLists.txt new file mode 100644 index 00000000000..27f1bdae576 --- /dev/null +++ b/docqueries/metrics/CMakeLists.txt @@ -0,0 +1,11 @@ +# Do not use extensions +SET(LOCAL_FILES + betweennessCentrality + ) + +foreach (f ${LOCAL_FILES}) + configure_file("${f}.result" "${PGR_DOCUMENTATION_SOURCE_DIR}/${f}.queries") + list(APPEND LOCAL_DOC_FILES "${PGR_DOCUMENTATION_SOURCE_DIR}/${f}.queries") +endforeach() + +set(PROJECT_DOC_FILES ${PROJECT_DOC_FILES} ${LOCAL_DOC_FILES} PARENT_SCOPE) diff --git a/docqueries/lineGraph/doc-pgr_lineGraph.test.sql b/docqueries/metrics/betweennessCentrality.pg similarity index 56% rename from docqueries/lineGraph/doc-pgr_lineGraph.test.sql rename to docqueries/metrics/betweennessCentrality.pg index c18e68cfe35..dbd30cc264b 100644 --- a/docqueries/lineGraph/doc-pgr_lineGraph.test.sql +++ b/docqueries/metrics/betweennessCentrality.pg @@ -1,7 +1,9 @@ -- CopyRight(c) pgRouting developers -- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/ + /* -- q1 */ -SELECT * FROM pgr_lineGraph( - 'SELECT id, source, target, cost, reverse_cost FROM edges' -); +SELECT * FROM pgr_betweennessCentrality( +'SELECT id, source, target, cost, reverse_cost +FROM edges where id < 5' +) ORDER BY vid; /* -- q2 */ diff --git a/docqueries/metrics/betweennessCentrality.result b/docqueries/metrics/betweennessCentrality.result new file mode 100644 index 00000000000..be9bb20878e --- /dev/null +++ b/docqueries/metrics/betweennessCentrality.result @@ -0,0 +1,21 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * FROM pgr_betweennessCentrality( +'SELECT id, source, target, cost, reverse_cost +FROM edges where id < 5' +) ORDER BY vid; + vid | centrality +-----+------------ + 5 | 0 + 6 | 0.5 + 7 | 0 + 10 | 0.25 + 15 | 0 +(5 rows) + +/* -- q2 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/metrics/test.conf b/docqueries/metrics/test.conf new file mode 100644 index 00000000000..6afe7ec483b --- /dev/null +++ b/docqueries/metrics/test.conf @@ -0,0 +1,12 @@ +#!/usr/bin/perl -w + +%main::tests = ( + 'any' => { + 'files' => [qw( + betweennessCentrality.pg + )] + }, + +); + +1; diff --git a/docqueries/mincut/CMakeLists.txt b/docqueries/mincut/CMakeLists.txt index 96b295e0eaf..84c97ae8b97 100644 --- a/docqueries/mincut/CMakeLists.txt +++ b/docqueries/mincut/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - doc-stoerWagner + stoerWagner ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/mincut/doc-stoerWagner.test.sql b/docqueries/mincut/stoerWagner.pg similarity index 100% rename from docqueries/mincut/doc-stoerWagner.test.sql rename to docqueries/mincut/stoerWagner.pg diff --git a/docqueries/mincut/doc-stoerWagner.result b/docqueries/mincut/stoerWagner.result similarity index 96% rename from docqueries/mincut/doc-stoerWagner.result rename to docqueries/mincut/stoerWagner.result index b2da1eba4b5..bba70d63695 100644 --- a/docqueries/mincut/doc-stoerWagner.result +++ b/docqueries/mincut/stoerWagner.result @@ -8,7 +8,7 @@ SELECT * FROM pgr_stoerWagner( FROM edges WHERE id < 17'); seq | edge | cost | mincut -----+------+------+-------- - 1 | 14 | 1 | 1 + 1 | 6 | 1 | 1 (1 row) /* -- q2 */ diff --git a/docqueries/mincut/test.conf b/docqueries/mincut/test.conf index b0a914f6e54..2ce6ca260d5 100644 --- a/docqueries/mincut/test.conf +++ b/docqueries/mincut/test.conf @@ -2,13 +2,8 @@ %main::tests = ( 'any' => { - 'comment' => 'stoer_wagner algorithm tets.', - 'data' => [ ], - 'tests' => [qw( - doc-stoerWagner - )], - 'documentation' => [qw( - doc-stoerWagner + 'files' => [qw( + stoerWagner.pg )] }, diff --git a/docqueries/ordering/cuthillMckeeOrdering.test.sql b/docqueries/ordering/cuthillMckeeOrdering.pg similarity index 100% rename from docqueries/ordering/cuthillMckeeOrdering.test.sql rename to docqueries/ordering/cuthillMckeeOrdering.pg diff --git a/docqueries/ordering/test.conf b/docqueries/ordering/test.conf index 73d9c922129..257a2beef7f 100644 --- a/docqueries/ordering/test.conf +++ b/docqueries/ordering/test.conf @@ -2,16 +2,11 @@ %main::tests = ( 'any' => { - 'comment' => 'Ordering algorithm tests.', - 'data' => [ ], - 'tests' => [qw( - cuthillMckeeOrdering - )], - 'documentation' => [qw( - cuthillMckeeOrdering + 'files' => [qw( + cuthillMckeeOrdering.pg )] }, ); -1; \ No newline at end of file +1; diff --git a/docqueries/pickDeliver/CMakeLists.txt b/docqueries/pickDeliver/CMakeLists.txt index 5ae797dcd02..76b0015761f 100644 --- a/docqueries/pickDeliver/CMakeLists.txt +++ b/docqueries/pickDeliver/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-pickDeliverEuclidean - doc-pickDeliver + pickDeliverEuclidean + pickDeliver lc101 ) diff --git a/docqueries/pickDeliver/lc101.test.sql b/docqueries/pickDeliver/lc101.pg similarity index 100% rename from docqueries/pickDeliver/lc101.test.sql rename to docqueries/pickDeliver/lc101.pg diff --git a/docqueries/pickDeliver/doc-pickDeliver.test.sql b/docqueries/pickDeliver/pickDeliver.pg similarity index 100% rename from docqueries/pickDeliver/doc-pickDeliver.test.sql rename to docqueries/pickDeliver/pickDeliver.pg diff --git a/docqueries/pickDeliver/doc-pickDeliver.result b/docqueries/pickDeliver/pickDeliver.result similarity index 100% rename from docqueries/pickDeliver/doc-pickDeliver.result rename to docqueries/pickDeliver/pickDeliver.result diff --git a/docqueries/pickDeliver/doc-pickDeliverEuclidean.test.sql b/docqueries/pickDeliver/pickDeliverEuclidean.pg similarity index 100% rename from docqueries/pickDeliver/doc-pickDeliverEuclidean.test.sql rename to docqueries/pickDeliver/pickDeliverEuclidean.pg diff --git a/docqueries/pickDeliver/doc-pickDeliverEuclidean.result b/docqueries/pickDeliver/pickDeliverEuclidean.result similarity index 100% rename from docqueries/pickDeliver/doc-pickDeliverEuclidean.result rename to docqueries/pickDeliver/pickDeliverEuclidean.result diff --git a/docqueries/pickDeliver/test.conf b/docqueries/pickDeliver/test.conf index f30ce9bb2dc..7b331a952ea 100644 --- a/docqueries/pickDeliver/test.conf +++ b/docqueries/pickDeliver/test.conf @@ -2,21 +2,13 @@ %main::tests = ( 'any' => { - 'comment' => 'Function test for any versions.', - 'data' => [], - 'tests' => [qw( - doc-pickDeliver - doc-pickDeliverEuclidean - lc101 + 'files' => [qw( + pickDeliver.pg + pickDeliverEuclidean.pg + lc101.pg )], - 'documentation' => [qw( - doc-pickDeliver - doc-pickDeliverEuclidean - lc101 - )], - -#put here the ones that you are not testing (just a place holder) + #put here the ones that you are not testing (just a place holder) 'nottesting' => [qw( past_example jet_customers diff --git a/docqueries/planar/CMakeLists.txt b/docqueries/planar/CMakeLists.txt index 790fddd0e83..21a66f4e369 100644 --- a/docqueries/planar/CMakeLists.txt +++ b/docqueries/planar/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_boyerMyrvold - doc-pgr_isPlanar + boyerMyrvold + isPlanar ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/planar/doc-pgr_boyerMyrvold.test.sql b/docqueries/planar/boyerMyrvold.pg similarity index 100% rename from docqueries/planar/doc-pgr_boyerMyrvold.test.sql rename to docqueries/planar/boyerMyrvold.pg diff --git a/docqueries/planar/doc-pgr_boyerMyrvold.result b/docqueries/planar/boyerMyrvold.result similarity index 100% rename from docqueries/planar/doc-pgr_boyerMyrvold.result rename to docqueries/planar/boyerMyrvold.result diff --git a/docqueries/planar/doc-pgr_isPlanar.test.sql b/docqueries/planar/isPlanar.pg similarity index 100% rename from docqueries/planar/doc-pgr_isPlanar.test.sql rename to docqueries/planar/isPlanar.pg diff --git a/docqueries/planar/doc-pgr_isPlanar.result b/docqueries/planar/isPlanar.result similarity index 100% rename from docqueries/planar/doc-pgr_isPlanar.result rename to docqueries/planar/isPlanar.result diff --git a/docqueries/planar/test.conf b/docqueries/planar/test.conf index 4f6137c5627..35096e4766e 100644 --- a/docqueries/planar/test.conf +++ b/docqueries/planar/test.conf @@ -2,13 +2,8 @@ %main::tests = ( 'any' => { - 'comment' => 'boyerMyrvold planarity algorithm tests.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_isPlanar - )], - 'documentation' => [qw( - doc-pgr_isPlanar + 'files' => [qw( + isPlanar.pg )] }, diff --git a/docqueries/spanningTree/CMakeLists.txt b/docqueries/spanningTree/CMakeLists.txt index 4a33c1643dc..c7a5dac2dec 100644 --- a/docqueries/spanningTree/CMakeLists.txt +++ b/docqueries/spanningTree/CMakeLists.txt @@ -1,13 +1,13 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_kruskalBFS - doc-pgr_kruskalDD - doc-pgr_kruskalDFS - doc-pgr_kruskal - doc-pgr_primBFS - doc-pgr_primDD - doc-pgr_primDFS - doc-pgr_prim + kruskalBFS + kruskalDD + kruskalDFS + kruskal + primBFS + primDD + primDFS + prim ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/spanningTree/doc-pgr_kruskalBFS.result b/docqueries/spanningTree/doc-pgr_kruskalBFS.result deleted file mode 100644 index 378883b2106..00000000000 --- a/docqueries/spanningTree/doc-pgr_kruskalBFS.result +++ /dev/null @@ -1,48 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -/* -- q1 */ -SELECT * FROM pgr_kruskalBFS( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - 6); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 3 | 6 | 16 | 16 | 1 | 3 - 6 | 4 | 6 | 17 | 15 | 1 | 4 - 7 | 5 | 6 | 12 | 13 | 1 | 5 - 8 | 6 | 6 | 11 | 11 | 1 | 6 - 9 | 6 | 6 | 8 | 12 | 1 | 6 - 10 | 7 | 6 | 7 | 10 | 1 | 7 - 11 | 7 | 6 | 9 | 14 | 1 | 7 - 12 | 8 | 6 | 3 | 7 | 1 | 8 - 13 | 9 | 6 | 1 | 6 | 1 | 9 -(13 rows) - -/* -- q2 */ -SELECT * FROM pgr_kruskalBFS( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - ARRAY[9, 6], max_depth => 3); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 3 | 6 | 16 | 16 | 1 | 3 - 6 | 0 | 9 | 9 | -1 | 0 | 0 - 7 | 1 | 9 | 8 | 14 | 1 | 1 - 8 | 2 | 9 | 7 | 10 | 1 | 2 - 9 | 2 | 9 | 12 | 12 | 1 | 2 - 10 | 3 | 9 | 3 | 7 | 1 | 3 - 11 | 3 | 9 | 11 | 11 | 1 | 3 - 12 | 3 | 9 | 17 | 13 | 1 | 3 -(12 rows) - -/* -- q3 */ -ROLLBACK; -ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_kruskalDD.result b/docqueries/spanningTree/doc-pgr_kruskalDD.result deleted file mode 100644 index eff6fd12b4a..00000000000 --- a/docqueries/spanningTree/doc-pgr_kruskalDD.result +++ /dev/null @@ -1,40 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -/* -- q1 */ -SELECT * FROM pgr_kruskalDD( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - 6, 3.5); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 3 | 6 | 16 | 16 | 1 | 3 -(5 rows) - -/* -- q2 */ -SELECT * FROM pgr_kruskalDD( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - ARRAY[9, 6], 3.5); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 3 | 6 | 16 | 16 | 1 | 3 - 6 | 0 | 9 | 9 | -1 | 0 | 0 - 7 | 1 | 9 | 8 | 14 | 1 | 1 - 8 | 2 | 9 | 7 | 10 | 1 | 2 - 9 | 3 | 9 | 3 | 7 | 1 | 3 - 10 | 2 | 9 | 12 | 12 | 1 | 2 - 11 | 3 | 9 | 11 | 11 | 1 | 3 - 12 | 3 | 9 | 17 | 13 | 1 | 3 -(12 rows) - -/* -- q3 */ -ROLLBACK; -ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_kruskalDFS.result b/docqueries/spanningTree/doc-pgr_kruskalDFS.result deleted file mode 100644 index 03d62fac4e7..00000000000 --- a/docqueries/spanningTree/doc-pgr_kruskalDFS.result +++ /dev/null @@ -1,48 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -/* -- q1 */ -SELECT * FROM pgr_kruskalDFS( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - 6); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 3 | 6 | 16 | 16 | 1 | 3 - 6 | 4 | 6 | 17 | 15 | 1 | 4 - 7 | 5 | 6 | 12 | 13 | 1 | 5 - 8 | 6 | 6 | 11 | 11 | 1 | 6 - 9 | 6 | 6 | 8 | 12 | 1 | 6 - 10 | 7 | 6 | 7 | 10 | 1 | 7 - 11 | 8 | 6 | 3 | 7 | 1 | 8 - 12 | 9 | 6 | 1 | 6 | 1 | 9 - 13 | 7 | 6 | 9 | 14 | 1 | 7 -(13 rows) - -/* -- q2 */ -SELECT * FROM pgr_kruskalDFS( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - ARRAY[9, 6], max_depth => 3); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 3 | 6 | 16 | 16 | 1 | 3 - 6 | 0 | 9 | 9 | -1 | 0 | 0 - 7 | 1 | 9 | 8 | 14 | 1 | 1 - 8 | 2 | 9 | 7 | 10 | 1 | 2 - 9 | 3 | 9 | 3 | 7 | 1 | 3 - 10 | 2 | 9 | 12 | 12 | 1 | 2 - 11 | 3 | 9 | 11 | 11 | 1 | 3 - 12 | 3 | 9 | 17 | 13 | 1 | 3 -(12 rows) - -/* -- q3 */ -ROLLBACK; -ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_primBFS.result b/docqueries/spanningTree/doc-pgr_primBFS.result deleted file mode 100644 index 7263280e207..00000000000 --- a/docqueries/spanningTree/doc-pgr_primBFS.result +++ /dev/null @@ -1,53 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -/* -- q1 */ -SELECT * FROM pgr_primBFS( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - 6); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 1 | 6 | 7 | 4 | 1 | 1 - 5 | 2 | 6 | 15 | 3 | 1 | 2 - 6 | 2 | 6 | 11 | 5 | 1 | 2 - 7 | 2 | 6 | 3 | 7 | 1 | 2 - 8 | 2 | 6 | 8 | 10 | 1 | 2 - 9 | 3 | 6 | 16 | 9 | 1 | 3 - 10 | 3 | 6 | 12 | 11 | 1 | 3 - 11 | 3 | 6 | 1 | 6 | 1 | 3 - 12 | 3 | 6 | 9 | 14 | 1 | 3 - 13 | 4 | 6 | 17 | 13 | 1 | 4 -(13 rows) - -/* -- q2 */ -SELECT * FROM pgr_primBFS( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - ARRAY[9, 6], max_depth => 3); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 1 | 6 | 7 | 4 | 1 | 1 - 5 | 2 | 6 | 15 | 3 | 1 | 2 - 6 | 2 | 6 | 11 | 5 | 1 | 2 - 7 | 2 | 6 | 3 | 7 | 1 | 2 - 8 | 2 | 6 | 8 | 10 | 1 | 2 - 9 | 3 | 6 | 16 | 9 | 1 | 3 - 10 | 3 | 6 | 12 | 11 | 1 | 3 - 11 | 3 | 6 | 1 | 6 | 1 | 3 - 12 | 3 | 6 | 9 | 14 | 1 | 3 - 13 | 0 | 9 | 9 | -1 | 0 | 0 - 14 | 1 | 9 | 8 | 14 | 1 | 1 - 15 | 2 | 9 | 7 | 10 | 1 | 2 - 16 | 3 | 9 | 6 | 4 | 1 | 3 - 17 | 3 | 9 | 3 | 7 | 1 | 3 -(17 rows) - -/* -- q3 */ -ROLLBACK; -ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_primDD.result b/docqueries/spanningTree/doc-pgr_primDD.result deleted file mode 100644 index dd2c976fe33..00000000000 --- a/docqueries/spanningTree/doc-pgr_primDD.result +++ /dev/null @@ -1,52 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -/* -- q1 */ -SELECT * FROM pgr_primDD( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - 6, 3.5); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 2 | 6 | 11 | 5 | 1 | 2 - 6 | 3 | 6 | 16 | 9 | 1 | 3 - 7 | 3 | 6 | 12 | 11 | 1 | 3 - 8 | 1 | 6 | 7 | 4 | 1 | 1 - 9 | 2 | 6 | 3 | 7 | 1 | 2 - 10 | 3 | 6 | 1 | 6 | 1 | 3 - 11 | 2 | 6 | 8 | 10 | 1 | 2 - 12 | 3 | 6 | 9 | 14 | 1 | 3 -(12 rows) - -/* -- q2 */ -SELECT * FROM pgr_primDD( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - ARRAY[9, 6], 3.5); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 2 | 6 | 11 | 5 | 1 | 2 - 6 | 3 | 6 | 16 | 9 | 1 | 3 - 7 | 3 | 6 | 12 | 11 | 1 | 3 - 8 | 1 | 6 | 7 | 4 | 1 | 1 - 9 | 2 | 6 | 3 | 7 | 1 | 2 - 10 | 3 | 6 | 1 | 6 | 1 | 3 - 11 | 2 | 6 | 8 | 10 | 1 | 2 - 12 | 3 | 6 | 9 | 14 | 1 | 3 - 13 | 0 | 9 | 9 | -1 | 0 | 0 - 14 | 1 | 9 | 8 | 14 | 1 | 1 - 15 | 2 | 9 | 7 | 10 | 1 | 2 - 16 | 3 | 9 | 6 | 4 | 1 | 3 - 17 | 3 | 9 | 3 | 7 | 1 | 3 -(17 rows) - -/* -- q3 */ -ROLLBACK; -ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_primDFS.result b/docqueries/spanningTree/doc-pgr_primDFS.result deleted file mode 100644 index 8d16ea4229f..00000000000 --- a/docqueries/spanningTree/doc-pgr_primDFS.result +++ /dev/null @@ -1,53 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -/* -- q1 */ -SELECT * FROM pgr_primDFS( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - 6); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 2 | 6 | 11 | 5 | 1 | 2 - 6 | 3 | 6 | 16 | 9 | 1 | 3 - 7 | 3 | 6 | 12 | 11 | 1 | 3 - 8 | 4 | 6 | 17 | 13 | 1 | 4 - 9 | 1 | 6 | 7 | 4 | 1 | 1 - 10 | 2 | 6 | 3 | 7 | 1 | 2 - 11 | 3 | 6 | 1 | 6 | 1 | 3 - 12 | 2 | 6 | 8 | 10 | 1 | 2 - 13 | 3 | 6 | 9 | 14 | 1 | 3 -(13 rows) - -/* -- q2 */ -SELECT * FROM pgr_primDFS( - 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', - ARRAY[9, 6], max_depth => 3); - seq | depth | start_vid | node | edge | cost | agg_cost ------+-------+-----------+------+------+------+---------- - 1 | 0 | 6 | 6 | -1 | 0 | 0 - 2 | 1 | 6 | 5 | 1 | 1 | 1 - 3 | 1 | 6 | 10 | 2 | 1 | 1 - 4 | 2 | 6 | 15 | 3 | 1 | 2 - 5 | 2 | 6 | 11 | 5 | 1 | 2 - 6 | 3 | 6 | 16 | 9 | 1 | 3 - 7 | 3 | 6 | 12 | 11 | 1 | 3 - 8 | 1 | 6 | 7 | 4 | 1 | 1 - 9 | 2 | 6 | 3 | 7 | 1 | 2 - 10 | 3 | 6 | 1 | 6 | 1 | 3 - 11 | 2 | 6 | 8 | 10 | 1 | 2 - 12 | 3 | 6 | 9 | 14 | 1 | 3 - 13 | 0 | 9 | 9 | -1 | 0 | 0 - 14 | 1 | 9 | 8 | 14 | 1 | 1 - 15 | 2 | 9 | 7 | 10 | 1 | 2 - 16 | 3 | 9 | 6 | 4 | 1 | 3 - 17 | 3 | 9 | 3 | 7 | 1 | 3 -(17 rows) - -/* -- q3 */ -ROLLBACK; -ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_kruskal.test.sql b/docqueries/spanningTree/kruskal.pg similarity index 100% rename from docqueries/spanningTree/doc-pgr_kruskal.test.sql rename to docqueries/spanningTree/kruskal.pg diff --git a/docqueries/spanningTree/doc-pgr_kruskal.result b/docqueries/spanningTree/kruskal.result similarity index 100% rename from docqueries/spanningTree/doc-pgr_kruskal.result rename to docqueries/spanningTree/kruskal.result diff --git a/docqueries/spanningTree/doc-pgr_kruskalBFS.test.sql b/docqueries/spanningTree/kruskalBFS.pg similarity index 100% rename from docqueries/spanningTree/doc-pgr_kruskalBFS.test.sql rename to docqueries/spanningTree/kruskalBFS.pg diff --git a/docqueries/spanningTree/kruskalBFS.result b/docqueries/spanningTree/kruskalBFS.result new file mode 100644 index 00000000000..3470f79bfec --- /dev/null +++ b/docqueries/spanningTree/kruskalBFS.result @@ -0,0 +1,48 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * FROM pgr_kruskalBFS( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 15 | 16 | 16 | 1 | 3 + 6 | 4 | 6 | 16 | 17 | 15 | 1 | 4 + 7 | 5 | 6 | 17 | 12 | 13 | 1 | 5 + 8 | 6 | 6 | 12 | 11 | 11 | 1 | 6 + 9 | 6 | 6 | 12 | 8 | 12 | 1 | 6 + 10 | 7 | 6 | 8 | 7 | 10 | 1 | 7 + 11 | 7 | 6 | 8 | 9 | 14 | 1 | 7 + 12 | 8 | 6 | 7 | 3 | 7 | 1 | 8 + 13 | 9 | 6 | 3 | 1 | 6 | 1 | 9 +(13 rows) + +/* -- q2 */ +SELECT * FROM pgr_kruskalBFS( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], max_depth => 3); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 15 | 16 | 16 | 1 | 3 + 6 | 0 | 9 | 9 | 9 | -1 | 0 | 0 + 7 | 1 | 9 | 9 | 8 | 14 | 1 | 1 + 8 | 2 | 9 | 8 | 7 | 10 | 1 | 2 + 9 | 2 | 9 | 8 | 12 | 12 | 1 | 2 + 10 | 3 | 9 | 7 | 3 | 7 | 1 | 3 + 11 | 3 | 9 | 12 | 11 | 11 | 1 | 3 + 12 | 3 | 9 | 12 | 17 | 13 | 1 | 3 +(12 rows) + +/* -- q3 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_kruskalDD.test.sql b/docqueries/spanningTree/kruskalDD.pg similarity index 100% rename from docqueries/spanningTree/doc-pgr_kruskalDD.test.sql rename to docqueries/spanningTree/kruskalDD.pg diff --git a/docqueries/spanningTree/kruskalDD.result b/docqueries/spanningTree/kruskalDD.result new file mode 100644 index 00000000000..c13a139b2e1 --- /dev/null +++ b/docqueries/spanningTree/kruskalDD.result @@ -0,0 +1,40 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 15 | 16 | 16 | 1 | 3 +(5 rows) + +/* -- q2 */ +SELECT * FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 15 | 16 | 16 | 1 | 3 + 6 | 0 | 9 | 9 | 9 | -1 | 0 | 0 + 7 | 1 | 9 | 9 | 8 | 14 | 1 | 1 + 8 | 2 | 9 | 8 | 7 | 10 | 1 | 2 + 9 | 3 | 9 | 7 | 3 | 7 | 1 | 3 + 10 | 2 | 9 | 8 | 12 | 12 | 1 | 2 + 11 | 3 | 9 | 12 | 11 | 11 | 1 | 3 + 12 | 3 | 9 | 12 | 17 | 13 | 1 | 3 +(12 rows) + +/* -- q3 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_kruskalDFS.test.sql b/docqueries/spanningTree/kruskalDFS.pg similarity index 100% rename from docqueries/spanningTree/doc-pgr_kruskalDFS.test.sql rename to docqueries/spanningTree/kruskalDFS.pg diff --git a/docqueries/spanningTree/kruskalDFS.result b/docqueries/spanningTree/kruskalDFS.result new file mode 100644 index 00000000000..19bdaf33922 --- /dev/null +++ b/docqueries/spanningTree/kruskalDFS.result @@ -0,0 +1,48 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * FROM pgr_kruskalDFS( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 15 | 16 | 16 | 1 | 3 + 6 | 4 | 6 | 16 | 17 | 15 | 1 | 4 + 7 | 5 | 6 | 17 | 12 | 13 | 1 | 5 + 8 | 6 | 6 | 12 | 11 | 11 | 1 | 6 + 9 | 6 | 6 | 12 | 8 | 12 | 1 | 6 + 10 | 7 | 6 | 8 | 7 | 10 | 1 | 7 + 11 | 8 | 6 | 7 | 3 | 7 | 1 | 8 + 12 | 9 | 6 | 3 | 1 | 6 | 1 | 9 + 13 | 7 | 6 | 8 | 9 | 14 | 1 | 7 +(13 rows) + +/* -- q2 */ +SELECT * FROM pgr_kruskalDFS( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], max_depth => 3); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 15 | 16 | 16 | 1 | 3 + 6 | 0 | 9 | 9 | 9 | -1 | 0 | 0 + 7 | 1 | 9 | 9 | 8 | 14 | 1 | 1 + 8 | 2 | 9 | 8 | 7 | 10 | 1 | 2 + 9 | 3 | 9 | 7 | 3 | 7 | 1 | 3 + 10 | 2 | 9 | 8 | 12 | 12 | 1 | 2 + 11 | 3 | 9 | 12 | 11 | 11 | 1 | 3 + 12 | 3 | 9 | 12 | 17 | 13 | 1 | 3 +(12 rows) + +/* -- q3 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_prim.test.sql b/docqueries/spanningTree/prim.pg similarity index 100% rename from docqueries/spanningTree/doc-pgr_prim.test.sql rename to docqueries/spanningTree/prim.pg diff --git a/docqueries/spanningTree/doc-pgr_prim.result b/docqueries/spanningTree/prim.result similarity index 100% rename from docqueries/spanningTree/doc-pgr_prim.result rename to docqueries/spanningTree/prim.result diff --git a/docqueries/spanningTree/doc-pgr_primBFS.test.sql b/docqueries/spanningTree/primBFS.pg similarity index 100% rename from docqueries/spanningTree/doc-pgr_primBFS.test.sql rename to docqueries/spanningTree/primBFS.pg diff --git a/docqueries/spanningTree/primBFS.result b/docqueries/spanningTree/primBFS.result new file mode 100644 index 00000000000..4a90683431e --- /dev/null +++ b/docqueries/spanningTree/primBFS.result @@ -0,0 +1,53 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * FROM pgr_primBFS( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 1 | 6 | 6 | 7 | 4 | 1 | 1 + 5 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 6 | 2 | 6 | 10 | 11 | 5 | 1 | 2 + 7 | 2 | 6 | 7 | 3 | 7 | 1 | 2 + 8 | 2 | 6 | 7 | 8 | 10 | 1 | 2 + 9 | 3 | 6 | 11 | 16 | 9 | 1 | 3 + 10 | 3 | 6 | 11 | 12 | 11 | 1 | 3 + 11 | 3 | 6 | 3 | 1 | 6 | 1 | 3 + 12 | 3 | 6 | 8 | 9 | 14 | 1 | 3 + 13 | 4 | 6 | 12 | 17 | 13 | 1 | 4 +(13 rows) + +/* -- q2 */ +SELECT * FROM pgr_primBFS( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], max_depth => 3); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 1 | 6 | 6 | 7 | 4 | 1 | 1 + 5 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 6 | 2 | 6 | 10 | 11 | 5 | 1 | 2 + 7 | 2 | 6 | 7 | 3 | 7 | 1 | 2 + 8 | 2 | 6 | 7 | 8 | 10 | 1 | 2 + 9 | 3 | 6 | 11 | 16 | 9 | 1 | 3 + 10 | 3 | 6 | 11 | 12 | 11 | 1 | 3 + 11 | 3 | 6 | 3 | 1 | 6 | 1 | 3 + 12 | 3 | 6 | 8 | 9 | 14 | 1 | 3 + 13 | 0 | 9 | 9 | 9 | -1 | 0 | 0 + 14 | 1 | 9 | 9 | 8 | 14 | 1 | 1 + 15 | 2 | 9 | 8 | 7 | 10 | 1 | 2 + 16 | 3 | 9 | 7 | 6 | 4 | 1 | 3 + 17 | 3 | 9 | 7 | 3 | 7 | 1 | 3 +(17 rows) + +/* -- q3 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_primDD.test.sql b/docqueries/spanningTree/primDD.pg similarity index 100% rename from docqueries/spanningTree/doc-pgr_primDD.test.sql rename to docqueries/spanningTree/primDD.pg diff --git a/docqueries/spanningTree/primDD.result b/docqueries/spanningTree/primDD.result new file mode 100644 index 00000000000..d9c255d726b --- /dev/null +++ b/docqueries/spanningTree/primDD.result @@ -0,0 +1,52 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 2 | 6 | 10 | 11 | 5 | 1 | 2 + 6 | 3 | 6 | 11 | 16 | 9 | 1 | 3 + 7 | 3 | 6 | 11 | 12 | 11 | 1 | 3 + 8 | 1 | 6 | 6 | 7 | 4 | 1 | 1 + 9 | 2 | 6 | 7 | 3 | 7 | 1 | 2 + 10 | 3 | 6 | 3 | 1 | 6 | 1 | 3 + 11 | 2 | 6 | 7 | 8 | 10 | 1 | 2 + 12 | 3 | 6 | 8 | 9 | 14 | 1 | 3 +(12 rows) + +/* -- q2 */ +SELECT * FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 2 | 6 | 10 | 11 | 5 | 1 | 2 + 6 | 3 | 6 | 11 | 16 | 9 | 1 | 3 + 7 | 3 | 6 | 11 | 12 | 11 | 1 | 3 + 8 | 1 | 6 | 6 | 7 | 4 | 1 | 1 + 9 | 2 | 6 | 7 | 3 | 7 | 1 | 2 + 10 | 3 | 6 | 3 | 1 | 6 | 1 | 3 + 11 | 2 | 6 | 7 | 8 | 10 | 1 | 2 + 12 | 3 | 6 | 8 | 9 | 14 | 1 | 3 + 13 | 0 | 9 | 9 | 9 | -1 | 0 | 0 + 14 | 1 | 9 | 9 | 8 | 14 | 1 | 1 + 15 | 2 | 9 | 8 | 7 | 10 | 1 | 2 + 16 | 3 | 9 | 7 | 6 | 4 | 1 | 3 + 17 | 3 | 9 | 7 | 3 | 7 | 1 | 3 +(17 rows) + +/* -- q3 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_primDFS.test.sql b/docqueries/spanningTree/primDFS.pg similarity index 100% rename from docqueries/spanningTree/doc-pgr_primDFS.test.sql rename to docqueries/spanningTree/primDFS.pg diff --git a/docqueries/spanningTree/primDFS.result b/docqueries/spanningTree/primDFS.result new file mode 100644 index 00000000000..b9e2fcf86a3 --- /dev/null +++ b/docqueries/spanningTree/primDFS.result @@ -0,0 +1,53 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * FROM pgr_primDFS( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 2 | 6 | 10 | 11 | 5 | 1 | 2 + 6 | 3 | 6 | 11 | 16 | 9 | 1 | 3 + 7 | 3 | 6 | 11 | 12 | 11 | 1 | 3 + 8 | 4 | 6 | 12 | 17 | 13 | 1 | 4 + 9 | 1 | 6 | 6 | 7 | 4 | 1 | 1 + 10 | 2 | 6 | 7 | 3 | 7 | 1 | 2 + 11 | 3 | 6 | 3 | 1 | 6 | 1 | 3 + 12 | 2 | 6 | 7 | 8 | 10 | 1 | 2 + 13 | 3 | 6 | 8 | 9 | 14 | 1 | 3 +(13 rows) + +/* -- q2 */ +SELECT * FROM pgr_primDFS( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], max_depth => 3); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 2 | 6 | 10 | 11 | 5 | 1 | 2 + 6 | 3 | 6 | 11 | 16 | 9 | 1 | 3 + 7 | 3 | 6 | 11 | 12 | 11 | 1 | 3 + 8 | 1 | 6 | 6 | 7 | 4 | 1 | 1 + 9 | 2 | 6 | 7 | 3 | 7 | 1 | 2 + 10 | 3 | 6 | 3 | 1 | 6 | 1 | 3 + 11 | 2 | 6 | 7 | 8 | 10 | 1 | 2 + 12 | 3 | 6 | 8 | 9 | 14 | 1 | 3 + 13 | 0 | 9 | 9 | 9 | -1 | 0 | 0 + 14 | 1 | 9 | 9 | 8 | 14 | 1 | 1 + 15 | 2 | 9 | 8 | 7 | 10 | 1 | 2 + 16 | 3 | 9 | 7 | 6 | 4 | 1 | 3 + 17 | 3 | 9 | 7 | 3 | 7 | 1 | 3 +(17 rows) + +/* -- q3 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/spanningTree/doc-pgr_randomSpanTree.test.sql b/docqueries/spanningTree/randomSpanTree.pg similarity index 100% rename from docqueries/spanningTree/doc-pgr_randomSpanTree.test.sql rename to docqueries/spanningTree/randomSpanTree.pg diff --git a/docqueries/spanningTree/doc-pgr_randomSpanTree.result b/docqueries/spanningTree/randomSpanTree.result similarity index 100% rename from docqueries/spanningTree/doc-pgr_randomSpanTree.result rename to docqueries/spanningTree/randomSpanTree.result diff --git a/docqueries/spanningTree/test.conf b/docqueries/spanningTree/test.conf index 8d6f730dabc..2c2d87f39ac 100644 --- a/docqueries/spanningTree/test.conf +++ b/docqueries/spanningTree/test.conf @@ -2,29 +2,16 @@ %main::tests = ( 'any' => { - 'comment' => 'Spanning tree algorithm tets.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_kruskal - doc-pgr_kruskalDD - doc-pgr_kruskalDFS - doc-pgr_kruskalBFS + 'files' => [qw( + kruskal.pg + kruskalDD.pg + kruskalDFS.pg + kruskalBFS.pg - doc-pgr_prim - doc-pgr_primDFS - doc-pgr_primDD - doc-pgr_primBFS - )], - 'documentation' => [qw( - doc-pgr_kruskal - doc-pgr_kruskalDD - doc-pgr_kruskalDFS - doc-pgr_kruskalBFS - - doc-pgr_prim - doc-pgr_primDFS - doc-pgr_primDD - doc-pgr_primBFS + prim.pg + primDFS.pg + primDD.pg + primBFS.pg )] }, diff --git a/docqueries/src/concepts.test.sql b/docqueries/src/concepts.pg similarity index 100% rename from docqueries/src/concepts.test.sql rename to docqueries/src/concepts.pg diff --git a/docqueries/src/migration.test.sql b/docqueries/src/migration.pg similarity index 90% rename from docqueries/src/migration.test.sql rename to docqueries/src/migration.pg index cea07bd7696..d332ab6d9c0 100644 --- a/docqueries/src/migration.test.sql +++ b/docqueries/src/migration.pg @@ -338,3 +338,42 @@ FROM pgr_drivingDistance( ARRAY[11, 16], 3.0, equicost => true); /* --drivingdistance5 */ +/* --kruskalDD1 */ +SELECT * FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); +/* --kruskalDD2 */ +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); +/* --kruskalDD3 */ +SELECT * FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); +/* --kruskalDD4 */ +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); +/* --kruskalDD5 */ + +/* --primDD1 */ +SELECT * FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); +/* --primDD2 */ +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); +/* --primDD3 */ +SELECT * FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); +/* --primDD4 */ +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); +/* --primDD5 */ diff --git a/docqueries/src/migration.result b/docqueries/src/migration.result index c88792e5fb4..93e5af8927e 100644 --- a/docqueries/src/migration.result +++ b/docqueries/src/migration.result @@ -1079,5 +1079,167 @@ FROM pgr_drivingDistance( (13 rows) /* --drivingdistance5 */ +/* --kruskalDD1 */ +SELECT * FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 15 | 16 | 16 | 1 | 3 +(5 rows) + +/* --kruskalDD2 */ +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); + seq | depth | start_vid | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+---------- + 1 | 0 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 16 | 16 | 1 | 3 +(5 rows) + +/* --kruskalDD3 */ +SELECT * FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 15 | 16 | 16 | 1 | 3 + 6 | 0 | 9 | 9 | 9 | -1 | 0 | 0 + 7 | 1 | 9 | 9 | 8 | 14 | 1 | 1 + 8 | 2 | 9 | 8 | 7 | 10 | 1 | 2 + 9 | 3 | 9 | 7 | 3 | 7 | 1 | 3 + 10 | 2 | 9 | 8 | 12 | 12 | 1 | 2 + 11 | 3 | 9 | 12 | 11 | 11 | 1 | 3 + 12 | 3 | 9 | 12 | 17 | 13 | 1 | 3 +(12 rows) + +/* --kruskalDD4 */ +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_kruskalDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); + seq | depth | start_vid | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+---------- + 1 | 0 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 15 | 3 | 1 | 2 + 5 | 3 | 6 | 16 | 16 | 1 | 3 + 6 | 0 | 9 | 9 | -1 | 0 | 0 + 7 | 1 | 9 | 8 | 14 | 1 | 1 + 8 | 2 | 9 | 7 | 10 | 1 | 2 + 9 | 3 | 9 | 3 | 7 | 1 | 3 + 10 | 2 | 9 | 12 | 12 | 1 | 2 + 11 | 3 | 9 | 11 | 11 | 1 | 3 + 12 | 3 | 9 | 17 | 13 | 1 | 3 +(12 rows) + +/* --kruskalDD5 */ +/* --primDD1 */ +SELECT * FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 2 | 6 | 10 | 11 | 5 | 1 | 2 + 6 | 3 | 6 | 11 | 16 | 9 | 1 | 3 + 7 | 3 | 6 | 11 | 12 | 11 | 1 | 3 + 8 | 1 | 6 | 6 | 7 | 4 | 1 | 1 + 9 | 2 | 6 | 7 | 3 | 7 | 1 | 2 + 10 | 3 | 6 | 3 | 1 | 6 | 1 | 3 + 11 | 2 | 6 | 7 | 8 | 10 | 1 | 2 + 12 | 3 | 6 | 8 | 9 | 14 | 1 | 3 +(12 rows) + +/* --primDD2 */ +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + 6, 3.5); + seq | depth | start_vid | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+---------- + 1 | 0 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 15 | 3 | 1 | 2 + 5 | 2 | 6 | 11 | 5 | 1 | 2 + 6 | 3 | 6 | 16 | 9 | 1 | 3 + 7 | 3 | 6 | 12 | 11 | 1 | 3 + 8 | 1 | 6 | 7 | 4 | 1 | 1 + 9 | 2 | 6 | 3 | 7 | 1 | 2 + 10 | 3 | 6 | 1 | 6 | 1 | 3 + 11 | 2 | 6 | 8 | 10 | 1 | 2 + 12 | 3 | 6 | 9 | 14 | 1 | 3 +(12 rows) + +/* --primDD3 */ +SELECT * FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); + seq | depth | start_vid | pred | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+------+---------- + 1 | 0 | 6 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 10 | 15 | 3 | 1 | 2 + 5 | 2 | 6 | 10 | 11 | 5 | 1 | 2 + 6 | 3 | 6 | 11 | 16 | 9 | 1 | 3 + 7 | 3 | 6 | 11 | 12 | 11 | 1 | 3 + 8 | 1 | 6 | 6 | 7 | 4 | 1 | 1 + 9 | 2 | 6 | 7 | 3 | 7 | 1 | 2 + 10 | 3 | 6 | 3 | 1 | 6 | 1 | 3 + 11 | 2 | 6 | 7 | 8 | 10 | 1 | 2 + 12 | 3 | 6 | 8 | 9 | 14 | 1 | 3 + 13 | 0 | 9 | 9 | 9 | -1 | 0 | 0 + 14 | 1 | 9 | 9 | 8 | 14 | 1 | 1 + 15 | 2 | 9 | 8 | 7 | 10 | 1 | 2 + 16 | 3 | 9 | 7 | 6 | 4 | 1 | 3 + 17 | 3 | 9 | 7 | 3 | 7 | 1 | 3 +(17 rows) + +/* --primDD4 */ +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_primDD( + 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', + ARRAY[9, 6], 3.5); + seq | depth | start_vid | node | edge | cost | agg_cost +-----+-------+-----------+------+------+------+---------- + 1 | 0 | 6 | 6 | -1 | 0 | 0 + 2 | 1 | 6 | 5 | 1 | 1 | 1 + 3 | 1 | 6 | 10 | 2 | 1 | 1 + 4 | 2 | 6 | 15 | 3 | 1 | 2 + 5 | 2 | 6 | 11 | 5 | 1 | 2 + 6 | 3 | 6 | 16 | 9 | 1 | 3 + 7 | 3 | 6 | 12 | 11 | 1 | 3 + 8 | 1 | 6 | 7 | 4 | 1 | 1 + 9 | 2 | 6 | 3 | 7 | 1 | 2 + 10 | 3 | 6 | 1 | 6 | 1 | 3 + 11 | 2 | 6 | 8 | 10 | 1 | 2 + 12 | 3 | 6 | 9 | 14 | 1 | 3 + 13 | 0 | 9 | 9 | -1 | 0 | 0 + 14 | 1 | 9 | 8 | 14 | 1 | 1 + 15 | 2 | 9 | 7 | 10 | 1 | 2 + 16 | 3 | 9 | 6 | 4 | 1 | 3 + 17 | 3 | 9 | 3 | 7 | 1 | 3 +(17 rows) + +/* --primDD5 */ ROLLBACK; ROLLBACK diff --git a/docqueries/src/sampledata.test.sql b/docqueries/src/sampledata.pg similarity index 100% rename from docqueries/src/sampledata.test.sql rename to docqueries/src/sampledata.pg diff --git a/docqueries/src/test.conf b/docqueries/src/test.conf index a8072e7593f..2eb35118beb 100644 --- a/docqueries/src/test.conf +++ b/docqueries/src/test.conf @@ -2,19 +2,11 @@ %main::tests = ( 'any' => { - 'comment' => '', - 'data' => [], - 'tests' => [qw( - withPoints-category - sampledata - migration - concepts - )], - 'documentation' => [qw( - sampledata - withPoints-category - migration - concepts + 'files' => [qw( + sampledata.pg + withPoints-category.pg + migration.pg + concepts.pg )], }, ); diff --git a/docqueries/src/withPoints-category.test.sql b/docqueries/src/withPoints-category.pg similarity index 100% rename from docqueries/src/withPoints-category.test.sql rename to docqueries/src/withPoints-category.pg diff --git a/docqueries/topologicalSort/CMakeLists.txt b/docqueries/topologicalSort/CMakeLists.txt index 22dee192698..f2f5aae793b 100644 --- a/docqueries/topologicalSort/CMakeLists.txt +++ b/docqueries/topologicalSort/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - doc-topologicalSort + topologicalSort ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/topologicalSort/test.conf b/docqueries/topologicalSort/test.conf index 1843c3d68c4..4fb2719adfa 100644 --- a/docqueries/topologicalSort/test.conf +++ b/docqueries/topologicalSort/test.conf @@ -2,13 +2,8 @@ %main::tests = ( 'any' => { - 'comment' => 'topologicalSort algorithm tests.', - 'data' => [ ], - 'tests' => [qw( - doc-topologicalSort - )], - 'documentation' => [qw( - doc-topologicalSort + 'files' => [qw( + topologicalSort.pg )] }, diff --git a/docqueries/topologicalSort/doc-topologicalSort.test.sql b/docqueries/topologicalSort/topologicalSort.pg similarity index 100% rename from docqueries/topologicalSort/doc-topologicalSort.test.sql rename to docqueries/topologicalSort/topologicalSort.pg diff --git a/docqueries/topologicalSort/doc-topologicalSort.result b/docqueries/topologicalSort/topologicalSort.result similarity index 99% rename from docqueries/topologicalSort/doc-topologicalSort.result rename to docqueries/topologicalSort/topologicalSort.result index ac0fd1cad1b..f055e8336f8 100644 --- a/docqueries/topologicalSort/doc-topologicalSort.result +++ b/docqueries/topologicalSort/topologicalSort.result @@ -62,6 +62,7 @@ SELECT * FROM pgr_topologicalsort( SELECT * FROM pgr_topologicalsort( $$SELECT id, source, target, cost, reverse_cost FROM edges$$); ERROR: Graph is not DAG +HINT: CONTEXT: SQL function "pgr_topologicalsort" statement 1 /* -- q4 */ ROLLBACK; diff --git a/docqueries/topology/CMakeLists.txt b/docqueries/topology/CMakeLists.txt index 7466f209d7e..0d78f52ed87 100644 --- a/docqueries/topology/CMakeLists.txt +++ b/docqueries/topology/CMakeLists.txt @@ -1,11 +1,11 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_analyzeGraph - doc-pgr_analyzeOneWay - doc-pgr_createTopology - doc-pgr_createVerticesTable - doc-pgr_extractVertices - doc-pgr_nodeNetwork + analyzeGraph + analyzeOneWay + createTopology + createVerticesTable + extractVertices + nodeNetwork degree ) diff --git a/docqueries/topology/doc-pgr_analyzeGraph.test.sql b/docqueries/topology/analyzeGraph.pg similarity index 100% rename from docqueries/topology/doc-pgr_analyzeGraph.test.sql rename to docqueries/topology/analyzeGraph.pg diff --git a/docqueries/topology/doc-pgr_analyzeGraph.result b/docqueries/topology/analyzeGraph.result similarity index 100% rename from docqueries/topology/doc-pgr_analyzeGraph.result rename to docqueries/topology/analyzeGraph.result diff --git a/docqueries/topology/doc-pgr_analyzeOneWay.test.sql b/docqueries/topology/analyzeOneWay.pg similarity index 100% rename from docqueries/topology/doc-pgr_analyzeOneWay.test.sql rename to docqueries/topology/analyzeOneWay.pg diff --git a/docqueries/topology/doc-pgr_analyzeOneWay.result b/docqueries/topology/analyzeOneWay.result similarity index 100% rename from docqueries/topology/doc-pgr_analyzeOneWay.result rename to docqueries/topology/analyzeOneWay.result diff --git a/docqueries/topology/doc-pgr_createTopology.test.sql b/docqueries/topology/createTopology.pg similarity index 100% rename from docqueries/topology/doc-pgr_createTopology.test.sql rename to docqueries/topology/createTopology.pg diff --git a/docqueries/topology/doc-pgr_createTopology.result b/docqueries/topology/createTopology.result similarity index 100% rename from docqueries/topology/doc-pgr_createTopology.result rename to docqueries/topology/createTopology.result diff --git a/docqueries/topology/createVertTab-any.test.sql b/docqueries/topology/createVertTab-any.pg similarity index 100% rename from docqueries/topology/createVertTab-any.test.sql rename to docqueries/topology/createVertTab-any.pg diff --git a/docqueries/topology/doc-pgr_createVerticesTable.test.sql b/docqueries/topology/createVerticesTable.pg similarity index 100% rename from docqueries/topology/doc-pgr_createVerticesTable.test.sql rename to docqueries/topology/createVerticesTable.pg diff --git a/docqueries/topology/doc-pgr_createVerticesTable.result b/docqueries/topology/createVerticesTable.result similarity index 100% rename from docqueries/topology/doc-pgr_createVerticesTable.result rename to docqueries/topology/createVerticesTable.result diff --git a/docqueries/topology/degree.test.sql b/docqueries/topology/degree.pg similarity index 100% rename from docqueries/topology/degree.test.sql rename to docqueries/topology/degree.pg diff --git a/docqueries/topology/doc-pgr_extractVertices.test.sql b/docqueries/topology/extractVertices.pg similarity index 100% rename from docqueries/topology/doc-pgr_extractVertices.test.sql rename to docqueries/topology/extractVertices.pg diff --git a/docqueries/topology/doc-pgr_extractVertices.result b/docqueries/topology/extractVertices.result similarity index 100% rename from docqueries/topology/doc-pgr_extractVertices.result rename to docqueries/topology/extractVertices.result diff --git a/docqueries/topology/issue900.test.sql b/docqueries/topology/issue900.pg similarity index 100% rename from docqueries/topology/issue900.test.sql rename to docqueries/topology/issue900.pg diff --git a/docqueries/topology/doc-pgr_nodeNetwork.test.sql b/docqueries/topology/nodeNetwork.pg similarity index 100% rename from docqueries/topology/doc-pgr_nodeNetwork.test.sql rename to docqueries/topology/nodeNetwork.pg diff --git a/docqueries/topology/doc-pgr_nodeNetwork.result b/docqueries/topology/nodeNetwork.result similarity index 100% rename from docqueries/topology/doc-pgr_nodeNetwork.result rename to docqueries/topology/nodeNetwork.result diff --git a/docqueries/topology/test.conf b/docqueries/topology/test.conf index c821ed980c5..de6a9bfd292 100644 --- a/docqueries/topology/test.conf +++ b/docqueries/topology/test.conf @@ -2,34 +2,17 @@ %main::tests = ( 'any' => { - 'comment' => 'pgr_createTopology, pgr_analyzegraph, and pgr_analyzeOneway tests for any versions.', - 'data' => [ ], - 'tests' => [qw( - issue900 - createVertTab-any - doc-pgr_createTopology - doc-pgr_createVerticesTable - doc-pgr_analyzeGraph - doc-pgr_analyzeOneWay - doc-pgr_nodeNetwork - doc-pgr_extractVertices - degree + 'files' => [qw( + issue900.pg + createVertTab-any.pg + createTopology.pg + createVerticesTable.pg + analyzeGraph.pg + analyzeOneWay.pg + nodeNetwork.pg + extractVertices.pg + degree.pg )], - - 'documentation' => [qw( - doc-pgr_analyzeGraph - doc-pgr_createTopology - doc-pgr_nodeNetwork - doc-pgr_analyzeOneWay - doc-pgr_createVerticesTable - doc-pgr_extractVertices - doc-pgr_analyzeGraph - degree - )], - - 'dummyStorage' => [qw( - )] - }, ); diff --git a/docqueries/transitiveClosure/CMakeLists.txt b/docqueries/transitiveClosure/CMakeLists.txt index f3c4890009e..1f7502b1da9 100644 --- a/docqueries/transitiveClosure/CMakeLists.txt +++ b/docqueries/transitiveClosure/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - doc-transitiveClosure + transitiveClosure ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/transitiveClosure/test.conf b/docqueries/transitiveClosure/test.conf index 1aef5993762..11e49e0b23f 100644 --- a/docqueries/transitiveClosure/test.conf +++ b/docqueries/transitiveClosure/test.conf @@ -2,13 +2,8 @@ %main::tests = ( 'any' => { - 'comment' => 'transitiveClosure algorithm tests.', - 'data' => [ ], - 'tests' => [qw( - doc-transitiveClosure - )], - 'documentation' => [qw( - doc-transitiveClosure + 'files' => [qw( + transitiveClosure.pg )] }, diff --git a/docqueries/transitiveClosure/doc-transitiveClosure.test.sql b/docqueries/transitiveClosure/transitiveClosure.pg similarity index 100% rename from docqueries/transitiveClosure/doc-transitiveClosure.test.sql rename to docqueries/transitiveClosure/transitiveClosure.pg diff --git a/docqueries/transitiveClosure/doc-transitiveClosure.result b/docqueries/transitiveClosure/transitiveClosure.result similarity index 100% rename from docqueries/transitiveClosure/doc-transitiveClosure.result rename to docqueries/transitiveClosure/transitiveClosure.result diff --git a/docqueries/traversal/CMakeLists.txt b/docqueries/traversal/CMakeLists.txt index eae0c3f6817..6bc7709c8fc 100644 --- a/docqueries/traversal/CMakeLists.txt +++ b/docqueries/traversal/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_depthFirstSearch + depthFirstSearch ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/traversal/doc-pgr_depthFirstSearch.test.sql b/docqueries/traversal/depthFirstSearch.pg similarity index 100% rename from docqueries/traversal/doc-pgr_depthFirstSearch.test.sql rename to docqueries/traversal/depthFirstSearch.pg diff --git a/docqueries/traversal/doc-pgr_depthFirstSearch.result b/docqueries/traversal/depthFirstSearch.result similarity index 100% rename from docqueries/traversal/doc-pgr_depthFirstSearch.result rename to docqueries/traversal/depthFirstSearch.result diff --git a/docqueries/traversal/test.conf b/docqueries/traversal/test.conf index 22d6d906fee..816840fe485 100644 --- a/docqueries/traversal/test.conf +++ b/docqueries/traversal/test.conf @@ -2,13 +2,8 @@ %main::tests = ( 'any' => { - 'comment' => 'Depth First Search algorithm tests.', - 'data' => [ ], - 'tests' => [qw( - doc-pgr_depthFirstSearch - )], - 'documentation' => [qw( - doc-pgr_depthFirstSearch + 'files' => [qw( + depthFirstSearch.pg )] }, diff --git a/docqueries/trsp/CMakeLists.txt b/docqueries/trsp/CMakeLists.txt index 87252d02426..a3636ad44d2 100644 --- a/docqueries/trsp/CMakeLists.txt +++ b/docqueries/trsp/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - doc-trsp + trsp trsp_withPoints trspVia trspVia_withPoints diff --git a/docqueries/trsp/four_edges.test.sql b/docqueries/trsp/four_edges.pg similarity index 100% rename from docqueries/trsp/four_edges.test.sql rename to docqueries/trsp/four_edges.pg diff --git a/docqueries/trsp/issue693.test.sql b/docqueries/trsp/issue693.pg similarity index 100% rename from docqueries/trsp/issue693.test.sql rename to docqueries/trsp/issue693.pg diff --git a/docqueries/trsp/issue704.test.sql b/docqueries/trsp/issue704.pg similarity index 100% rename from docqueries/trsp/issue704.test.sql rename to docqueries/trsp/issue704.pg diff --git a/docqueries/trsp/issue717.test.sql b/docqueries/trsp/issue717.pg similarity index 100% rename from docqueries/trsp/issue717.test.sql rename to docqueries/trsp/issue717.pg diff --git a/docqueries/trsp/test.conf b/docqueries/trsp/test.conf index 7978fa4fd32..c8a12420d63 100644 --- a/docqueries/trsp/test.conf +++ b/docqueries/trsp/test.conf @@ -2,32 +2,21 @@ %main::tests = ( 'any' => { - 'comment' => 'TRSP test for any versions.', 'data' => ['trsp-issue244.data'], - 'tests' => [qw( - trsp-renumber - doc-trsp - trsp_withPoints - trspVia - trspVia_withPoints - trsp-any-02 - trsp_vias-any-04 - issue693 - issue704 - issue717 - four_edges + 'files' => [qw( + trsp-renumber.pg + trsp.pg + trsp_withPoints.pg + trspVia.pg + trspVia_withPoints.pg + trsp-any-02.pg + trsp_vias-any-04.pg + issue693.pg + issue704.pg + issue717.pg + four_edges.pg )], - 'documentation' => [qw( - doc-trsp - trsp_withPoints - trspVia - trspVia_withPoints - )] }, - -# 'vpg-vpgis' => {}, # for version specific tests -# '8-1' => {}, # for pg 8.x and postgis 1.x -# '9.2-2.1' => {}, # for pg 9.2 and postgis 2.1 ); 1; diff --git a/docqueries/trsp/trsp-any-02.test.sql b/docqueries/trsp/trsp-any-02.pg similarity index 100% rename from docqueries/trsp/trsp-any-02.test.sql rename to docqueries/trsp/trsp-any-02.pg diff --git a/docqueries/trsp/trsp-renumber.test.sql b/docqueries/trsp/trsp-renumber.pg similarity index 100% rename from docqueries/trsp/trsp-renumber.test.sql rename to docqueries/trsp/trsp-renumber.pg diff --git a/docqueries/trsp/doc-trsp.test.sql b/docqueries/trsp/trsp.pg similarity index 100% rename from docqueries/trsp/doc-trsp.test.sql rename to docqueries/trsp/trsp.pg diff --git a/docqueries/trsp/doc-trsp.result b/docqueries/trsp/trsp.result similarity index 100% rename from docqueries/trsp/doc-trsp.result rename to docqueries/trsp/trsp.result diff --git a/docqueries/trsp/trspVia.test.sql b/docqueries/trsp/trspVia.pg similarity index 100% rename from docqueries/trsp/trspVia.test.sql rename to docqueries/trsp/trspVia.pg diff --git a/docqueries/trsp/trspVia_withPoints.test.sql b/docqueries/trsp/trspVia_withPoints.pg similarity index 100% rename from docqueries/trsp/trspVia_withPoints.test.sql rename to docqueries/trsp/trspVia_withPoints.pg diff --git a/docqueries/trsp/trsp_vias-any-04.test.sql b/docqueries/trsp/trsp_vias-any-04.pg similarity index 100% rename from docqueries/trsp/trsp_vias-any-04.test.sql rename to docqueries/trsp/trsp_vias-any-04.pg diff --git a/docqueries/trsp/trsp_withPoints.test.sql b/docqueries/trsp/trsp_withPoints.pg similarity index 100% rename from docqueries/trsp/trsp_withPoints.test.sql rename to docqueries/trsp/trsp_withPoints.pg diff --git a/docqueries/tsp/CMakeLists.txt b/docqueries/tsp/CMakeLists.txt index 375dd9173e5..69b00b58c3a 100644 --- a/docqueries/tsp/CMakeLists.txt +++ b/docqueries/tsp/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_TSPeuclidean - doc-pgr_TSP + TSPeuclidean + TSP ) configure_file("wi29.sql" "${PGR_DOCUMENTATION_SOURCE_DIR}/wi29.queries") diff --git a/docqueries/tsp/doc-pgr_TSP.test.sql b/docqueries/tsp/TSP.pg similarity index 100% rename from docqueries/tsp/doc-pgr_TSP.test.sql rename to docqueries/tsp/TSP.pg diff --git a/docqueries/tsp/doc-pgr_TSP.result b/docqueries/tsp/TSP.result similarity index 100% rename from docqueries/tsp/doc-pgr_TSP.result rename to docqueries/tsp/TSP.result diff --git a/docqueries/tsp/doc-pgr_TSPeuclidean.test.sql b/docqueries/tsp/TSPeuclidean.pg similarity index 100% rename from docqueries/tsp/doc-pgr_TSPeuclidean.test.sql rename to docqueries/tsp/TSPeuclidean.pg diff --git a/docqueries/tsp/doc-pgr_TSPeuclidean.result b/docqueries/tsp/TSPeuclidean.result similarity index 100% rename from docqueries/tsp/doc-pgr_TSPeuclidean.result rename to docqueries/tsp/TSPeuclidean.result diff --git a/docqueries/tsp/test.conf b/docqueries/tsp/test.conf index 306060ce736..869bc11e814 100644 --- a/docqueries/tsp/test.conf +++ b/docqueries/tsp/test.conf @@ -2,15 +2,10 @@ %main::tests = ( 'any' => { - 'comment' => 'TSP tests', 'data' => ['wi29.sql'], - 'tests' => [qw( - doc-pgr_TSPeuclidean - doc-pgr_TSP - )], - 'documentation' => [qw( - doc-pgr_TSPeuclidean - doc-pgr_TSP + 'files' => [qw( + TSPeuclidean.pg + TSP.pg )] }, ); diff --git a/docqueries/utilities/findCloseEdges.test.sql b/docqueries/utilities/findCloseEdges.pg similarity index 100% rename from docqueries/utilities/findCloseEdges.test.sql rename to docqueries/utilities/findCloseEdges.pg diff --git a/docqueries/utilities/test.conf b/docqueries/utilities/test.conf index 1a785c21824..d7ea922f6b5 100644 --- a/docqueries/utilities/test.conf +++ b/docqueries/utilities/test.conf @@ -2,13 +2,8 @@ %main::tests = ( 'any' => { - 'comment' => 'Utilites example queries.', - 'data' => [ ], - 'tests' => [qw( - findCloseEdges - )], - 'documentation' => [qw( - findCloseEdges + 'files' => [qw( + findCloseEdges.pg )] }, ); diff --git a/docqueries/version/CMakeLists.txt b/docqueries/version/CMakeLists.txt index 304b591291c..42e8d8a427f 100644 --- a/docqueries/version/CMakeLists.txt +++ b/docqueries/version/CMakeLists.txt @@ -1,7 +1,7 @@ # Do not use extensions SET(LOCAL_FILES - doc-version - doc-full_version + version + full_version ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/version/doc-full_version.test.sql b/docqueries/version/full_version.pg similarity index 100% rename from docqueries/version/doc-full_version.test.sql rename to docqueries/version/full_version.pg diff --git a/docqueries/version/doc-full_version.result b/docqueries/version/full_version.result similarity index 88% rename from docqueries/version/doc-full_version.result rename to docqueries/version/full_version.result index f7344703cb0..8df58803fb4 100644 --- a/docqueries/version/doc-full_version.result +++ b/docqueries/version/full_version.result @@ -6,7 +6,7 @@ SET SELECT version, library FROM pgr_full_version(); version | library ---------+----------------- - 3.6.3 | pgrouting-3.6.3 + 3.7.0 | pgrouting-3.7.0 (1 row) /* -- q2 */ diff --git a/docqueries/version/test.conf b/docqueries/version/test.conf index 81cf944ae12..54c89cf12a6 100644 --- a/docqueries/version/test.conf +++ b/docqueries/version/test.conf @@ -2,21 +2,10 @@ %main::tests = ( 'any' => { - 'comment' => 'pgr_createTopology, pgr_analyzegraph, and pgr_analyzeOneway tests for any versions.', - 'data' => ['sampledata.data'], - 'tests' => [qw( - doc-version - doc-full_version + 'files' => [qw( + version.pg + full_version.pg )], - - 'documentation' => [qw( - doc-version - doc-full_version - )], - - 'dummyStorage' => [qw( - )] - }, ); diff --git a/docqueries/version/doc-version.test.sql b/docqueries/version/version.pg similarity index 100% rename from docqueries/version/doc-version.test.sql rename to docqueries/version/version.pg diff --git a/docqueries/version/doc-version.result b/docqueries/version/version.result similarity index 95% rename from docqueries/version/doc-version.result rename to docqueries/version/version.result index 7884e6eb855..d8fb9ee349f 100644 --- a/docqueries/version/doc-version.result +++ b/docqueries/version/version.result @@ -6,7 +6,7 @@ SET SELECT pgr_version(); pgr_version ------------- - 3.6.3 + 3.7.0 (1 row) /* -- q2 */ diff --git a/docqueries/vrp_basic/CMakeLists.txt b/docqueries/vrp_basic/CMakeLists.txt index 6f3cd2f1614..b350952e7f2 100644 --- a/docqueries/vrp_basic/CMakeLists.txt +++ b/docqueries/vrp_basic/CMakeLists.txt @@ -1,6 +1,6 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_vrpOneDepot + vrpOneDepot ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/vrp_basic/oneDepotWrapper.test.sql b/docqueries/vrp_basic/oneDepotWrapper.pg similarity index 100% rename from docqueries/vrp_basic/oneDepotWrapper.test.sql rename to docqueries/vrp_basic/oneDepotWrapper.pg diff --git a/docqueries/vrp_basic/test.conf b/docqueries/vrp_basic/test.conf index bcbd4d65014..63f256698ed 100644 --- a/docqueries/vrp_basic/test.conf +++ b/docqueries/vrp_basic/test.conf @@ -2,13 +2,9 @@ %main::tests = ( 'any' => { - 'comment' => 'VRP Single depot test for any versions.', 'data' => ['../../tools/testers/solomon_100_rc101.data.sql'], - 'tests' => [qw( - doc-pgr_vrpOneDepot - )], - 'documentation' => [qw( - doc-pgr_vrpOneDepot + 'files' => [qw( + vrpOneDepot.pg )] }, ); diff --git a/docqueries/vrp_basic/doc-pgr_vrpOneDepot.test.sql b/docqueries/vrp_basic/vrpOneDepot.pg similarity index 100% rename from docqueries/vrp_basic/doc-pgr_vrpOneDepot.test.sql rename to docqueries/vrp_basic/vrpOneDepot.pg diff --git a/docqueries/vrp_basic/doc-pgr_vrpOneDepot.result b/docqueries/vrp_basic/vrpOneDepot.result similarity index 100% rename from docqueries/vrp_basic/doc-pgr_vrpOneDepot.result rename to docqueries/vrp_basic/vrpOneDepot.result diff --git a/docqueries/withPoints/CMakeLists.txt b/docqueries/withPoints/CMakeLists.txt index 6d1a2860606..a20fdf84cb0 100644 --- a/docqueries/withPoints/CMakeLists.txt +++ b/docqueries/withPoints/CMakeLists.txt @@ -1,10 +1,10 @@ # Do not use extensions SET(LOCAL_FILES - doc-pgr_withPointsCostMatrix - doc-pgr_withPointsCost - doc-pgr_withPointsDD - doc-pgr_withPointsKSP - doc-pgr_withPoints + withPointsCostMatrix + withPointsCost + withPointsDD + withPointsKSP + withPoints withPointsVia ) diff --git a/docqueries/withPoints/test.conf b/docqueries/withPoints/test.conf index e7f7ac8e12a..6ad1789e0fa 100644 --- a/docqueries/withPoints/test.conf +++ b/docqueries/withPoints/test.conf @@ -2,23 +2,14 @@ %main::tests = ( 'any' => { - 'comment' => 'Function test for any versions.', 'data' => ['sampledata.data'], - 'tests' => [qw( - doc-pgr_withPoints - doc-pgr_withPointsCost - doc-pgr_withPointsCostMatrix - doc-pgr_withPointsDD - doc-pgr_withPointsKSP - withPointsVia - )], - 'documentation' => [qw( - doc-pgr_withPoints - doc-pgr_withPointsCost - doc-pgr_withPointsCostMatrix - doc-pgr_withPointsDD - doc-pgr_withPointsKSP - withPointsVia + 'files' => [qw( + withPoints.pg + withPointsCost.pg + withPointsCostMatrix.pg + withPointsDD.pg + withPointsKSP.pg + withPointsVia.pg )], }, ); diff --git a/docqueries/withPoints/doc-pgr_withPoints.test.sql b/docqueries/withPoints/withPoints.pg similarity index 100% rename from docqueries/withPoints/doc-pgr_withPoints.test.sql rename to docqueries/withPoints/withPoints.pg diff --git a/docqueries/withPoints/doc-pgr_withPoints.result b/docqueries/withPoints/withPoints.result similarity index 100% rename from docqueries/withPoints/doc-pgr_withPoints.result rename to docqueries/withPoints/withPoints.result diff --git a/docqueries/withPoints/doc-pgr_withPointsCost.test.sql b/docqueries/withPoints/withPointsCost.pg similarity index 100% rename from docqueries/withPoints/doc-pgr_withPointsCost.test.sql rename to docqueries/withPoints/withPointsCost.pg diff --git a/docqueries/withPoints/doc-pgr_withPointsCost.result b/docqueries/withPoints/withPointsCost.result similarity index 100% rename from docqueries/withPoints/doc-pgr_withPointsCost.result rename to docqueries/withPoints/withPointsCost.result diff --git a/docqueries/withPoints/doc-pgr_withPointsCostMatrix.test.sql b/docqueries/withPoints/withPointsCostMatrix.pg similarity index 100% rename from docqueries/withPoints/doc-pgr_withPointsCostMatrix.test.sql rename to docqueries/withPoints/withPointsCostMatrix.pg diff --git a/docqueries/withPoints/doc-pgr_withPointsCostMatrix.result b/docqueries/withPoints/withPointsCostMatrix.result similarity index 100% rename from docqueries/withPoints/doc-pgr_withPointsCostMatrix.result rename to docqueries/withPoints/withPointsCostMatrix.result diff --git a/docqueries/withPoints/doc-pgr_withPointsDD.test.sql b/docqueries/withPoints/withPointsDD.pg similarity index 100% rename from docqueries/withPoints/doc-pgr_withPointsDD.test.sql rename to docqueries/withPoints/withPointsDD.pg diff --git a/docqueries/withPoints/doc-pgr_withPointsDD.result b/docqueries/withPoints/withPointsDD.result similarity index 89% rename from docqueries/withPoints/doc-pgr_withPointsDD.result rename to docqueries/withPoints/withPointsDD.result index efef2cd6baf..73feef7dec6 100644 --- a/docqueries/withPoints/doc-pgr_withPointsDD.result +++ b/docqueries/withPoints/withPointsDD.result @@ -83,8 +83,8 @@ SELECT * FROM pgr_withPointsDD( 1 | 0 | -2 | -2 | -2 | -1 | 0 | 0 2 | 1 | -2 | -2 | 11 | 8 | 0.1 | 0.1 3 | 2 | -2 | 11 | 16 | 9 | 1 | 1.1 - 4 | 2 | -2 | 11 | 7 | 8 | 1 | 1.1 - 5 | 2 | -2 | 11 | 12 | 11 | 1 | 1.1 + 4 | 2 | -2 | 11 | 12 | 11 | 1 | 1.1 + 5 | 2 | -2 | 11 | 7 | 8 | 1 | 1.1 6 | 3 | -2 | 12 | 17 | 13 | 1 | 2.1 7 | 3 | -2 | 16 | 15 | 16 | 1 | 2.1 8 | 3 | -2 | 7 | 8 | 10 | 1 | 2.1 @@ -93,14 +93,14 @@ SELECT * FROM pgr_withPointsDD( 11 | 0 | -1 | -1 | -1 | -1 | 0 | 0 12 | 1 | -1 | -1 | 11 | 5 | 0.2 | 0.2 13 | 2 | -1 | 11 | 7 | 8 | 1 | 1.2 - 14 | 2 | -1 | 11 | 12 | 11 | 1 | 1.2 - 15 | 2 | -1 | 11 | 16 | 9 | 1 | 1.2 + 14 | 2 | -1 | 11 | 16 | 9 | 1 | 1.2 + 15 | 2 | -1 | 11 | 12 | 11 | 1 | 1.2 16 | 3 | -1 | 7 | -2 | 8 | 0.9 | 2.1 - 17 | 3 | -1 | 12 | 17 | 13 | 1 | 2.2 - 18 | 3 | -1 | 16 | 15 | 16 | 1 | 2.2 + 17 | 3 | -1 | 7 | 3 | 7 | 1 | 2.2 + 18 | 3 | -1 | 7 | 6 | 4 | 1 | 2.2 19 | 3 | -1 | 7 | 8 | 10 | 1 | 2.2 - 20 | 3 | -1 | 7 | 6 | 4 | 1 | 2.2 - 21 | 3 | -1 | 7 | 3 | 7 | 1 | 2.2 + 20 | 3 | -1 | 16 | 15 | 16 | 1 | 2.2 + 21 | 3 | -1 | 12 | 17 | 13 | 1 | 2.2 (21 rows) /* -- q6 */ diff --git a/docqueries/withPoints/doc-pgr_withPointsKSP.test.sql b/docqueries/withPoints/withPointsKSP.pg similarity index 100% rename from docqueries/withPoints/doc-pgr_withPointsKSP.test.sql rename to docqueries/withPoints/withPointsKSP.pg diff --git a/docqueries/withPoints/doc-pgr_withPointsKSP.result b/docqueries/withPoints/withPointsKSP.result similarity index 100% rename from docqueries/withPoints/doc-pgr_withPointsKSP.result rename to docqueries/withPoints/withPointsKSP.result diff --git a/docqueries/withPoints/withPointsVia.test.sql b/docqueries/withPoints/withPointsVia.pg similarity index 100% rename from docqueries/withPoints/withPointsVia.test.sql rename to docqueries/withPoints/withPointsVia.pg diff --git a/include/allpairs/pgr_allpairs.hpp b/include/allpairs/allpairs.hpp similarity index 96% rename from include/allpairs/pgr_allpairs.hpp rename to include/allpairs/allpairs.hpp index f322e546f86..a5058c96f94 100644 --- a/include/allpairs/pgr_allpairs.hpp +++ b/include/allpairs/allpairs.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_allpairs.hpp +File: allpairs.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // http://www.cs.rpi.edu/~musser/archive/2005/gsd/restricted/FloydWarshall/FloydWarshall.pdf -#ifndef INCLUDE_ALLPAIRS_PGR_ALLPAIRS_HPP_ -#define INCLUDE_ALLPAIRS_PGR_ALLPAIRS_HPP_ +#ifndef INCLUDE_ALLPAIRS_ALLPAIRS_HPP_ +#define INCLUDE_ALLPAIRS_ALLPAIRS_HPP_ #pragma once #include @@ -44,11 +44,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/iid_t_rt.h" #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" // TODO(vicky) don't keep it here -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/alloc.hpp" namespace pgrouting { template < class G > class Pgr_allpairs; @@ -263,4 +263,4 @@ class Pgr_allpairs { } // namespace pgrouting -#endif // INCLUDE_ALLPAIRS_PGR_ALLPAIRS_HPP_ +#endif // INCLUDE_ALLPAIRS_ALLPAIRS_HPP_ diff --git a/include/alphaShape/pgr_alphaShape.h b/include/alphaShape/alphaShape.hpp similarity index 88% rename from include/alphaShape/pgr_alphaShape.h rename to include/alphaShape/alphaShape.hpp index 066b72121eb..2dd463180c7 100644 --- a/include/alphaShape/pgr_alphaShape.h +++ b/include/alphaShape/alphaShape.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -file: pgr_alphaShape.h +File: alphaShape.hpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org @@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_ALPHASHAPE_PGR_ALPHASHAPE_H_ -#define INCLUDE_ALPHASHAPE_PGR_ALPHASHAPE_H_ +#ifndef INCLUDE_ALPHASHAPE_ALPHASHAPE_HPP_ +#define INCLUDE_ALPHASHAPE_ALPHASHAPE_HPP_ #pragma once #ifndef __cplusplus @@ -39,10 +39,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "c_types/edge_xy_t.h" -#include "cpp_common/pgr_messages.h" +#include "cpp_common/edge_xy_t.hpp" +#include "cpp_common/messages.hpp" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/base_graph.hpp" #include "cpp_common/bline.hpp" @@ -53,7 +53,7 @@ using BG = boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, XY_vertex, Basic_edge >; -using G = graph::Pgr_base_graph ; +using G = graph::Pgr_base_graph ; using E = boost::graph_traits::edge_descriptor; using V = boost::graph_traits::vertex_descriptor; @@ -99,4 +99,4 @@ class Pgr_alphaShape : public Pgr_messages { } // namespace alphashape } // namespace pgrouting -#endif // INCLUDE_ALPHASHAPE_PGR_ALPHASHAPE_H_ +#endif // INCLUDE_ALPHASHAPE_ALPHASHAPE_HPP_ diff --git a/include/astar/astar.hpp b/include/astar/astar.hpp index c68e62545a5..32736025f01 100644 --- a/include/astar/astar.hpp +++ b/include/astar/astar.hpp @@ -1,5 +1,4 @@ /*PGR-GNU***************************************************************** - File: astar.hpp Copyright (c) 2015 pgRouting developers @@ -27,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_ASTAR_PGR_ASTAR_HPP_ -#define INCLUDE_ASTAR_PGR_ASTAR_HPP_ +#ifndef INCLUDE_ASTAR_ASTAR_HPP_ +#define INCLUDE_ASTAR_ASTAR_HPP_ #pragma once #include @@ -41,8 +40,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "visitors/astar_visitors.hpp" #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "c_types/ii_t_rt.h" namespace detail { @@ -207,4 +206,4 @@ std::deque astar( } // namespace algorithms } // namespace pgrouting -#endif // INCLUDE_ASTAR_PGR_ASTAR_HPP_ +#endif // INCLUDE_ASTAR_ASTAR_HPP_ diff --git a/include/bdAstar/bdAstar.hpp b/include/bdAstar/bdAstar.hpp index 4b51856dddf..cbaa86a308b 100644 --- a/include/bdAstar/bdAstar.hpp +++ b/include/bdAstar/bdAstar.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_bdAstar.hpp +File: bdAstar.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_BDASTAR_PGR_BDASTAR_HPP_ -#define INCLUDE_BDASTAR_PGR_BDASTAR_HPP_ +#ifndef INCLUDE_BDASTAR_BDASTAR_HPP_ +#define INCLUDE_BDASTAR_BDASTAR_HPP_ #pragma once @@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_bidirectional.hpp" +#include "cpp_common/bidirectional.hpp" #include "cpp_common/basePath_SSEC.hpp" namespace pgrouting { @@ -223,4 +223,4 @@ std::deque bdastar( } // namespace algorithms } // namespace pgrouting -#endif // INCLUDE_BDASTAR_PGR_BDASTAR_HPP_ +#endif // INCLUDE_BDASTAR_BDASTAR_HPP_ diff --git a/include/bdDijkstra/pgr_bdDijkstra.hpp b/include/bdDijkstra/bdDijkstra.hpp similarity index 95% rename from include/bdDijkstra/pgr_bdDijkstra.hpp rename to include/bdDijkstra/bdDijkstra.hpp index f6637f55a0c..c698430b979 100644 --- a/include/bdDijkstra/pgr_bdDijkstra.hpp +++ b/include/bdDijkstra/bdDijkstra.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -File: pgr_bdDijkstra.hpp +File: bdDijkstra.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -26,13 +25,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_BDDIJKSTRA_PGR_BDDIJKSTRA_HPP_ -#define INCLUDE_BDDIJKSTRA_PGR_BDDIJKSTRA_HPP_ +#ifndef INCLUDE_BDDIJKSTRA_BDDIJKSTRA_HPP_ +#define INCLUDE_BDDIJKSTRA_BDDIJKSTRA_HPP_ #pragma once - -#include "cpp_common/pgr_bidirectional.hpp" - #include #include #include @@ -41,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include +#include "cpp_common/bidirectional.hpp" #include "cpp_common/basePath_SSEC.hpp" @@ -146,4 +143,4 @@ class Pgr_bdDijkstra : public Pgr_bidirectional { } // namespace bidirectional } // namespace pgrouting -#endif // INCLUDE_BDDIJKSTRA_PGR_BDDIJKSTRA_HPP_ +#endif // INCLUDE_BDDIJKSTRA_BDDIJKSTRA_HPP_ diff --git a/include/bellman_ford/bellman_ford.hpp b/include/bellman_ford/bellman_ford.hpp new file mode 100644 index 00000000000..06e704cfcc1 --- /dev/null +++ b/include/bellman_ford/bellman_ford.hpp @@ -0,0 +1,185 @@ +/*PGR-GNU***************************************************************** +File: bellman_ford.hpp + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2018 Sourabh Garg +Mail to: sourabh.garg.mat14@gmail.com + +------ + +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_BELLMAN_FORD_BELLMAN_FORD_HPP_ +#define INCLUDE_BELLMAN_FORD_BELLMAN_FORD_HPP_ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "cpp_common/messages.hpp" +#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" +#include "c_types/ii_t_rt.h" + +namespace pgrouting { + +template < class G > +class Pgr_bellman_ford : public pgrouting::Pgr_messages { + public: + typedef typename G::V V; + typedef typename G::E E; + //@{ + + + + /** @brief bellman_ford one to a set of many + * @todo document this function + */ + + std::deque bellman_ford( + G &graph, + int64_t start_vertex, + const std::set &end_vertex, + bool only_cost = false) { + // adjust predecessors and distances vectors + clear(); + predecessors.resize(graph.num_vertices()); + distances.resize(graph.num_vertices()); + + // get the graphs source and targets + if (!graph.has_vertex(start_vertex)) return std::deque(); + auto v_source(graph.get_V(start_vertex)); + + std::set s_v_targets; + for (const auto &vertex : end_vertex) { + if (graph.has_vertex(vertex)) { + s_v_targets.insert(graph.get_V(vertex)); + } + } + + std::vector v_targets(s_v_targets.begin(), s_v_targets.end()); + // perform the algorithm + bellman_ford_1_to_many(graph, v_source); + + // get the results // route id are the targets + auto paths = get_paths(graph, v_source, v_targets, only_cost); + + std::stable_sort(paths.begin(), paths.end(), + [](const Path &e1, const Path &e2)->bool { + return e1.end_id() < e2.end_id(); + }); + + return paths; + } + + + /** @brief BellmanFord combinations **/ + std::deque bellman_ford( + G &graph, + const std::map> &combinations, + bool only_cost = false) { + std::deque paths; + + for (const auto &comb : combinations) { + if (!graph.has_vertex(comb.first)) continue; + auto tmp_paths = bellman_ford(graph, comb.first, comb.second, only_cost); + paths.insert(paths.end(), tmp_paths.begin(), tmp_paths.end()); + } + + return paths; + } + + //@} + + private: + //! Call to BellmanFord 1 source to many targets + bool bellman_ford_1_to_many( + G &graph, + V source) { + log << std::string(__FUNCTION__) << "\n"; + /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ + CHECK_FOR_INTERRUPTS(); + try { + boost::bellman_ford_shortest_paths( + graph.graph, + static_cast(graph.num_vertices()), + boost::predecessor_map(&predecessors[0]) + .weight_map(get(&G::G_T_E::cost, graph.graph)) + .distance_map(&distances[0]) + .root_vertex(source)); + } catch (boost::exception const& ex) { + (void)ex; + throw; + } catch (std::exception &e) { + (void)e; + throw; + } catch (...) { + throw; + } + return true; + } + + + // To Empty predecessors and distances vector for each function call + void clear() { + predecessors.clear(); + distances.clear(); + } + + + // used when multiple goals + std::deque get_paths( + const G &graph, + V source, + std::vector< V > &targets, + bool only_cost) const { + std::deque paths; + for (const auto target : targets) { + paths.push_back(Path( + graph, + source, target, + predecessors, distances, + only_cost, true)); + } + return paths; + } + + + + //! @name members + //@{ + std::vector predecessors; + std::vector distances; + + //@} +}; + +} // namespace pgrouting + +#endif // INCLUDE_BELLMAN_FORD_BELLMAN_FORD_HPP_ diff --git a/include/bellman_ford/pgr_edwardMoore.hpp b/include/bellman_ford/edwardMoore.hpp similarity index 61% rename from include/bellman_ford/pgr_edwardMoore.hpp rename to include/bellman_ford/edwardMoore.hpp index 2c461ef0757..d85ef2e2d7c 100644 --- a/include/bellman_ford/pgr_edwardMoore.hpp +++ b/include/bellman_ford/edwardMoore.hpp @@ -1,7 +1,9 @@ /*PGR-GNU***************************************************************** -File: pgr_edwardMoore.hpp +File: edwardMoore.hpp + Copyright (c) 2019 pgRouting developers Mail: project@pgrouting.org + Copyright (c) 2019 Gudesa Venkata Sai AKhil Mail: gvs.akhil1997@gmail.com ------ @@ -18,19 +20,20 @@ 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_BELLMAN_FORD_PGR_EDWARDMOORE_HPP_ -#define INCLUDE_BELLMAN_FORD_PGR_EDWARDMOORE_HPP_ +#ifndef INCLUDE_BELLMAN_FORD_EDWARDMOORE_HPP_ +#define INCLUDE_BELLMAN_FORD_EDWARDMOORE_HPP_ #pragma once #include #include #include #include +#include #include #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "c_types/ii_t_rt.h" @@ -42,89 +45,38 @@ class Pgr_edwardMoore { public: typedef typename G::V V; typedef typename G::E E; - typedef typename G::B_G B_G; typedef typename G::EO_i EO_i; - typedef typename G::E_i E_i; - - std::deque edwardMoore( - G &graph, - const std::vector &start_vertex, - const std::vector &end_vertex) { - std::deque paths; - - for (const auto &source : start_vertex) { - std::deque result_paths = one_to_many_edwardMoore( - graph, - source, - end_vertex); - - paths.insert( - paths.begin(), - std::make_move_iterator(result_paths.begin()), - std::make_move_iterator(result_paths.end())); - } - - std::sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2) -> bool { - return e1.end_id() < e2.end_id(); - }); - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2) -> bool { - return e1.start_id() < e2.start_id(); - }); - return paths; - } - // preparation for the parallel arrays + /** @brief edwardMoore for combinations */ std::deque edwardMoore( G &graph, - const std::vector &combinations) { + const std::map> &combinations) { std::deque paths; - // group targets per distinct source - std::map< int64_t, std::vector > vertex_map; - for (const II_t_rt &comb : combinations) { - std::map< int64_t, std::vector >::iterator it = vertex_map.find(comb.d1.source); - if (it != vertex_map.end()) { - it->second.push_back(comb.d2.target); - } else { - std::vector targets{comb.d2.target}; - vertex_map[comb.d1.source] = targets; - } - } - - for (const auto &start_ends : vertex_map) { - std::deque result_paths = one_to_many_edwardMoore( - graph, - start_ends.first, - start_ends.second); - - paths.insert( - paths.end(), - std::make_move_iterator(result_paths.begin()), - std::make_move_iterator(result_paths.end())); - } - - std::sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2) -> bool { - return e1.end_id() < e2.end_id(); - }); - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2) -> bool { - return e1.start_id() < e2.start_id(); - }); - - return paths; + for (const auto &comb : combinations) { + if (!graph.has_vertex(comb.first)) continue; + auto tmp_paths = one_to_many_edwardMoore(graph, comb.first, comb.second); + paths.insert(paths.end(), tmp_paths.begin(), tmp_paths.end()); + } + std::sort(paths.begin(), paths.end(), + [](const Path &e1, const Path &e2) -> bool { + return e1.end_id() < e2.end_id(); + }); + std::stable_sort(paths.begin(), paths.end(), + [](const Path &e1, const Path &e2) -> bool { + return e1.start_id() < e2.start_id(); + }); + return paths; } private: - E DEFAULT_EDGE; + E default_edge; std::deque one_to_many_edwardMoore( G &graph, int64_t start_vertex, - std::vector end_vertex) { + const std::set &end_vertex) { std::deque paths; if (graph.has_vertex(start_vertex) == false) { @@ -135,7 +87,7 @@ class Pgr_edwardMoore { std::vector isInQ(graph.num_vertices(), false); std::vector from_edge(graph.num_vertices()); std::deque dq; - DEFAULT_EDGE = from_edge[0]; + default_edge = from_edge[0]; auto bgl_start_vertex = graph.get_V(start_vertex); @@ -159,7 +111,7 @@ class Pgr_edwardMoore { auto bgl_target_vertex = graph.get_V(target_vertex); - if (from_edge[bgl_target_vertex] == DEFAULT_EDGE) { + if (from_edge[bgl_target_vertex] == default_edge) { continue; } @@ -192,7 +144,7 @@ class Pgr_edwardMoore { path.push_back({graph[from].id, graph[e].id, graph[e].cost, current_cost[from], 0}); current_node = from; - } while (from_edge[current_node] != DEFAULT_EDGE); + } while (from_edge[current_node] != default_edge); std::reverse(path.begin(), path.end()); return path; @@ -237,4 +189,4 @@ class Pgr_edwardMoore { } // namespace functions } // namespace pgrouting -#endif // INCLUDE_BELLMAN_FORD_PGR_EDWARDMOORE_HPP_ +#endif // INCLUDE_BELLMAN_FORD_EDWARDMOORE_HPP_ diff --git a/include/bellman_ford/pgr_bellman_ford.hpp b/include/bellman_ford/pgr_bellman_ford.hpp deleted file mode 100644 index 2ed3299b367..00000000000 --- a/include/bellman_ford/pgr_bellman_ford.hpp +++ /dev/null @@ -1,318 +0,0 @@ -/*PGR-GNU***************************************************************** - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Copyright (c) 2018 Sourabh Garg -Mail to: sourabh.garg.mat14@gmail.com - ------- - -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_BELLMAN_FORD_PGR_BELLMAN_FORD_HPP_ -#define INCLUDE_BELLMAN_FORD_PGR_BELLMAN_FORD_HPP_ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "cpp_common/pgr_messages.h" -#include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" -#include "c_types/ii_t_rt.h" - - - - -//****************************************** -namespace pgrouting { - -template < class G > -class Pgr_bellman_ford : public pgrouting::Pgr_messages { - public: - typedef typename G::V V; - typedef typename G::E E; - //@} - - //! @name BellmanFord - //@{ - //! BellmanFord 1 to 1 - Path bellman_ford( - G &graph, - int64_t start_vertex, - int64_t end_vertex, - bool only_cost = false) { - clear(); - log << std::string(__FUNCTION__) << "\n"; - - // adjust predecessors and distances vectors - predecessors.resize(graph.num_vertices()); - distances.resize(graph.num_vertices()); - - - if (!graph.has_vertex(start_vertex) - || !graph.has_vertex(end_vertex)) { - return Path(start_vertex, end_vertex); - } - - // get the graphs source and target - auto v_source(graph.get_V(start_vertex)); - auto v_target(graph.get_V(end_vertex)); - - // perform the algorithm - bellman_ford_1_to_1(graph, v_source, v_target); - - // get the results - return Path( - graph, - v_source, v_target, - predecessors, distances, - only_cost, true); - } - - - //! BellmanFord 1 to many - std::deque bellman_ford( - G &graph, - int64_t start_vertex, - const std::vector< int64_t > &end_vertex, - bool only_cost = false) { - // adjust predecessors and distances vectors - clear(); - log << std::string(__FUNCTION__) << "\n"; - predecessors.resize(graph.num_vertices()); - distances.resize(graph.num_vertices()); - - // get the graphs source and target - if (!graph.has_vertex(start_vertex)) - return std::deque(); - auto v_source(graph.get_V(start_vertex)); - - std::set< V > s_v_targets; - for (const auto &vertex : end_vertex) { - if (graph.has_vertex(vertex)) { - s_v_targets.insert(graph.get_V(vertex)); - } - } - - std::vector< V > v_targets(s_v_targets.begin(), s_v_targets.end()); - // perform the algorithm - bellman_ford_1_to_many(graph, v_source); - - std::deque< Path > paths; - // get the results // route id are the targets - paths = get_paths(graph, v_source, v_targets, only_cost); - - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.end_id() < e2.end_id(); - }); - - return paths; - } - - // BellmanFord many to 1 - std::deque bellman_ford( - G &graph, - const std::vector < int64_t > &start_vertex, - int64_t end_vertex, - bool only_cost = false) { - std::deque paths; - log << std::string(__FUNCTION__) << "\n"; - for (const auto &start : start_vertex) { - paths.push_back( - bellman_ford(graph, start, end_vertex, only_cost)); - } - - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.start_id() < e2.start_id(); - }); - return paths; - } - - - // BellmanFord many to many - std::deque bellman_ford( - G &graph, - const std::vector< int64_t > &start_vertex, - const std::vector< int64_t > &end_vertex, - bool only_cost = false) { - // a call to 1 to many is faster for each of the sources - std::deque paths; - log << std::string(__FUNCTION__) << "\n"; - - for (const auto &start : start_vertex) { - auto r_paths = bellman_ford(graph, start, end_vertex, only_cost); - paths.insert(paths.begin(), r_paths.begin(), r_paths.end()); - } - - - std::sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.end_id() < e2.end_id(); - }); - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.start_id() < e2.start_id(); - }); - return paths; - } - - // BellmanFord combinations - std::deque bellman_ford( - G &graph, - const std::vector &combinations, - bool only_cost = false) { - // a call to 1 to many is faster for each of the sources - std::deque paths; - log << std::string(__FUNCTION__) << "\n"; - - // group targets per distinct source - std::map< int64_t, std::vector > vertex_map; - for (const II_t_rt &comb : combinations) { - std::map< int64_t, std::vector >::iterator it = vertex_map.find(comb.d1.source); - if (it != vertex_map.end()) { - it->second.push_back(comb.d2.target); - } else { - std::vector targets{comb.d2.target}; - vertex_map[comb.d1.source] = targets; - } - } - - for (const auto &start_ends : vertex_map) { - std::deque result_paths = bellman_ford( - graph, - start_ends.first, - start_ends.second, - only_cost); - paths.insert( - paths.end(), - std::make_move_iterator(result_paths.begin()), - std::make_move_iterator(result_paths.end())); - } - - return paths; - } - - //@} - - private: - //! Call to BellmanFord 1 source to 1 target - bool bellman_ford_1_to_1( - G &graph, - V source - ) { - log << std::string(__FUNCTION__) << "\n"; - /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ - CHECK_FOR_INTERRUPTS(); - try { - boost::bellman_ford_shortest_paths( - graph.graph, - static_cast(graph.num_vertices()), - boost::predecessor_map(&predecessors[0]) - .weight_map(get(&G::G_T_E::cost, graph.graph)) - .distance_map(&distances[0]) - .root_vertex(source)); - } catch (boost::exception const& ex) { - (void)ex; - throw; - } catch (std::exception &e) { - (void)e; - throw; - } catch (...) { - throw; - } - return true; - } - //! Call to BellmanFord 1 source to many targets - bool bellman_ford_1_to_many( - G &graph, - V source) { - log << std::string(__FUNCTION__) << "\n"; - /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ - CHECK_FOR_INTERRUPTS(); - try { - boost::bellman_ford_shortest_paths( - graph.graph, - static_cast(graph.num_vertices()), - boost::predecessor_map(&predecessors[0]) - .weight_map(get(&G::G_T_E::cost, graph.graph)) - .distance_map(&distances[0]) - .root_vertex(source)); - } catch (boost::exception const& ex) { - (void)ex; - throw; - } catch (std::exception &e) { - (void)e; - throw; - } catch (...) { - throw; - } - return true; - } - - - // To Empty predecessors and distances vector for each function call - void clear() { - predecessors.clear(); - distances.clear(); - } - - - // used when multiple goals - std::deque get_paths( - const G &graph, - V source, - std::vector< V > &targets, - bool only_cost) const { - log << std::string(__FUNCTION__) << "\n"; - std::deque paths; - for (const auto target : targets) { - paths.push_back(Path( - graph, - source, target, - predecessors, distances, - only_cost, true)); - } - return paths; - } - - - - //! @name members - //@{ - std::vector< V > predecessors; - std::vector< double > distances; - - //@} -}; - -} // namespace pgrouting - -#endif // INCLUDE_BELLMAN_FORD_PGR_BELLMAN_FORD_HPP_ diff --git a/include/bgraph/graph_to_edges.hpp b/include/bgraph/graph_to_edges.hpp new file mode 100644 index 00000000000..05e805e375e --- /dev/null +++ b/include/bgraph/graph_to_edges.hpp @@ -0,0 +1,88 @@ +/*PGR-GNU***************************************************************** +File: graph_to_edges.hpp + +Function's developer: +Copyright (c) 2024 Vicky Vergara +Mail: vicky at gmail.com + +------ + +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_BGRAPH_GRAPH_TO_EDGES_HPP_ +#define INCLUDE_BGRAPH_GRAPH_TO_EDGES_HPP_ + +#include +#include +#include + +#include +#include + +#include "cpp_common/edge_t.hpp" +#include "c_types/edge_rt.h" + +namespace pgrouting { +namespace b_g { + +/** @brief converts a bg to Edges_t + * @param[in] bg the boost graph + * @param[in] add_self_loop flagg to include self loops on the graph + * @returns a set of Edges_t that exist on the graph + * id, source, target, cost, reverse_cost + * source < target + */ +template +std::vector graph_to_existing_edges(const G &bg, bool add_self_loop) { + std::vector results; + + std::map, Edge_t> st_to_edge; + int64_t count = 0; + + auto bg_edges = boost::edges(bg); + for (auto e = bg_edges.first; e != bg_edges.second; ++e) { + auto s = bg[boost::source(*e, bg)].id; + auto t = bg[boost::target(*e, bg)].id; + + if (s == t && !add_self_loop) continue; + + /* + * Reverse edge already been added + */ + if (st_to_edge.find({t, s}) != st_to_edge.end()) { + st_to_edge[std::pair(t, s)].reverse_cost = 1.0; + continue; + } + + /* + * Already been added + */ + if (st_to_edge.find({s, t}) != st_to_edge.end()) continue; + + st_to_edge[std::pair(s, t)] = {++count, s, t, 1, -1}; + } + + for (const auto &st : st_to_edge) { + results.push_back(st.second); + } + return results; +} + +} // namespace b_g +} // namespace pgrouting + +#endif // INCLUDE_BGRAPH_GRAPH_TO_EDGES_HPP_ diff --git a/include/bgraph/line_graph.hpp b/include/bgraph/line_graph.hpp new file mode 100644 index 00000000000..4d6435e5179 --- /dev/null +++ b/include/bgraph/line_graph.hpp @@ -0,0 +1,86 @@ +/*PGR-GNU***************************************************************** +File: line_graph.hpp + +Function's developer: +Copyright (c) 2024 Vicky Vergara +Mail: vicky at gmail.com + +------ + +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_BGRAPH_LINE_GRAPH_HPP_ +#define INCLUDE_BGRAPH_LINE_GRAPH_HPP_ + +#include + +#include +#include + +#include "cpp_common/basic_vertex.hpp" +#include "cpp_common/basic_edge.hpp" + +namespace pgrouting { +namespace b_g { + +using B_G_R = boost::adjacency_list< + boost::vecS, boost::vecS, boost::undirectedS, + pgrouting::Basic_vertex, pgrouting::Basic_edge>; + +template +B_G_R line_graph(const B_G& original) { + using V = typename boost::graph_traits::vertex_descriptor; + using IndexMap = std::map; + + B_G_R result; + IndexMap id_to_descriptor; + + auto o_edges = boost::edges(original); + for (auto e = o_edges.first; e != o_edges.second; ++e) { + auto v = add_vertex(result); + result[v].id = original[*e].id; + id_to_descriptor[original[*e].id] = v; + } + + /* for (each vertex v in original graph) */ + auto vs = boost::vertices(original); + for (auto vertexIt = vs.first; vertexIt != vs.second; vertexIt++) { + auto vertex = *vertexIt; + + /* for( all incoming edges in to vertex v) */ + auto o_inedges = boost::in_edges(vertex, original); + for (auto ine = o_inedges.first; ine != o_inedges.second; ++ine) { + auto s = original[*ine].id; + + auto o_out_edges = boost::out_edges(vertex, original); + for (auto eout = o_out_edges.first; eout != o_out_edges.second; ++eout) { + /* for( all outgoing edges out from vertex v) */ + auto t = original[*eout].id; + auto rs = id_to_descriptor[s]; + auto rt = id_to_descriptor[t]; + auto e = boost::add_edge(rs, rt, result); + result[e.first].id = static_cast(num_edges(result)); + } + } + } + return result; +} + +} // namespace b_g +} // namespace pgrouting + +#endif // INCLUDE_BGRAPH_LINE_GRAPH_HPP_ diff --git a/include/breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp b/include/breadthFirstSearch/binaryBreadthFirstSearch.hpp similarity index 70% rename from include/breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp rename to include/breadthFirstSearch/binaryBreadthFirstSearch.hpp index f0e1f16cac4..605733b53be 100644 --- a/include/breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp +++ b/include/breadthFirstSearch/binaryBreadthFirstSearch.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_binaryBreadthFirstSearch.hpp +File: binaryBreadthFirstSearch.hpp Copyright (c) 2019 pgRouting developers Mail: project@pgrouting.org @@ -21,8 +21,8 @@ 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_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_ -#define INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_ +#ifndef INCLUDE_BREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_HPP_ +#define INCLUDE_BREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_HPP_ #pragma once #include @@ -30,11 +30,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include #include #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/assert.hpp" #include "c_types/ii_t_rt.h" @@ -50,6 +51,7 @@ class Pgr_binaryBreadthFirstSearch { typedef typename G::EO_i EO_i; typedef typename G::E_i E_i; + std::deque binaryBreadthFirstSearch( G &graph, const std::vector &start_vertex, @@ -57,51 +59,34 @@ class Pgr_binaryBreadthFirstSearch { std::deque paths; for (const auto &source : start_vertex) { - std::deque result_paths = one_to_many_binaryBreadthFirstSearch( + auto result_paths = one_to_many_binaryBreadthFirstSearch( graph, source, end_vertex); + std::sort(result_paths.begin(), result_paths.end(), + [](const Path &e1, const Path &e2) -> bool { + return e1.end_id() < e2.end_id(); + }); paths.insert( - paths.begin(), - std::make_move_iterator(result_paths.begin()), - std::make_move_iterator(result_paths.end())); + paths.begin(), + std::make_move_iterator(result_paths.begin()), + std::make_move_iterator(result_paths.end())); } - std::sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2) -> bool { - return e1.end_id() < e2.end_id(); - }); - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2) -> bool { - return e1.start_id() < e2.start_id(); - }); - return paths; } - // preparation for parallel arrays + std::deque binaryBreadthFirstSearch( G &graph, - const std::vector &combinations) { + const std::map> &combinations) { std::deque paths; - // group targets per distinct source - std::map< int64_t, std::vector > vertex_map; - for (const II_t_rt &comb : combinations) { - std::map< int64_t, std::vector >::iterator it = vertex_map.find(comb.d1.source); - if (it != vertex_map.end()) { - it->second.push_back(comb.d2.target); - } else { - std::vector targets{comb.d2.target}; - vertex_map[comb.d1.source] = targets; - } - } + for (const auto &c : combinations) { + if (!graph.has_vertex(c.first)) continue; - for (const auto &start_ends : vertex_map) { std::deque result_paths = one_to_many_binaryBreadthFirstSearch( - graph, - start_ends.first, - start_ends.second); + graph, c.first, c.second); paths.insert( paths.begin(), std::make_move_iterator(result_paths.begin()), @@ -121,22 +106,20 @@ class Pgr_binaryBreadthFirstSearch { } private: - E DEFAULT_EDGE; + E default_edge; std::deque one_to_many_binaryBreadthFirstSearch( - G &graph, + const G &graph, int64_t start_vertex, - std::vector end_vertex) { + const std::set &end_vertex) { std::deque paths; - if (graph.has_vertex(start_vertex) == false) { - return paths; - } + if (!graph.has_vertex(start_vertex)) return paths; std::vector current_cost(graph.num_vertices(), std::numeric_limits::infinity()); std::vector from_edge(graph.num_vertices()); std::deque dq; - DEFAULT_EDGE = from_edge[0]; + default_edge = from_edge[0]; auto bgl_start_vertex = graph.get_V(start_vertex); @@ -152,15 +135,11 @@ class Pgr_binaryBreadthFirstSearch { } for (auto target_vertex : end_vertex) { - if (graph.has_vertex(target_vertex) == false) { - continue; - } + if (!graph.has_vertex(target_vertex)) continue; auto bgl_target_vertex = graph.get_V(target_vertex); - if (from_edge[bgl_target_vertex] == DEFAULT_EDGE) { - continue; - } + if (from_edge[bgl_target_vertex] == default_edge) continue; paths.push_front( getPath(graph, bgl_start_vertex, target_vertex, bgl_target_vertex, from_edge, current_cost)); @@ -170,7 +149,7 @@ class Pgr_binaryBreadthFirstSearch { } Path getPath( - G &graph, + const G &graph, V bgl_start_vertex, int64_t target, V bgl_target_vertex, @@ -191,7 +170,7 @@ class Pgr_binaryBreadthFirstSearch { path.push_back({graph[from].id, graph[e].id, graph[e].cost, current_cost[from], 0}); current_node = from; - } while (from_edge[current_node] != DEFAULT_EDGE); + } while (from_edge[current_node] != default_edge); std::reverse(path.begin(), path.end()); return path; @@ -199,7 +178,7 @@ class Pgr_binaryBreadthFirstSearch { void updateVertexCosts( - G &graph, + const G &graph, std::vector ¤t_cost, std::vector &from_edge, std::deque &dq, @@ -234,4 +213,4 @@ class Pgr_binaryBreadthFirstSearch { } // namespace functions } // namespace pgrouting -#endif // INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_ +#endif // INCLUDE_BREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_HPP_ diff --git a/include/breadthFirstSearch/pgr_breadthFirstSearch.hpp b/include/breadthFirstSearch/breadthFirstSearch.hpp similarity index 88% rename from include/breadthFirstSearch/pgr_breadthFirstSearch.hpp rename to include/breadthFirstSearch/breadthFirstSearch.hpp index 942fb89f8cf..83e139ad583 100644 --- a/include/breadthFirstSearch/pgr_breadthFirstSearch.hpp +++ b/include/breadthFirstSearch/breadthFirstSearch.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_breadthFirstSearch.hpp +File: breadthFirstSearch.hpp Copyright (c) 2019 pgRouting developers Mail: project@pgrouting.org @@ -21,18 +21,20 @@ 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_BREADTHFIRSTSEARCH_PGR_BREADTHFIRSTSEARCH_HPP_ -#define INCLUDE_BREADTHFIRSTSEARCH_PGR_BREADTHFIRSTSEARCH_HPP_ +#ifndef INCLUDE_BREADTHFIRSTSEARCH_BREADTHFIRSTSEARCH_HPP_ +#define INCLUDE_BREADTHFIRSTSEARCH_BREADTHFIRSTSEARCH_HPP_ #pragma once #include +#include -#include +#include #include -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "c_types/mst_rt.h" +#include "visitors/edges_order_bfs_visitor.hpp" //****************************************** @@ -48,8 +50,8 @@ class Pgr_breadthFirstSearch { std::vector breadthFirstSearch( - G &graph, - std::vector start_vertex, + const G &graph, + const std::set &start_vertex, int64_t depth) { std::vector results; using bfs_visitor = visitors::Edges_order_bfs_visitor; @@ -110,4 +112,4 @@ class Pgr_breadthFirstSearch { } // namespace functions } // namespace pgrouting -#endif // INCLUDE_BREADTHFIRSTSEARCH_PGR_BREADTHFIRSTSEARCH_HPP_ +#endif // INCLUDE_BREADTHFIRSTSEARCH_BREADTHFIRSTSEARCH_HPP_ diff --git a/include/c_common/e_report.h b/include/c_common/e_report.h index 1f49b620ccf..d11ac238ba2 100644 --- a/include/c_common/e_report.h +++ b/include/c_common/e_report.h @@ -1,9 +1,6 @@ /*PGR-GNU***************************************************************** File: e_report.h -Copyright (c) 2016 pgRouting developers -Mail: project@pgrouting.org - Function's developer: Copyright (c) 2016 Celia Virginia Vergara Castillo Mail: vicky_vergara@hotmail.com @@ -56,7 +53,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ -///@{ /*! @brief notice & error * * ~~~~{.c} @@ -70,76 +66,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ void pgr_global_report( - char* log_msg, - char* notice_msg, - char* error_msg); - -/*! @brief notice with no hint - * - * ~~~~{.c} - * pgr_notice(&log_msg, ¬ice_msg); - * - * precondition: before calling ereport - * assert(!log_msg); - * assert(!notice_msg); - * ~~~~ - */ -void -pgr_notice( - char* notice_msg); - -/*! @brief notice with hint - * - * ~~~~{.c} - * pgr_notice(&log_msg, ¬ice_msg); - * - * precondition: before calling ereport - * assert(!log_msg); - * assert(!notice_msg); - * ~~~~ - */ -void -pgr_notice2( - char* log_msg, - char* notice_msg); - -/*! @brief error with no hint - * - * - * ~~~~{.c} - * if (err_msg) { - * pfree(); - * } - * pgr_error(&error_msg); - * - * precondition: before calling ereport - * assert(!*error_msg); - * ~~~~ - */ -void -pgr_error(char* error_msg); + char** log_msg, + char** notice_msg, + char** error_msg); /* @brief throws postgres error when first string is not null */ -void throw_error(char*, char*); - - -/*! @brief error with hint - * - * ~~~~{.c} - * if (err_msg) { - * pfree(); - * } - * pgr_error(&log_msg, &error_msg); - * - * precondition: before calling ereport - * assert(!*log_msg); - * assert(!*error_msg); - * ~~~~ - */ -void -pgr_error2( - char* log_msg, - char* error_msg); -///@} +void pgr_throw_error(char*, char*); #endif // INCLUDE_C_COMMON_E_REPORT_H_ diff --git a/include/c_common/pgdata_getters.h b/include/c_common/pgdata_getters.h deleted file mode 100644 index e28d5e03371..00000000000 --- a/include/c_common/pgdata_getters.h +++ /dev/null @@ -1,144 +0,0 @@ -/*PGR-GNU***************************************************************** -File: pgdata_getters.h - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Copyright (c) 2023 Celia Virginia Vergara Castillo -mail: vicky at erosion.dev -Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI -mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com -Copyright (c) 2016 Rohith Reddy -Copyright (c) 2016 Andrea Nardelli -mail: nrd.nardelli at gmail.com -Copyright (c) 2015 Celia Virginia Vergara Castillo -mail: vicky at erosion.dev - ------- - -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_C_COMMON_PGDATA_GETTERS_H_ -#define INCLUDE_C_COMMON_PGDATA_GETTERS_H_ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef __cplusplus -} -#endif - -#ifdef __cplusplus -#include -#include -#else -#include -#include -#include -#endif - -#ifdef __cplusplus -using IID_t_rt = struct IID_t_rt; -using II_t_rt = struct II_t_rt; -using Coordinate_t = struct Coordinate_t; -using Delauny_t = struct Delauny_t; -using Edge_xy_t = struct Edge_xy_t; -using Flow_t = struct Flow_t; -using Edge_bool_t = struct Edge_bool_t; -using CostFlow_t = struct CostFlow_t; -using Edge_t = struct Edge_t; -using Orders_t = struct Orders_t; -using Point_on_edge_t = struct Point_on_edge_t; -using Vehicle_t = struct Vehicle_t; -using Restriction_t = struct Restriction_t; -#else -typedef struct IID_t_rt IID_t_rt; -typedef struct II_t_rt II_t_rt; -typedef struct Coordinate_t Coordinate_t; -typedef struct Delauny_t Delauny_t; -typedef struct Edge_xy_t Edge_xy_t; -typedef struct Flow_t Flow_t; -typedef struct Edge_bool_t Edge_bool_t; -typedef struct CostFlow_t CostFlow_t; -typedef struct Edge_t Edge_t; -typedef struct Orders_t Orders_t; -typedef struct Point_on_edge_t Point_on_edge_t; -typedef struct Restriction_t Restriction_t; -typedef struct Vehicle_t Vehicle_t; -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -/** @brief Read rows of combinations, called from C file*/ -void pgr_get_combinations(char *, II_t_rt **, size_t *, char**); - -/** @brief Read rows of matrix, called from C file*/ -void pgr_get_coordinates(char*, Coordinate_t**, size_t*, char**); - -/** @brief Read rows of delauny triangles, called from C file*/ -void pgr_get_delauny(char*, Delauny_t**, size_t*, char**); - -/** @brief Read edges called from C file*/ -void pgr_get_edges(char*, Edge_t**, size_t*, bool, bool, char**); - -/** @brief Read edges with x, y endpointscalled from C file */ -void pgr_get_edges_xy(char*, Edge_xy_t**, size_t*, bool, char**); - -/** @brief Read edges for flow called from C file */ -void pgr_get_flow_edges(char*, Edge_t**, size_t*, char**); - -/** @brief Read edges for cost called from C fileflow */ -void pgr_get_costFlow_edges(char*, CostFlow_t**, size_t*, char**); - -/** @brief Read "basic edges" called from C file */ -void pgr_get_basic_edges(char*, Edge_bool_t**, size_t*, char**); - -/** @brief Read rows of matrix, called from C file*/ -void pgr_get_matrixRows(char*, IID_t_rt**, size_t *, char **); - -/** @brief Reads the pick-Deliver orders */ -void pgr_get_orders(char *, Orders_t **, size_t *, bool, char**); - -/** @brief Read rows of points, called from C file*/ -void pgr_get_points(char*, Point_on_edge_t**, size_t*, char**); - -/** @brief Read rows of matrix, called from C file*/ -void pgr_get_restrictions(char*, Restriction_t**, size_t*, char**); - -/** @brief Reads the vehicles */ -void pgr_get_vehicles(char*, Vehicle_t**, size_t*, bool, char**); - -/** @brief Enforces the input array to be @b NOT empty */ -int64_t* pgr_get_bigIntArray(size_t*, ArrayType*, bool, char**); - -#ifdef __cplusplus -} -#endif - -#endif // INCLUDE_C_COMMON_PGDATA_GETTERS_H_ diff --git a/include/c_common/postgres_connection.h b/include/c_common/postgres_connection.h index 26c5cfc02b6..0ebc9ff1af7 100644 --- a/include/c_common/postgres_connection.h +++ b/include/c_common/postgres_connection.h @@ -41,11 +41,13 @@ extern "C" { #include #include +#include "cpp_common/undefPostgresDefine.hpp" + void pgr_send_error(int errcode); void pgr_SPI_finish(void); void pgr_SPI_connect(void); -SPIPlanPtr pgr_SPI_prepare(char* sql); +SPIPlanPtr pgr_SPI_prepare(const char* sql); Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan); #ifdef __cplusplus diff --git a/include/c_common/time_msg.h b/include/c_common/time_msg.h index 04a6b9a560d..7e66b0f15b6 100644 --- a/include/c_common/time_msg.h +++ b/include/c_common/time_msg.h @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: time_msg.h +File: time_msg.h Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/include/c_common/trsp_pgget.h b/include/c_common/trsp_pgget.h new file mode 100644 index 00000000000..50a48ca771f --- /dev/null +++ b/include/c_common/trsp_pgget.h @@ -0,0 +1,98 @@ +/*PGR-GNU***************************************************************** +File: trsp_pgget.h + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2023 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev +Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI +mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com +Copyright (c) 2016 Rohith Reddy +Copyright (c) 2016 Andrea Nardelli +mail: nrd.nardelli at gmail.com +Copyright (c) 2015 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev + +------ + +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*/ +/** @file + +This is a copy of pgdata_getters.h + +The old version of TRSP +- Is the only function that has its own edge reader within its code, + hence the name of the file. +- The old version of TRSP will exist during 3.x series + + +@note +- The only function that remains is `fetch_edge` +- The old version of TRSP will be removed on V4 + + @todo: TODO V4 Delete this file +*/ +#ifndef INCLUDE_C_COMMON_TRSP_PGGET_H_ +#define INCLUDE_C_COMMON_TRSP_PGGET_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +#include +#include +#else +#include +#include +#include +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + +#ifdef __cplusplus +using Edge_t = struct Edge_rt; +#else +typedef struct Edge_rt Edge_t; +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief Read edges called from C file*/ +void pgr_get_edges(char*, Edge_t**, size_t*, bool, bool, char**); + +#ifdef __cplusplus +} +#endif + +#endif // INCLUDE_C_COMMON_TRSP_PGGET_H_ diff --git a/include/c_types/edge_t.h b/include/c_types/edge_rt.h similarity index 89% rename from include/c_types/edge_t.h rename to include/c_types/edge_rt.h index 48875764ac5..06f9c050ecd 100644 --- a/include/c_types/edge_t.h +++ b/include/c_types/edge_rt.h @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: Edge_t.h +File: edge_rt.h Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_EDGE_T_H_ -#define INCLUDE_C_TYPES_EDGE_T_H_ +#ifndef INCLUDE_C_TYPES_EDGE_RT_H_ +#define INCLUDE_C_TYPES_EDGE_RT_H_ #pragma once /* for int64_t */ @@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # include #endif -struct Edge_t{ +struct Edge_rt{ int64_t id; int64_t source; int64_t target; @@ -45,4 +45,4 @@ struct Edge_t{ double reverse_cost; }; -#endif // INCLUDE_C_TYPES_EDGE_T_H_ +#endif // INCLUDE_C_TYPES_EDGE_RT_H_ diff --git a/include/c_types/path_rt.h b/include/c_types/path_rt.h index bdaf0d2b231..4b940087293 100644 --- a/include/c_types/path_rt.h +++ b/include/c_types/path_rt.h @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #endif struct Path_rt { - int seq; int64_t start_id; int64_t end_id; int64_t node; diff --git a/include/c_types/routes_t.h b/include/c_types/routes_t.h index 2f56eb20309..1bfc791d140 100644 --- a/include/c_types/routes_t.h +++ b/include/c_types/routes_t.h @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_types.h +File: routes_t.h Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/include/c_types/pickDeliver/schedule_rt.h b/include/c_types/schedule_rt.h similarity index 90% rename from include/c_types/pickDeliver/schedule_rt.h rename to include/c_types/schedule_rt.h index 93abeba24a4..e9d708e3549 100644 --- a/include/c_types/pickDeliver/schedule_rt.h +++ b/include/c_types/schedule_rt.h @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: general_vehicle_orders_t.h +File: schedule_rt.h Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_PICKDELIVER_SCHEDULE_RT_H_ -#define INCLUDE_C_TYPES_PICKDELIVER_SCHEDULE_RT_H_ +#ifndef INCLUDE_C_TYPES_SCHEDULE_RT_H_ +#define INCLUDE_C_TYPES_SCHEDULE_RT_H_ #pragma once /* for int64_t */ @@ -66,4 +66,4 @@ struct Schedule_rt { /*************************************************************************/ -#endif // INCLUDE_C_TYPES_PICKDELIVER_SCHEDULE_RT_H_ +#endif // INCLUDE_C_TYPES_SCHEDULE_RT_H_ diff --git a/include/c_types/stoerWagner_t.h b/include/c_types/stoerWagner_t.h index 968559bded6..67bb43650f9 100644 --- a/include/c_types/stoerWagner_t.h +++ b/include/c_types/stoerWagner_t.h @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_stoerWagner_t.h +File: stoerWagner_t.h Copyright (c) 2015 Aditya Pratap Singh Mail: adityapratap.singh28@gmail.com diff --git a/include/c_types/transitiveClosure_rt.h b/include/c_types/transitiveClosure_rt.h index 98f407890d7..2b00808c7dc 100644 --- a/include/c_types/transitiveClosure_rt.h +++ b/include/c_types/transitiveClosure_rt.h @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: contracted_rt.h +File: transitiveClosure_rt.h Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org diff --git a/include/c_types/trsp/trsp.h b/include/c_types/trsp/trsp.h index d9925ad7e65..ea047b3cd89 100644 --- a/include/c_types/trsp/trsp.h +++ b/include/c_types/trsp/trsp.h @@ -33,21 +33,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #ifdef __cplusplus # include typedef int64_t int64; -typedef double float8; #else # include #endif struct restrict_t { int target_id; - float8 to_cost; + double to_cost; int via[MAX_RULE_LENGTH]; }; struct path_element_tt { - int64 vertex_id; - int64 edge_id; - float8 cost; + int64_t vertex_id; + int64_t edge_id; + double cost; }; diff --git a/include/chinese/pgr_chinesePostman.hpp b/include/chinese/chinesePostman.hpp similarity index 86% rename from include/chinese/pgr_chinesePostman.hpp rename to include/chinese/chinesePostman.hpp index 45827999bb2..501769a1113 100644 --- a/include/chinese/pgr_chinesePostman.hpp +++ b/include/chinese/chinesePostman.hpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: chinesePostman.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CHINESE_PGR_CHINESEPOSTMAN_HPP_ -#define INCLUDE_CHINESE_PGR_CHINESEPOSTMAN_HPP_ +#ifndef INCLUDE_CHINESE_CHINESEPOSTMAN_HPP_ +#define INCLUDE_CHINESE_CHINESEPOSTMAN_HPP_ #pragma once #include @@ -35,11 +36,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "max_flow/pgr_minCostMaxFlow.hpp" +#include "max_flow/minCostMaxFlow.hpp" #include "c_types/path_rt.h" -#include "c_types/edge_t.h" +#include "cpp_common/edge_t.hpp" #include "c_types/flow_t.h" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" #include "cpp_common/identifiers.hpp" @@ -48,9 +49,7 @@ namespace graph { class PgrDirectedChPPGraph { public: - PgrDirectedChPPGraph( - const Edge_t *dataEdges, - const size_t totalEdges); + explicit PgrDirectedChPPGraph(const std::vector&); double DirectedChPP() const { return m_cost; @@ -105,39 +104,36 @@ class PgrDirectedChPPGraph { PgrDirectedChPPGraph::~PgrDirectedChPPGraph() { edgeToIdx.clear(); } -PgrDirectedChPPGraph::PgrDirectedChPPGraph( - const Edge_t *dataEdges, - const size_t totalEdges) : +PgrDirectedChPPGraph::PgrDirectedChPPGraph(const std::vector &dataEdges) : totalDeg(0), totalCost(0), vertices(), edgeToIdx(), originalEdges(), resultGraph(), VToVecid(), edgeVisited(), pathStack(), resultPath(), edges(), sources(), targets() { - pgassert(totalEdges > 0); pgassert(pathStack.empty()); pgassert(originalEdges.empty()); startPoint = dataEdges[0].source; - for (size_t i = 0; i < totalEdges; ++i) { - if (dataEdges[i].cost > 0) { - auto edge(dataEdges[i]); + for (const auto e : dataEdges) { + if (e.cost > 0) { + auto edge = e; edge.reverse_cost = -1.0; totalCost += edge.cost; originalEdges.push_back(edge); - vertices += dataEdges[i].source; - vertices += dataEdges[i].target; + vertices += e.source; + vertices += e.target; } - if (dataEdges[i].reverse_cost > 0) { - auto edge(dataEdges[i]); + if (e.reverse_cost > 0) { + auto edge = e; std::swap(edge.source, edge.target); std::swap(edge.cost, edge.reverse_cost); edge.reverse_cost = -1.0; totalCost += edge.cost; originalEdges.push_back(edge); - vertices += dataEdges[i].source; - vertices += dataEdges[i].target; - pgassert(dataEdges[i].source == edge.target); - pgassert(dataEdges[i].target == edge.source); + vertices += e.source; + vertices += e.target; + pgassert(e.source == edge.target); + pgassert(e.target == edge.source); } } @@ -182,18 +178,13 @@ PgrDirectedChPPGraph::PgrDirectedChPPGraph( for (iter = deg.begin(); iter != deg.end(); ++iter) { int64_t p = iter->first; int d = iter->second; - if (d == 0) - continue; - if (d > 0) - totalDeg += d; - CostFlow_t edge; + if (d == 0) continue; + if (d > 0) totalDeg += d; + CostFlow_t edge = {}; edge.reverse_capacity = -1; edge.reverse_cost = -1.0; edge.cost = 0.0; - if (d > 0) - edge.capacity = d; - else - edge.capacity = -d; + edge.capacity = std::abs(d); edge.edge_id = 0; if (d > 0) edge.source = p, edge.target = superTarget; @@ -270,7 +261,7 @@ PgrDirectedChPPGraph::BuildResultPath() { int64_t preNode = pathStack.top(); pathStack.pop(); - Path_rt newElement; + Path_rt newElement = {}; while (!pathStack.empty()) { int64_t nowNode = pathStack.top(); pathStack.pop(); @@ -281,10 +272,8 @@ PgrDirectedChPPGraph::BuildResultPath() { newElement.cost = edge_t.cost; if (resultPath.empty()) { /* adding the first row because is a cycle */ - newElement.seq = 1; newElement.agg_cost = 0.0; } else { - newElement.seq = resultPath.back().seq + 1; newElement.agg_cost = resultPath.back().agg_cost + resultPath.back().cost; } resultPath.push_back(newElement); @@ -294,10 +283,8 @@ PgrDirectedChPPGraph::BuildResultPath() { newElement.edge = -1; newElement.cost = 0; if (resultPath.empty()) { - newElement.seq = 1; newElement.agg_cost = 0.0; } else { - newElement.seq = resultPath.back().seq + 1; newElement.agg_cost = resultPath.back().agg_cost + resultPath.back().cost; } @@ -343,4 +330,4 @@ PgrDirectedChPPGraph::BuildResultGraph() { } // namespace graph } // namespace pgrouting -#endif // INCLUDE_CHINESE_PGR_CHINESEPOSTMAN_HPP_ +#endif // INCLUDE_CHINESE_CHINESEPOSTMAN_HPP_ diff --git a/include/circuits/hawickcircuits.hpp b/include/circuits/hawickcircuits.hpp index 7e4a6590b8d..2367ecbe734 100644 --- a/include/circuits/hawickcircuits.hpp +++ b/include/circuits/hawickcircuits.hpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: hawickcircuits.hpp Copyright (c) 2022 pgRouting developers Mail: project@pgrouting.org @@ -37,9 +38,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" +#include "cpp_common/assert.hpp" #include "c_types/circuits_rt.h" /** diff --git a/include/coloring/pgr_bipartite_driver.hpp b/include/coloring/bipartite_driver.hpp similarity index 88% rename from include/coloring/pgr_bipartite_driver.hpp rename to include/coloring/bipartite_driver.hpp index 84abe2e0cd7..10589a5523e 100644 --- a/include/coloring/pgr_bipartite_driver.hpp +++ b/include/coloring/bipartite_driver.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_bipartite_driver.hpp +File: bipartite_driver.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -28,8 +28,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_COLORING_PGR_BIPARTITE_DRIVER_HPP_ -#define INCLUDE_COLORING_PGR_BIPARTITE_DRIVER_HPP_ +#ifndef INCLUDE_COLORING_BIPARTITE_DRIVER_HPP_ +#define INCLUDE_COLORING_BIPARTITE_DRIVER_HPP_ #pragma once #include @@ -41,10 +41,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/pgr_messages.h" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/messages.hpp" +#include "cpp_common/interruption.hpp" typedef struct II_t_rt II_t_rt; +#include "c_types/ii_t_rt.h" namespace pgrouting { namespace functions { @@ -78,7 +79,7 @@ class Pgr_Bipartite : public pgrouting::Pgr_messages { int64_t vid = graph[*v].id; boost::get(partition_map, *v) == boost::color_traits ::white() ? - results.push_back({{vid}, {0}}) :results.push_back({{vid}, {1}}); + results.push_back({{vid}, {0}}) : results.push_back({{vid}, {1}}); } return results; } @@ -92,4 +93,4 @@ class Pgr_Bipartite : public pgrouting::Pgr_messages { }; } // namespace functions } // namespace pgrouting -#endif // INCLUDE_COLORING_PGR_BIPARTITE_DRIVER_HPP_ +#endif // INCLUDE_COLORING_BIPARTITE_DRIVER_HPP_ diff --git a/include/coloring/pgr_edgeColoring.hpp b/include/coloring/edgeColoring.hpp similarity index 88% rename from include/coloring/pgr_edgeColoring.hpp rename to include/coloring/edgeColoring.hpp index 4e3b412d7ad..897b3f4aceb 100644 --- a/include/coloring/pgr_edgeColoring.hpp +++ b/include/coloring/edgeColoring.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_edgeColoring.hpp +File: edgeColoring.hpp Generated with Template by: Copyright (c) 2021 pgRouting developers @@ -23,8 +23,8 @@ 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_COLORING_PGR_EDGECOLORING_HPP_ -#define INCLUDE_COLORING_PGR_EDGECOLORING_HPP_ +#ifndef INCLUDE_COLORING_EDGECOLORING_HPP_ +#define INCLUDE_COLORING_EDGECOLORING_HPP_ #pragma once #include @@ -35,10 +35,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "c_types/edge_t.h" +#include "cpp_common/edge_t.hpp" #include "c_types/ii_t_rt.h" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_messages.h" +#include "cpp_common/assert.hpp" +#include "cpp_common/messages.hpp" namespace pgrouting { namespace functions { @@ -57,7 +57,7 @@ class Pgr_edgeColoring : public Pgr_messages { public: std::vector edgeColoring(); - Pgr_edgeColoring(Edge_t*, size_t); + explicit Pgr_edgeColoring(const std::vector&); Pgr_edgeColoring() = delete; #if BOOST_VERSION >= 106800 @@ -80,4 +80,4 @@ class Pgr_edgeColoring : public Pgr_messages { } // namespace functions } // namespace pgrouting -#endif // INCLUDE_COLORING_PGR_EDGECOLORING_HPP_ +#endif // INCLUDE_COLORING_EDGECOLORING_HPP_ diff --git a/include/coloring/pgr_sequentialVertexColoring.hpp b/include/coloring/sequentialVertexColoring.hpp similarity index 93% rename from include/coloring/pgr_sequentialVertexColoring.hpp rename to include/coloring/sequentialVertexColoring.hpp index 0fc5e611c0a..d9d3d117aa7 100644 --- a/include/coloring/pgr_sequentialVertexColoring.hpp +++ b/include/coloring/sequentialVertexColoring.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_sequentialVertexColoring.hpp +File: sequentialVertexColoring.hpp Copyright (c) 2020 pgRouting developers Mail: project@pgrouting.org @@ -21,8 +21,8 @@ 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_COLORING_PGR_SEQUENTIALVERTEXCOLORING_HPP_ -#define INCLUDE_COLORING_PGR_SEQUENTIALVERTEXCOLORING_HPP_ +#ifndef INCLUDE_COLORING_SEQUENTIALVERTEXCOLORING_HPP_ +#define INCLUDE_COLORING_SEQUENTIALVERTEXCOLORING_HPP_ #pragma once #include @@ -36,8 +36,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "c_types/ii_t_rt.h" @@ -146,4 +146,4 @@ class Pgr_sequentialVertexColoring { } // namespace functions } // namespace pgrouting -#endif // INCLUDE_COLORING_PGR_SEQUENTIALVERTEXCOLORING_HPP_ +#endif // INCLUDE_COLORING_SEQUENTIALVERTEXCOLORING_HPP_ diff --git a/include/components/pgr_components.hpp b/include/components/components.hpp similarity index 89% rename from include/components/pgr_components.hpp rename to include/components/components.hpp index 8167b976651..350bcc1738c 100644 --- a/include/components/pgr_components.hpp +++ b/include/components/components.hpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: components.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_COMPONENTS_PGR_COMPONENTS_HPP_ -#define INCLUDE_COMPONENTS_PGR_COMPONENTS_HPP_ +#ifndef INCLUDE_COMPONENTS_COMPONENTS_HPP_ +#define INCLUDE_COMPONENTS_COMPONENTS_HPP_ #pragma once #include @@ -39,9 +40,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/base_graph.hpp" #include "cpp_common/identifiers.hpp" -#include "components/componentsResult.h" +#include "components/componentsResult.hpp" namespace pgrouting { namespace algorithms { @@ -71,4 +72,4 @@ bridges(pgrouting::UndirectedGraph &graph); } // namespace algorithms } // namespace pgrouting -#endif // INCLUDE_COMPONENTS_PGR_COMPONENTS_HPP_ +#endif // INCLUDE_COMPONENTS_COMPONENTS_HPP_ diff --git a/include/components/componentsResult.h b/include/components/componentsResult.hpp similarity index 87% rename from include/components/componentsResult.h rename to include/components/componentsResult.hpp index 3b4d91c05f1..a91883f0cca 100644 --- a/include/components/componentsResult.h +++ b/include/components/componentsResult.hpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: componentsResult.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_COMPONENTS_COMPONENTSRESULT_H_ -#define INCLUDE_COMPONENTS_COMPONENTSRESULT_H_ +#ifndef INCLUDE_COMPONENTS_COMPONENTSRESULT_HPP_ +#define INCLUDE_COMPONENTS_COMPONENTSRESULT_HPP_ #pragma once #include @@ -47,4 +48,4 @@ componentsResult( } // namespace algorithms } // namespace pgrouting -#endif // INCLUDE_COMPONENTS_COMPONENTSRESULT_H_ +#endif // INCLUDE_COMPONENTS_COMPONENTSRESULT_HPP_ diff --git a/include/components/pgr_makeConnected.hpp b/include/components/makeConnected.hpp similarity index 91% rename from include/components/pgr_makeConnected.hpp rename to include/components/makeConnected.hpp index 1b3661f5b6e..89dbc3272bd 100644 --- a/include/components/pgr_makeConnected.hpp +++ b/include/components/makeConnected.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_makeConnected.hpp +File: makeConnected.hpp Copyright (c) 2020 pgRouting developers Mail: project@pgrouting.org @@ -21,8 +21,8 @@ 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_COMPONENTS_PGR_MAKECONNECTED_HPP_ -#define INCLUDE_COMPONENTS_PGR_MAKECONNECTED_HPP_ +#ifndef INCLUDE_COMPONENTS_MAKECONNECTED_HPP_ +#define INCLUDE_COMPONENTS_MAKECONNECTED_HPP_ #pragma once #include @@ -38,9 +38,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_types/ii_t_rt.h" -#include "cpp_common/pgr_messages.h" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/messages.hpp" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" //****************************************** namespace pgrouting { @@ -99,4 +99,4 @@ class Pgr_makeConnected : public pgrouting::Pgr_messages { } // namespace functions } // namespace pgrouting -#endif // INCLUDE_COMPONENTS_PGR_MAKECONNECTED_HPP_ +#endif // INCLUDE_COMPONENTS_MAKECONNECTED_HPP_ diff --git a/include/contraction/ch_graphs.hpp b/include/contraction/ch_graphs.hpp index c047d5b6db7..c71b99d06d6 100644 --- a/include/contraction/ch_graphs.hpp +++ b/include/contraction/ch_graphs.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_CH_graphs.hpp +File: ch_graphs.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -36,10 +36,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "contraction/pgr_contractionGraph.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/ch_vertex.h" -#include "cpp_common/ch_edge.h" +#include "contraction/contractionGraph.hpp" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/ch_vertex.hpp" +#include "cpp_common/ch_edge.hpp" namespace pgrouting { @@ -48,12 +48,12 @@ namespace graph { using CHUndirectedGraph = Pgr_contractionGraph < boost::adjacency_list < boost::listS, boost::vecS, boost::undirectedS, - CH_vertex, CH_edge>>; + CH_vertex, CH_edge>, false>; using CHDirectedGraph = Pgr_contractionGraph< boost::adjacency_list < boost::listS, boost::vecS, boost::bidirectionalS, - CH_vertex, CH_edge>>; + CH_vertex, CH_edge>, true>; } // namespace graph diff --git a/include/contraction/pgr_contract.hpp b/include/contraction/contract.hpp similarity index 90% rename from include/contraction/pgr_contract.hpp rename to include/contraction/contract.hpp index 788396c55f5..474b6f5fa54 100644 --- a/include/contraction/pgr_contract.hpp +++ b/include/contraction/contract.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_contract.hpp +File: contract.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,18 +27,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CONTRACTION_PGR_CONTRACT_HPP_ -#define INCLUDE_CONTRACTION_PGR_CONTRACT_HPP_ +#ifndef INCLUDE_CONTRACTION_CONTRACT_HPP_ +#define INCLUDE_CONTRACTION_CONTRACT_HPP_ #pragma once #include #include -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" -#include "contraction/pgr_contractionGraph.hpp" +#include "contraction/contractionGraph.hpp" #include "contraction/ch_graphs.hpp" -#include "contraction/pgr_linearContraction.hpp" -#include "contraction/pgr_deadEndContraction.hpp" +#include "contraction/linearContraction.hpp" +#include "contraction/deadEndContraction.hpp" namespace pgrouting { namespace contraction { @@ -131,4 +131,4 @@ class Pgr_contract { } // namespace contraction } // namespace pgrouting -#endif // INCLUDE_CONTRACTION_PGR_CONTRACT_HPP_ +#endif // INCLUDE_CONTRACTION_CONTRACT_HPP_ diff --git a/include/contraction/pgr_contractionGraph.hpp b/include/contraction/contractionGraph.hpp similarity index 93% rename from include/contraction/pgr_contractionGraph.hpp rename to include/contraction/contractionGraph.hpp index 5f40909f2e9..75cd790ec97 100644 --- a/include/contraction/pgr_contractionGraph.hpp +++ b/include/contraction/contractionGraph.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_contractionGraph.hpp +File: contractionGraph.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CONTRACTION_PGR_CONTRACTIONGRAPH_HPP_ -#define INCLUDE_CONTRACTION_PGR_CONTRACTIONGRAPH_HPP_ +#ifndef INCLUDE_CONTRACTION_CONTRACTIONGRAPH_HPP_ +#define INCLUDE_CONTRACTION_CONTRACTIONGRAPH_HPP_ #pragma once #include @@ -39,16 +39,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/ch_vertex.h" -#include "cpp_common/ch_edge.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/ch_vertex.hpp" +#include "cpp_common/ch_edge.hpp" namespace pgrouting { namespace graph { -template -class Pgr_contractionGraph : public Pgr_base_graph { +template +class Pgr_contractionGraph : public Pgr_base_graph { public: typedef typename boost::graph_traits < G >::vertex_descriptor V; typedef typename boost::graph_traits < G >::edge_descriptor E; @@ -56,10 +56,10 @@ class Pgr_contractionGraph : public Pgr_base_graph { typedef typename boost::graph_traits < G >::in_edge_iterator EI_i; /*! - Prepares the _graph_ to be of type *gtype* + Prepares the _graph_ to be of type *directed* */ - explicit Pgr_contractionGraph(graphType gtype) - : Pgr_base_graph(gtype) { + explicit Pgr_contractionGraph() + : Pgr_base_graph() { } /*! @brief get the vertex descriptors of adjacent vertices of *v* @@ -259,4 +259,4 @@ class Pgr_contractionGraph : public Pgr_base_graph { } // namespace graph } // namespace pgrouting -#endif // INCLUDE_CONTRACTION_PGR_CONTRACTIONGRAPH_HPP_ +#endif // INCLUDE_CONTRACTION_CONTRACTIONGRAPH_HPP_ diff --git a/include/contraction/pgr_deadEndContraction.hpp b/include/contraction/deadEndContraction.hpp similarity index 92% rename from include/contraction/pgr_deadEndContraction.hpp rename to include/contraction/deadEndContraction.hpp index faf936b2d18..83f05e9202e 100644 --- a/include/contraction/pgr_deadEndContraction.hpp +++ b/include/contraction/deadEndContraction.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_deadend.hpp +File: deadEndContraction.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,16 +27,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CONTRACTION_PGR_DEADENDCONTRACTION_HPP_ -#define INCLUDE_CONTRACTION_PGR_DEADENDCONTRACTION_HPP_ +#ifndef INCLUDE_CONTRACTION_DEADENDCONTRACTION_HPP_ +#define INCLUDE_CONTRACTION_DEADENDCONTRACTION_HPP_ #pragma once #include #include #include + +#include + #include "cpp_common/identifiers.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/interruption.hpp" namespace pgrouting { namespace contraction { @@ -123,4 +126,4 @@ class Pgr_deadend { } // namespace contraction } // namespace pgrouting -#endif // INCLUDE_CONTRACTION_PGR_DEADENDCONTRACTION_HPP_ +#endif // INCLUDE_CONTRACTION_DEADENDCONTRACTION_HPP_ diff --git a/include/contraction/pgr_linearContraction.hpp b/include/contraction/linearContraction.hpp similarity index 95% rename from include/contraction/pgr_linearContraction.hpp rename to include/contraction/linearContraction.hpp index 7c1d1fc3c55..704d0f34f6d 100644 --- a/include/contraction/pgr_linearContraction.hpp +++ b/include/contraction/linearContraction.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_linear.c +File: linearContraction.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CONTRACTION_PGR_LINEARCONTRACTION_HPP_ -#define INCLUDE_CONTRACTION_PGR_LINEARCONTRACTION_HPP_ +#ifndef INCLUDE_CONTRACTION_LINEARCONTRACTION_HPP_ +#define INCLUDE_CONTRACTION_LINEARCONTRACTION_HPP_ #pragma once @@ -38,7 +38,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include +#include +#include "cpp_common/ch_edge.hpp" #include "cpp_common/identifiers.hpp" @@ -196,4 +198,4 @@ class Pgr_linear { } // namespace contraction } // namespace pgrouting -#endif // INCLUDE_CONTRACTION_PGR_LINEARCONTRACTION_HPP_ +#endif // INCLUDE_CONTRACTION_LINEARCONTRACTION_HPP_ diff --git a/include/cpp_common/Dmatrix.h b/include/cpp_common/Dmatrix.hpp similarity index 96% rename from include/cpp_common/Dmatrix.h rename to include/cpp_common/Dmatrix.hpp index 1b81153ca09..a4db572b276 100644 --- a/include/cpp_common/Dmatrix.h +++ b/include/cpp_common/Dmatrix.hpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: Dmatrix.hpp FILE: Dmatrix.h @@ -25,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_DMATRIX_H_ -#define INCLUDE_CPP_COMMON_DMATRIX_H_ +#ifndef INCLUDE_CPP_COMMON_DMATRIX_HPP_ +#define INCLUDE_CPP_COMMON_DMATRIX_HPP_ #pragma once #include @@ -128,4 +129,4 @@ class Dmatrix { } // namespace tsp } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_DMATRIX_H_ +#endif // INCLUDE_CPP_COMMON_DMATRIX_HPP_ diff --git a/include/cpp_common/pgr_alloc.hpp b/include/cpp_common/alloc.hpp similarity index 92% rename from include/cpp_common/pgr_alloc.hpp rename to include/cpp_common/alloc.hpp index b5fe731d945..e0ed3d400f0 100644 --- a/include/cpp_common/pgr_alloc.hpp +++ b/include/cpp_common/alloc.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_palloc.hpp +File: alloc.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_PGR_ALLOC_HPP_ -#define INCLUDE_CPP_COMMON_PGR_ALLOC_HPP_ +#ifndef INCLUDE_CPP_COMMON_ALLOC_HPP_ +#define INCLUDE_CPP_COMMON_ALLOC_HPP_ #pragma once @@ -91,4 +91,4 @@ pgr_msg(const std::string &msg); } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_PGR_ALLOC_HPP_ +#endif // INCLUDE_CPP_COMMON_ALLOC_HPP_ diff --git a/include/cpp_common/pgr_assert.h b/include/cpp_common/assert.hpp similarity index 95% rename from include/cpp_common/pgr_assert.h rename to include/cpp_common/assert.hpp index e58aa5144ea..2afe6d5a254 100644 --- a/include/cpp_common/pgr_assert.h +++ b/include/cpp_common/assert.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: pgr_assert +File: assert.hpp Copyright (c) 2014 pgRouting developers Mail: project@pgrouting.org @@ -26,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CPP_COMMON_PGR_ASSERT_H_ -#define INCLUDE_CPP_COMMON_PGR_ASSERT_H_ +#ifndef INCLUDE_CPP_COMMON_ASSERT_HPP_ +#define INCLUDE_CPP_COMMON_ASSERT_HPP_ #pragma once #include @@ -70,7 +69,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * Example: * @code #include - #include "pgr_assert.h" + #include "cpp_common/assert.hpp" int main() { @@ -149,4 +148,4 @@ class AssertFailedException : public std::exception { virtual ~AssertFailedException() throw() {} }; -#endif // INCLUDE_CPP_COMMON_PGR_ASSERT_H_ +#endif // INCLUDE_CPP_COMMON_ASSERT_HPP_ diff --git a/include/cpp_common/basePath_SSEC.hpp b/include/cpp_common/basePath_SSEC.hpp index cade2c1edcf..aa7d4017fc7 100644 --- a/include/cpp_common/basePath_SSEC.hpp +++ b/include/cpp_common/basePath_SSEC.hpp @@ -1,5 +1,4 @@ /*PGR-GNU***************************************************************** - File: basePath_SSEC.hpp Copyright (c) 2015 pgRouting developers @@ -38,13 +37,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include +#include "cpp_common/undefPostgresDefine.hpp" + #include #include #include "c_types/path_rt.h" #include "c_types/mst_rt.h" -#include "cpp_common/path_t.h" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/path_t.hpp" +#include "cpp_common/base_graph.hpp" #include "cpp_common/rule.hpp" namespace pgrouting { @@ -89,7 +90,7 @@ class Path { ConstpthIt end() const {return path.end();} - void erase(pthIt pos) {path.erase(pos);} + void erase(const pthIt &pos) {path.erase(pos);} const Path_t& back() const {return path.back();} Path_t& back() {return path.back();} const Path_t& front() const {return path.front();} diff --git a/include/cpp_common/base_graph.hpp b/include/cpp_common/base_graph.hpp new file mode 100644 index 00000000000..72efb41d136 --- /dev/null +++ b/include/cpp_common/base_graph.hpp @@ -0,0 +1,877 @@ +/*PGR-GNU***************************************************************** +File: base_graph.hpp + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2015 Celia Virginia Vergara Castillo +vicky_vergara@hotmail.com +------ + +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*/ + +/** @file */ + +#ifndef INCLUDE_CPP_COMMON_BASE_GRAPH_HPP_ +#define INCLUDE_CPP_COMMON_BASE_GRAPH_HPP_ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "cpp_common/basic_vertex.hpp" +#include "cpp_common/xy_vertex.hpp" +#include "cpp_common/basic_edge.hpp" + +#include "cpp_common/assert.hpp" + +namespace pgrouting { + +/** @brief boost::graph simplified to pgRouting needs + This class gives the handling basics of a boost::graph of kind G + where G: + can be an undirected graph or a directed graph. +Requiremets: +============ +A vertex class T_V +------------------ +Current Available vertex classes: +- Basic_vertex +- XY_vertex +An edge class T_E +----------------- +Current Available edge classes: +- Basic_edge +extract_vertices function +------------------------- +Data obtained from postgresql is stored in +A C array of Edge_t type. +~~~~{.c} +std::vector< T_V > +extract_vertices(Edge_t *, size_t) +~~~~ +Data obtained from postgresql is stored in +o a vector container. +~~~~{.c} +std::vector< T_V > +extract_vertices(std::vector< Edge_t >) +~~~~ +Boost Graph +------------- +The code is prepared to be used for: +- boost::adjacency_list graph type +- boost::undirectedS when the graph is UNDIRECTED +- boost::bidirectionalS when the graph is DIRECTED +~~~~{.c} +boost::adjacency_list +< boost::vecS, // not tested with other values +boost::vecS, // not tested with other values +boost::undirectedS, // Using UNDIRECTED +Basic_vertex, // the vertex class +Basic_edge > // the edge class +~~~~ +Example Usage: +============= +For this example we will use: +- Basic_vertex +- Basic_edge +- Edge_t +Create Graph type +----------------- +~~~~{.c} +typedef typename +graph::Pgr_base_graph < +boost::adjacency_list < +boost::vecS, + boost::vecS, + boost::bidirectionalS, + Basic_vertex, + Basic_edge >, + Basic_vertex, + Basic_edge > + DirectedGraph; +~~~~ +Initializing the graph +------------------------------ +Graph initialization is for seting the Vertices of the graph. +//TODO discuss if also the edges +Vector of unique vertices of the graph +~~~~{.c} +size_t total_edges; +Edge_t *my_edges = NULL; +pgr_get_edges(edges_sql, &my_edges, &total_tuples, true, false, &err_msg); +std::vector< Basic_Vertex > vertices(pgrouting::extract_vertices(my_edges)); +~~~~ +There are several ways to initialize the graph +~~~~{.c} +// 1. Initializes an empty graph +pgrouting::DirectedGraph digraph(true); +// 2. Initializes a graph based on the vertices +pgrouting::DirectedGraph digraph( + verices, + true); +vertices.clear(); +3. Initializes a graph based on the extracted vertices +pgrouting::DirectedGraph digraph( + pgrouting::extract_vertices(my_edges, total_edges); + true); +4. Initializes a graph based on the extracted vertices +pgrouting::DirectedGraph digraph( + pgrouting::extract_vertices(my_edges); + true); +~~~~ +1. Initializes an empty graph + - vertices vector size is 0 +2. Initializes a graph based on the vertices: + - vertices vector size is vertices.size() + - the vertices are inserted + - vertices container can be clared to free memory +3. Initializes a graph based on the vertices extracted + - from edges stored on a C array + - the vertices are inserted +4. Initializes a graph based on the vertices extracted + - from edges stored on a vector + - the vertices are inserted +Fill the graph +--------------------- +After initializing the graph with the vertices, the edges can be added. +~~~~{.c} +// inserting edges from a C array +digraph.insert_edges(my_edges, total_edges); +// adding more edges to the graph from a vector container +digraph.insert_edges(new_edges); +~~~~ +*/ + +namespace graph { +template +class Pgr_base_graph; + +} // namespace graph + + +/** @name Graph types + Type | pgRouting + :---------: | :--------------------- + UndirectedGraph | Basic undirected graph + DirectedGraph | Basic directed graph + xyUndirectedGraph | X & Y values stored on the vertex + xyDirectedGraph | X & Y values stored on the vertex + */ +/**@{*/ +typedef graph::Pgr_base_graph < +boost::adjacency_list < boost::vecS, boost::vecS, + boost::undirectedS, + Basic_vertex, Basic_edge >, + Basic_vertex, Basic_edge, false > UndirectedGraph; + +typedef graph::Pgr_base_graph < +boost::adjacency_list < boost::vecS, boost::vecS, + boost::bidirectionalS, + Basic_vertex, Basic_edge >, + Basic_vertex, Basic_edge , true> DirectedGraph; + +typedef graph::Pgr_base_graph < +boost::adjacency_list < boost::listS, boost::vecS, + boost::undirectedS, + XY_vertex, Basic_edge >, + XY_vertex, Basic_edge , false> xyUndirectedGraph; + +typedef graph::Pgr_base_graph < +boost::adjacency_list < boost::listS, boost::vecS, + boost::bidirectionalS, + XY_vertex, Basic_edge >, + XY_vertex, Basic_edge , true> xyDirectedGraph; + +/**@}*/ + + +namespace graph { + +template +class Pgr_base_graph { + public: + /** @name Graph related types + Type | boost meaning | pgRouting meaning + :---------: | :-------------------- | :---------------------- + G | boost::adjacency_list | Graph + V | vertex_descriptor | Think of it as local ID of a vertex + E | edge_descriptor | Think of it as local ID of an edge + V_i | vertex_iterator | To cycle the vertices of the Graph + E_i | edge_iterator | To cycle the edges of the Graph + EO_i | out_edge_iterator | To cycle the out going edges of a vertex + EI_i | in_edge_iterator | To cycle the in coming edges of a vertex (only in bidirectional graphs) + */ + /**@{*/ + using B_G = G; + using G_T_E = T_E; + using G_T_V = T_V; + using V = typename boost::graph_traits::vertex_descriptor; + using E = typename boost::graph_traits::edge_descriptor; + using V_i = typename boost::graph_traits::vertex_iterator; + using E_i = typename boost::graph_traits::edge_iterator; + using EO_i = typename boost::graph_traits::out_edge_iterator; + using EI_i = typename boost::graph_traits::in_edge_iterator; + + using vertices_size_type = typename boost::graph_traits::vertices_size_type; + using edges_size_type = typename boost::graph_traits::edges_size_type; + using degree_size_type = typename boost::graph_traits::degree_size_type; + using vertex_index_t = typename boost::property_map::type; + + /**@}*/ + + /** @name Other types + Type | Meaning | pgRouting Meaning + :---------: | :------------- | :---------------------- + IndexMap | maps V -> id | given a V store the id + id_to_V | maps id -> V | given an id store the V + */ + /**@{*/ + + using IndexMap = std::map; + using id_to_V = typename std::map; + + /**@}*/ + + + /** @name Graph constructors */ + /**@{*/ + /** @brief Constructor */ + /** + - Prepares the graph to be of type gtype + - inserts the vertices + - The vertices must be checked (if necessary) before calling the constructor + */ + explicit Pgr_base_graph( + const std::vector &vertices) + : graph(vertices.size()), + m_is_directed(t_directed), + vertIndex(boost::get(boost::vertex_index, graph)), + propmapIndex(mapIndex) { + // This code does not work with contraction + size_t i = 0; + for (auto vi = boost::vertices(graph).first; + vi != boost::vertices(graph).second; ++vi) { + vertices_map[vertices[i].id] = (*vi); + graph[(*vi)].cp_members(vertices[i]); + // put(propmapIndex, *vi, num_vertices()); + pgassert(vertIndex[*vi] == i); + ++i; + } + + std::ostringstream log; + for (auto iter = vertices_map.begin(); + iter != vertices_map.end(); + iter++) { + log << "Key: " + << iter->first <<"\tValue:" << iter->second << "\n"; + } + // pgassert(mapIndex.size() == vertices.size()); + } + + /** + Prepares the _graph_ to be of type gtype with 0 vertices + */ + explicit Pgr_base_graph() + : graph(0), + m_is_directed(t_directed), + vertIndex(boost::get(boost::vertex_index, graph)), + propmapIndex(mapIndex) { + } + /**@}*/ + + /** @name Edges inserters */ + /**@{*/ + template void insert_edges_neg(const std::vector &edges) { + insert_edges(edges, false); + } + + + /** @brief Inserts *count* edges of type *Edge_t* into the graph + The set of edges should not have an illegal vertex defined + When the graph is empty calls: + - @b extract_vertices + and throws an exception if there are illegal vertices. + When developing: + - if an illegal vertex is found an exception is thrown + - That means that the set of vertices should be checked in the + code that is being developed + No edge is inserted when there is an error on the vertices + @param edges + @param normal + */ + template + void insert_edges(const std::vector &edges, bool normal = true) { + for (const auto &edge : edges) { + graph_add_edge(edge, normal); + } + } + + + template void insert_min_edges_no_parallel(const std::vector &edges) { + for (const auto edge : edges) { + graph_add_min_edge_no_parallel(edge); + } + } + + template void insert_negative_edges(const std::vector &edges, bool normal = true) { + for (const auto edge : edges) { + graph_add_neg_edge(edge, normal); + } + } + /**@}*/ + + /** @name in & out degree */ + /**@{*/ + /** @brief get the out-degree of a vertex + @returns 0: The out degree of a vertex that its not in the graph + @param [in] vertex_id original vertex id + */ + degree_size_type out_degree(int64_t vertex_id) const { + if (!has_vertex(vertex_id)) { + return 0; + } + auto v = get_V(vertex_id); + auto d = out_degree(v); + return d; + } + + degree_size_type in_degree(int64_t vertex_id) const { + if (!has_vertex(vertex_id)) { + return 0; + } + return is_directed()? + in_degree(get_V(vertex_id)) + : out_degree(get_V(vertex_id)); + } + + /** @brief in degree of a vertex + * + * - when its undirected there is no "concept" of in degree + * - out degree is returned + * - on directed in degree of vertex is returned + * @param [in] v vertex descriptor + */ + degree_size_type in_degree(V &v) const { + return is_directed()? + boost::in_degree(v, graph) : + boost::out_degree(v, graph); + } + + /** @brief out degree of a vertex + * + * regardles of undirected or directed graph + * - out degree is returned + */ + degree_size_type out_degree(V &v) const { + return boost::out_degree(v, graph); + } + /**@}*/ + + + /** @name Get vertex descriptor */ + /**@{*/ + /** @brief get the vertex descriptor of the vertex + When the vertex does not exist + - creates a new vetex + @return V: The vertex descriptor of the vertex + */ + V get_V(const T_V &vertex) { + auto vm_s(vertices_map.find(vertex.id)); + if (vm_s == vertices_map.end()) { + auto v = add_vertex(graph); + graph[v].cp_members(vertex); + vertices_map[vertex.id] = v; + put(propmapIndex, v, num_vertices()); + return v; + } + return vm_s->second; + } + + /** @brief get the vertex descriptor of the vid + Call has_vertex(vid) before calling this function + @param[in] vid vertex identifier + @return V: The vertex descriptor of the vertex + */ + V get_V(int64_t vid) const { + if (!has_vertex(vid)) throw std::string("Call to ") + __PRETTY_FUNCTION__ + "without checking with has_vertex"; + return vertices_map.find(vid)->second; + } + + /** @brief get source edge + @param[in] e edge descriptor + @return V vertex descriptor + */ + V source(E e) const {return boost::source(e, graph);} + + /** @brief get source edge + @param[in] e edge descriptor + @return V vertex descriptor + */ + V target(E e) const {return boost::target(e, graph);} + + /** @brief get source edge + @param[in] v vertex descriptor + @param[in] e edge descriptor + @return V vertex descriptor + */ + V adjacent(V v, E e) const { + pgassert(is_source(v, e) || is_target(v, e)); + return is_source(v, e)? target(e) : source(e); + } + /**@}*/ + + + /** @name to be or not to be */ + /**@{*/ + /** @brief does vertex exist in the graph? + @param[in] vid vertex identifier + @return true: when vid is in the graph + @return false: when vid is not in the graph + */ + bool has_vertex(int64_t vid) const { + return vertices_map.find(vid) != vertices_map.end(); + } + /** @brief is the graph directed? + @return true: when the graph is directed + @return false: when the graph is not directed + */ + bool is_directed() const {return m_is_directed;} + /** @brief is the graph undirected? + @return true: when the graph is undirected + @return false: when the graph is not undirected + */ + bool is_undirected() const {return !m_is_directed;} + /** @brief is v a source in the edge? + @param[in] v vertex descriptor + @param[in] e edge descriptor + @return true: when v is source on the edge + @return false: when v is not source on the edge + */ + bool is_source(V v, E e) const {return v == source(e);} + /** @brief is v a target in the edge? + @param[in] v vertex descriptor + @param[in] e edge descriptor + @return true: when v is target on the edge + @return false: when v is not target on the edge + */ + bool is_target(V v, E e) const {return v == target(e);} + + /**@}*/ + + /** @name get original edge/vertex data */ + /**@{*/ + /** @brief get the edge + @param[in] e edge descriptor + @return The edge information (allows modification) + */ + T_E& operator[](E e) {return graph[e];} + + /** @brief get the edge + @param[in] e edge descriptor + @return The edge information (does not allow modification) + */ + const T_E& operator[](E e) const {return graph[e];} + + /** @brief get the vertex + @param[in] v vertex descriptor + @return The vertex information (allows modification) + */ + T_V& operator[](V v) {return graph[v];} + + /** @brief get the vertex + @param[in] v vertex descriptor + @return The vertex information (does not allow modification) + */ + const T_V& operator[](V v) const {return graph[v];} + + /** @brief get the edge id of from--to with the indicated distance + @param[in] from vertex descriptor + @param[in] to vertex descriptor + @param[in] weight edge's weight to match when several options are found + @return The edge identifier of edge from--to with @b weight + @return OR the edge identifier of edge from--to with @b min weight + */ + int64_t get_edge_id(V from, V to, double &weight) const { + EO_i out_i, out_end; + double minCost = (std::numeric_limits::max)(); + int64_t minEdge = -1; + for (boost::tie(out_i, out_end) = boost::out_edges(from, graph); out_i != out_end; ++out_i) { + auto e = *out_i; + auto v_target = target(e); + auto v_source = source(e); + if ((from == v_source) && (to == v_target) && (weight == graph[e].cost)) return graph[e].id; + if ((from == v_source) && (to == v_target) && (minCost > graph[e].cost)) { + minCost = graph[e].cost; + minEdge = graph[e].id; + } + } + weight = minEdge == -1? 0: minCost; + return minEdge; + } + /**@}*/ + + + + /** @name only for debug */ + /**@{*/ + friend std::ostream& operator<<( + std::ostream &log, const Pgr_base_graph &g) { + typename Pgr_base_graph::EO_i out, out_end; + + auto vs = boost::vertices(g.graph); + for (auto vi = vs.first; vi != vs.second; ++vi) { + if ((*vi) >= g.num_vertices()) break; + log << (*vi) << ": " << " out_edges_of(" << g.graph[(*vi)] << "):"; + auto es = boost::out_edges(*vi, g.graph); + for (auto out = es.first; out != es.second; ++out) { + log << ' ' + << g.graph[*out].id << "=(" + << g[g.source(*out)].id << ", " + << g[g.target(*out)].id << ") = " + << g.graph[*out].cost <<"\t"; + } + log << std::endl; + } + return log; + } + /**@}*/ + + + /** @name Get edge descriptor */ + /**@{*/ + E get_edge(V from, V to, double &distance) const { + E e; + EO_i out_i, out_end; + V v_source, v_target; + double minCost = (std::numeric_limits::max)(); + E minEdge; + bool valid = false; + for (boost::tie(out_i, out_end) = boost::out_edges(from, graph); + out_i != out_end; ++out_i) { + e = *out_i; + if (!valid) { + minEdge = e; + valid = true; + } + v_target = target(e); + v_source = source(e); + if ((from == v_source) && (to == v_target) + && (distance == graph[e].cost)) { + return e; + } + if ((from == v_source) && (to == v_target) + && (minCost > graph[e].cost)) { + minCost = graph[e].cost; + minEdge = e; + } + } + return minEdge; + } + /**@}*/ + + /** @name How big */ + /**@{*/ + size_t num_vertices() const { return boost::num_vertices(graph);} + size_t num_edges() const { return boost::num_edges(graph);} + /**@}*/ + + /** @name edge disconection/reconnection */ + /**@{*/ + /** @brief Disconnects all edges from p_from to p_to + - No edge is disconnected if the vertices id's do not exist in the graph + - All removed edges are stored for future reinsertion + - All parallel edges are disconnected (automatically by boost) + ![disconnect_edge(2,3) on an UNDIRECTED graph](disconnectEdgeUndirected.png) + ![disconnect_edge(2,3) on a DIRECTED graph](disconnectEdgeDirected.png) + @param [in] p_from vertex identifier of the starting point of the edge + @param [in] p_to vertex identifier of the ending point of the edge + */ + void disconnect_edge(int64_t p_from, int64_t p_to) { + /* nothing to do, a vertex doesn't exist */ + if (!has_vertex(p_from) || !has_vertex(p_to)) return; + + EO_i out, out_end; + auto u(get_V(p_from)); + auto v(get_V(p_to)); + + for (boost::tie(out, out_end) = out_edges(u, graph); out != out_end; ++out) { + if (target(*out) == v) { + removed_edges.push_back(get_edge_info(*out)); + break; + } + } + boost::remove_edge(u, v, graph); + } + + /** @brief Disconnects the outgoing edges of a vertex + + - No edge is disconnected if it doesn't exist in the graph + - Removed edges are stored for future reinsertion + - all outgoing edges with the edge_id are removed if they exist + @param [in] vid original vertex + @param [in] eid original edge_id + */ + void disconnect_out_going_edge(int64_t vid, int64_t eid) { + /* nothing to do, the vertex doesn't exist */ + if (!has_vertex(vid)) return; + + auto v(get_V(vid)); + EO_i out, out_end; + bool change = true; + while (change) { + change = false; + for (boost::tie(out, out_end) = out_edges(v, graph); out != out_end; ++out) { + if (graph[*out].id == eid) { + removed_edges.push_back(get_edge_info(*out)); + boost::remove_edge((*out), graph); + change = true; + break; + } + } + } + } + + /** @brief Disconnects all incoming and outgoing edges from @b vertex + @param [in] vid vertex identifier + */ + void disconnect_vertex(int64_t vid) { + if (!has_vertex(vid)) return; + disconnect_vertex(get_V(vid)); + } + + /** @brief Disconnects all incoming and outgoing edges from the vertex + + boost::graph doesn't recommend th to insert/remove vertices, so a vertex removal is + simulated by disconnecting the vertex from the graph + - No edge is disconnected if the vertices id's do not exist in the graph + - All removed edges are stored for future reinsertion + - All parallel edges are disconnected (automatically by boost) + ![disconnect_vertex(2) on an UNDIRECTED graph](disconnectVertexUndirected.png) + ![disconnect_vertex(2) on a DIRECTED graph](disconnectVertexDirected.png) + @param [in] v vertex descriptor + */ + void disconnect_vertex(V v) { + EO_i out, out_end; + for (boost::tie(out, out_end) = out_edges(v, graph); out != out_end; ++out) { + removed_edges.push_back(get_edge_info(*out)); + } + + /* special case */ + if (m_is_directed) { + EI_i in, in_end; + for (boost::tie(in, in_end) = in_edges(v, graph); in != in_end; ++in) { + removed_edges.push_back(get_edge_info(*in)); + } + } + + /* delete incoming and outgoing edges from the vertex */ + boost::clear_vertex(v, graph); + } + + /** @brief Reconnects all edges that were removed */ + void + restore_graph() { + while (removed_edges.size() != 0) { + restore_edge(removed_edges[0]); + removed_edges.pop_front(); + } + } + + private: + void restore_edge(const T_E &edge) { + E e; + + auto u = get_V(edge.source); + auto v = get_V(edge.target); + if (edge.cost >= 0) { + bool inserted; + boost::tie(e, inserted) = boost::add_edge(u, v, graph); + graph[e].cp_members(edge); + } + } + + /* @brief builds up info that will be deleted + * @param[in] e edge descriptor + * @return edge data + */ + T_E get_edge_info(const E &e) const { + T_E d_edge; + d_edge.id = graph[e].id; + d_edge.source = graph[source(e)].id; + d_edge.target = graph[target(e)].id; + d_edge.cost = graph[e].cost; + return d_edge; + } + /**@}*/ + + template void graph_add_edge(const T &edge, bool normal) { + bool inserted; + E e; + if ((edge.cost < 0) && (edge.reverse_cost < 0)) return; + + /* + * true: for source + * false: for target + */ + auto vm_s = get_V(T_V(edge, true)); + auto vm_t = get_V(T_V(edge, false)); + + pgassert(vertices_map.find(edge.source) != vertices_map.end()); + pgassert(vertices_map.find(edge.target) != vertices_map.end()); + if (edge.cost >= 0) { + boost::tie(e, inserted) = + boost::add_edge(vm_s, vm_t, graph); + graph[e].cost = edge.cost; + graph[e].id = edge.id; + } + + if (edge.reverse_cost >= 0 + && (m_is_directed || (!m_is_directed && edge.cost != edge.reverse_cost))) { + boost::tie(e, inserted) = + boost::add_edge(vm_t, vm_s, graph); + + graph[e].cost = edge.reverse_cost; + graph[e].id = normal? edge.id : -edge.id; + } + } + + template void graph_add_min_edge_no_parallel(const T &edge) { + bool inserted; + E e; + if ((edge.cost < 0) && (edge.reverse_cost < 0)) return; + + /* + * true: for source + * false: for target + */ + auto vm_s = get_V(T_V(edge, true)); + auto vm_t = get_V(T_V(edge, false)); + + pgassert(vertices_map.find(edge.source) != vertices_map.end()); + pgassert(vertices_map.find(edge.target) != vertices_map.end()); + if (edge.cost >= 0) { + E e1; + bool found; + boost::tie(e1, found) = boost::edge(vm_s, vm_t, graph); + if (found) { + if (edge.cost < graph[e1].cost) { + graph[e1].cost = edge.cost; + graph[e1].id = edge.id; + } + } else { + boost::tie(e, inserted) = boost::add_edge(vm_s, vm_t, graph); + graph[e].cost = edge.cost; + graph[e].id = edge.id; + } + } + + if (edge.reverse_cost >= 0 + && (m_is_directed || (!m_is_directed && edge.cost != edge.reverse_cost))) { + E e1; + bool found; + boost::tie(e1, found) = boost::edge(vm_t, vm_s, graph); + if (found) { + if (edge.reverse_cost < graph[e1].cost) { + graph[e1].cost = edge.reverse_cost; + graph[e1].id = edge.id; + } + } else { + boost::tie(e, inserted) = + boost::add_edge(vm_t, vm_s, graph); + + graph[e].cost = edge.reverse_cost; + graph[e].id = edge.id; + } + } + } + + /** + Add edges with negative cost(either cost or reverse_cost or both) + Reading them into graph as positive cost ( edge_cost = (-1)* edge_negative_cost) [L931 & L941] + To Do: Read and apply edges with negative cost in function as it is + */ + template void graph_add_neg_edge(const T &edge, bool normal = true) { + bool inserted; + E e; + + auto vm_s = get_V(T_V(edge, true)); + auto vm_t = get_V(T_V(edge, false)); + + pgassert(vertices_map.find(edge.source) != vertices_map.end()); + pgassert(vertices_map.find(edge.target) != vertices_map.end()); + + boost::tie(e, inserted) = boost::add_edge(vm_s, vm_t, graph); + if (edge.cost < 0) { + /* reading negative edges as positive */ + graph[e].cost = (-0.5)*edge.cost; + } else { + graph[e].cost = edge.cost; + } + graph[e].id = edge.id; + + if (m_is_directed + || (!m_is_directed && edge.cost > edge.reverse_cost)) { + boost::tie(e, inserted) = + boost::add_edge(vm_t, vm_s, graph); + if (edge.reverse_cost < 0) { + /* reading negative edges as positive */ + graph[e].cost = (-0.5)*edge.reverse_cost; + } else { + graph[e].cost = edge.reverse_cost; + } + + graph[e].id = normal? edge.id : -edge.id; + } + } + + public: + /** @name The Graph */ + /**@{*/ + G graph; /**< The graph */ + id_to_V vertices_map; /**< id -> graph id */ + + private: + bool m_is_directed; /**< type (DIRECTED or UNDIRECTED) */ + /**@}*/ + + /** @name Id mapping handling */ + /**@{*/ + vertex_index_t vertIndex; + IndexMap mapIndex; + boost::associative_property_map propmapIndex; + /**@}*/ + + /** @name Graph Modification */ + /**@{*/ + /** Used for storing the removed_edges */ + std::deque removed_edges; + /**@}*/ +}; + +} // namespace graph +} // namespace pgrouting +#endif // INCLUDE_CPP_COMMON_BASE_GRAPH_HPP_ diff --git a/include/cpp_common/basic_edge.h b/include/cpp_common/basic_edge.hpp similarity index 89% rename from include/cpp_common/basic_edge.h rename to include/cpp_common/basic_edge.hpp index 9128b0e9b37..5353ebf0149 100644 --- a/include/cpp_common/basic_edge.h +++ b/include/cpp_common/basic_edge.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** - * +File: basic_edge.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_BASIC_EDGE_H_ -#define INCLUDE_CPP_COMMON_BASIC_EDGE_H_ +#ifndef INCLUDE_CPP_COMMON_BASIC_EDGE_HPP_ +#define INCLUDE_CPP_COMMON_BASIC_EDGE_HPP_ #pragma once #include @@ -49,4 +49,4 @@ class Basic_edge{ } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_BASIC_EDGE_H_ +#endif // INCLUDE_CPP_COMMON_BASIC_EDGE_HPP_ diff --git a/include/cpp_common/basic_vertex.h b/include/cpp_common/basic_vertex.hpp similarity index 85% rename from include/cpp_common/basic_vertex.h rename to include/cpp_common/basic_vertex.hpp index 2fe9ab21415..e4300311e2e 100644 --- a/include/cpp_common/basic_vertex.h +++ b/include/cpp_common/basic_vertex.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** - * +File: basic_vertex.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -27,14 +27,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_BASIC_VERTEX_H_ -#define INCLUDE_CPP_COMMON_BASIC_VERTEX_H_ +#ifndef INCLUDE_CPP_COMMON_BASIC_VERTEX_HPP_ +#define INCLUDE_CPP_COMMON_BASIC_VERTEX_HPP_ #pragma once #include #include -#include "c_types/edge_t.h" +#include "cpp_common/edge_t.hpp" @@ -43,17 +43,17 @@ namespace pgrouting { class Basic_vertex { public: Basic_vertex() : - id(0), vertex_index(0) {} + id(0) {} Basic_vertex(const Basic_vertex &v) : - id(v.id), vertex_index(0) {} + id(v.id) {} explicit Basic_vertex(const int64_t _id) : - id(_id), vertex_index(0) {} + id(_id) {} Basic_vertex& operator=(const Basic_vertex&) = default; Basic_vertex(const Edge_t &other, bool is_source) : - id(is_source? other.source : other.target), vertex_index(0) {} + id(is_source? other.source : other.target) {} void cp_members(const Basic_vertex &other) { this->id = other.id; @@ -63,7 +63,6 @@ class Basic_vertex { friend std::ostream& operator<<(std::ostream& log, const Basic_vertex &v); public: int64_t id; - size_t vertex_index; }; size_t check_vertices(std::vector < Basic_vertex > vertices); @@ -86,4 +85,4 @@ std::vector < Basic_vertex > extract_vertices( } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_BASIC_VERTEX_H_ +#endif // INCLUDE_CPP_COMMON_BASIC_VERTEX_HPP_ diff --git a/include/cpp_common/pgr_bidirectional.hpp b/include/cpp_common/bidirectional.hpp similarity index 96% rename from include/cpp_common/pgr_bidirectional.hpp rename to include/cpp_common/bidirectional.hpp index 00c60aa8fae..ded4d8129b0 100644 --- a/include/cpp_common/pgr_bidirectional.hpp +++ b/include/cpp_common/bidirectional.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_bdAstar.hpp +File: bidirectional.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -29,8 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_PGR_BIDIRECTIONAL_HPP_ -#define INCLUDE_CPP_COMMON_PGR_BIDIRECTIONAL_HPP_ +#ifndef INCLUDE_CPP_COMMON_BIDIRECTIONAL_HPP_ +#define INCLUDE_CPP_COMMON_BIDIRECTIONAL_HPP_ #pragma once @@ -46,10 +46,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/base_graph.hpp" namespace pgrouting { @@ -241,4 +241,4 @@ class Pgr_bidirectional { } // namespace bidirectional } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_PGR_BIDIRECTIONAL_HPP_ +#endif // INCLUDE_CPP_COMMON_BIDIRECTIONAL_HPP_ diff --git a/include/cpp_common/bline.hpp b/include/cpp_common/bline.hpp index 873730e2cee..4ecf49e1a46 100644 --- a/include/cpp_common/bline.hpp +++ b/include/cpp_common/bline.hpp @@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_CPP_COMMON_BLINE_HPP_ #pragma once +#include #include #include #include diff --git a/include/cpp_common/ch_edge.h b/include/cpp_common/ch_edge.hpp similarity index 91% rename from include/cpp_common/ch_edge.h rename to include/cpp_common/ch_edge.hpp index 0ae75873308..879b9dd7a95 100644 --- a/include/cpp_common/ch_edge.h +++ b/include/cpp_common/ch_edge.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: ch_edge.h +File: ch_edge.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,14 +27,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CPP_COMMON_CH_EDGE_H_ -#define INCLUDE_CPP_COMMON_CH_EDGE_H_ +#ifndef INCLUDE_CPP_COMMON_CH_EDGE_HPP_ +#define INCLUDE_CPP_COMMON_CH_EDGE_HPP_ #pragma once #include #include -#include "./ch_vertex.h" -// #include "./basic_edge.h" +#include "cpp_common/ch_vertex.hpp" namespace pgrouting { @@ -70,4 +69,4 @@ class CH_edge { } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_CH_EDGE_H_ +#endif // INCLUDE_CPP_COMMON_CH_EDGE_HPP_ diff --git a/include/cpp_common/ch_vertex.h b/include/cpp_common/ch_vertex.hpp similarity index 84% rename from include/cpp_common/ch_vertex.h rename to include/cpp_common/ch_vertex.hpp index 2e2ac64d2e4..2de3697d5b6 100644 --- a/include/cpp_common/ch_vertex.h +++ b/include/cpp_common/ch_vertex.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: ch_vertex.h +File: ch_vertex.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -26,13 +26,13 @@ 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_CPP_COMMON_CH_VERTEX_H_ -#define INCLUDE_CPP_COMMON_CH_VERTEX_H_ +#ifndef INCLUDE_CPP_COMMON_CH_VERTEX_HPP_ +#define INCLUDE_CPP_COMMON_CH_VERTEX_HPP_ #include #include #include -#include "c_types/edge_t.h" +#include "cpp_common/edge_t.hpp" #include "cpp_common/identifiers.hpp" namespace pgrouting { @@ -62,15 +62,6 @@ class CH_vertex { size_t check_vertices(std::vector < CH_vertex > vertices); -#if 0 -std::vector < CH_vertex > -extract_vertices( - const Edge_t *data_edges, int64_t count); - -std::vector < CH_vertex > -extract_vertices( - const std::vector < Edge_t > &data_edges); -#endif } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_CH_VERTEX_H_ +#endif // INCLUDE_CPP_COMMON_CH_VERTEX_HPP_ diff --git a/include/cpp_common/combinations.h b/include/cpp_common/combinations.hpp similarity index 78% rename from include/cpp_common/combinations.h rename to include/cpp_common/combinations.hpp index fe6361b7f47..a7e3a00165d 100644 --- a/include/cpp_common/combinations.h +++ b/include/cpp_common/combinations.hpp @@ -1,6 +1,5 @@ - /*PGR-GNU***************************************************************** -File: combinations.h +File: combinations.hpp Copyright (c) 2021 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CPP_COMMON_COMBINATIONS_H_ -#define INCLUDE_CPP_COMMON_COMBINATIONS_H_ +#ifndef INCLUDE_CPP_COMMON_COMBINATIONS_HPP_ +#define INCLUDE_CPP_COMMON_COMBINATIONS_HPP_ #pragma once #include @@ -36,24 +35,41 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include + #include "c_types/ii_t_rt.h" #include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/rule.hpp" + + +typedef struct ArrayType ArrayType; namespace pgrouting { + +class Path; + namespace utilities { +#if 1 std::map> get_combinations(const II_t_rt *, size_t); std::map> get_combinations(int64_t*, size_t, int64_t*, size_t); +#endif std::map> get_combinations( std::deque&, const std::vector&); +std::map> +get_combinations(const std::vector&); + + +std::map> +get_combinations(char*, ArrayType*, ArrayType*, bool); + } // namespace utilities } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_COMBINATIONS_H_ +#endif // INCLUDE_CPP_COMMON_COMBINATIONS_HPP_ diff --git a/include/cpp_common/compPaths.h b/include/cpp_common/compPaths.hpp similarity index 90% rename from include/cpp_common/compPaths.h rename to include/cpp_common/compPaths.hpp index 2d102f84885..69fc7db6516 100644 --- a/include/cpp_common/compPaths.h +++ b/include/cpp_common/compPaths.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: compPaths.h +File: compPaths.hpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org @@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CPP_COMMON_COMPPATHS_H_ -#define INCLUDE_CPP_COMMON_COMPPATHS_H_ +#ifndef INCLUDE_CPP_COMMON_COMPPATHS_HPP_ +#define INCLUDE_CPP_COMMON_COMPPATHS_HPP_ #pragma once #include "cpp_common/basePath_SSEC.hpp" @@ -54,4 +54,4 @@ class compPathsLess { } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_COMPPATHS_H_ +#endif // INCLUDE_CPP_COMMON_COMPPATHS_HPP_ diff --git a/include/c_types/coordinate_t.h b/include/cpp_common/coordinate_t.hpp similarity index 82% rename from include/c_types/coordinate_t.h rename to include/cpp_common/coordinate_t.hpp index 16c3c660a75..dd4d111430c 100644 --- a/include/c_types/coordinate_t.h +++ b/include/cpp_common/coordinate_t.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: coordinate_t.h +File: coordinate_t.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -26,16 +26,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_COORDINATE_T_H_ -#define INCLUDE_C_TYPES_COORDINATE_T_H_ +#ifndef INCLUDE_CPP_COMMON_COORDINATE_T_HPP_ +#define INCLUDE_CPP_COMMON_COORDINATE_T_HPP_ #pragma once -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif +#include struct Coordinate_t { int64_t id; @@ -43,4 +38,4 @@ struct Coordinate_t { double y; }; -#endif // INCLUDE_C_TYPES_COORDINATE_T_H_ +#endif // INCLUDE_CPP_COMMON_COORDINATE_T_HPP_ diff --git a/include/c_types/costFlow_t.h b/include/cpp_common/costFlow_t.hpp similarity index 82% rename from include/c_types/costFlow_t.h rename to include/cpp_common/costFlow_t.hpp index b5ae44f2214..e5d4e1e205f 100644 --- a/include/c_types/costFlow_t.h +++ b/include/cpp_common/costFlow_t.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: costFlow_t.h +File: costFlow_t.hpp Copyright (c) 2018 Maoguang Wang Mail: xjtumg1007@gmail.com @@ -23,17 +23,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_COSTFLOW_T_H_ -#define INCLUDE_C_TYPES_COSTFLOW_T_H_ +#ifndef INCLUDE_CPP_COMMON_COSTFLOW_T_HPP_ +#define INCLUDE_CPP_COMMON_COSTFLOW_T_HPP_ #pragma once -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif - +#include struct CostFlow_t { int64_t edge_id; @@ -45,4 +39,4 @@ struct CostFlow_t { double reverse_cost; }; -#endif // INCLUDE_C_TYPES_COSTFLOW_T_H_ +#endif // INCLUDE_CPP_COMMON_COSTFLOW_T_HPP_ diff --git a/include/c_types/delauny_t.h b/include/cpp_common/delauny_t.hpp similarity index 83% rename from include/c_types/delauny_t.h rename to include/cpp_common/delauny_t.hpp index 80291b5bac4..dd8d960540b 100644 --- a/include/c_types/delauny_t.h +++ b/include/cpp_common/delauny_t.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: delauny_t.h +File: delauny_t.hpp Copyright (c) 2019 pgRouting developers Mail: project@pgrouting.org @@ -26,16 +26,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_DELAUNY_T_H_ -#define INCLUDE_C_TYPES_DELAUNY_T_H_ +#ifndef INCLUDE_CPP_COMMON_DELAUNY_T_HPP_ +#define INCLUDE_CPP_COMMON_DELAUNY_T_HPP_ #pragma once -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif +#include struct Delauny_t { int64_t tid; @@ -44,4 +39,4 @@ struct Delauny_t { double y; }; -#endif // INCLUDE_C_TYPES_DELAUNY_T_H_ +#endif // INCLUDE_CPP_COMMON_DELAUNY_T_HPP_ diff --git a/include/cpp_common/edge_t.hpp b/include/cpp_common/edge_t.hpp new file mode 100644 index 00000000000..06ffd2ea57f --- /dev/null +++ b/include/cpp_common/edge_t.hpp @@ -0,0 +1,43 @@ +/*PGR-GNU***************************************************************** +File: edge_t.hpp + +Copyright (c) 2017 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2017 Celia Virginia Vergara Castillo +Mail: vicky_vergara@hotmail.com + +------ + +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*/ +/*! @file */ + +#ifndef INCLUDE_CPP_COMMON_EDGE_T_HPP_ +#define INCLUDE_CPP_COMMON_EDGE_T_HPP_ +#pragma once + +#include + +struct Edge_t{ + int64_t id; + int64_t source; + int64_t target; + double cost; + double reverse_cost; +}; + +#endif // INCLUDE_CPP_COMMON_EDGE_T_HPP_ diff --git a/include/c_types/edge_xy_t.h b/include/cpp_common/edge_xy_t.hpp similarity index 84% rename from include/c_types/edge_xy_t.h rename to include/cpp_common/edge_xy_t.hpp index ba921ec0387..96edc76d1e8 100644 --- a/include/c_types/edge_xy_t.h +++ b/include/cpp_common/edge_xy_t.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: edge_xy_t.h +File: edge_xy_t.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -26,17 +26,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_EDGE_XY_T_H_ -#define INCLUDE_C_TYPES_EDGE_XY_T_H_ +#ifndef INCLUDE_CPP_COMMON_EDGE_XY_T_HPP_ +#define INCLUDE_CPP_COMMON_EDGE_XY_T_HPP_ #pragma once -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif - +#include struct Edge_xy_t { int64_t id; @@ -50,4 +44,4 @@ struct Edge_xy_t { double y2; }; -#endif // INCLUDE_C_TYPES_EDGE_XY_T_H_ +#endif // INCLUDE_CPP_COMMON_EDGE_XY_T_HPP_ diff --git a/include/cpp_common/get_check_data.hpp b/include/cpp_common/get_check_data.hpp index 8e06ce4ca6a..0849cce1f33 100644 --- a/include/cpp_common/get_check_data.hpp +++ b/include/cpp_common/get_check_data.hpp @@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_C_COMMON_GET_CHECK_DATA_HPP_ -#define INCLUDE_C_COMMON_GET_CHECK_DATA_HPP_ +#ifndef INCLUDE_CPP_COMMON_GET_CHECK_DATA_HPP_ +#define INCLUDE_CPP_COMMON_GET_CHECK_DATA_HPP_ #pragma once @@ -37,10 +37,12 @@ extern "C" { #include } -#include -#include #include +#include +#include +#include +#include "cpp_common/undefPostgresDefine.hpp" namespace pgrouting { @@ -55,6 +57,12 @@ void fetch_column_info(const TupleDesc&, std::vector&); /** @brief Function return the value of specified column in char type. */ char getChar(const HeapTuple, const TupleDesc&, const Column_info_t&, bool, char); +/** @brief get postgres array into c++ set container */ +std::set get_pgset(ArrayType*); + +/** @brief get postgres array into c++ vector container */ +std::vector get_pgarray(ArrayType*, bool); + /** @brief Enforces the input array to be @b NOT empty */ int64_t* get_array(ArrayType*, size_t*, bool); @@ -73,4 +81,4 @@ char* getText(const HeapTuple, const TupleDesc&, const Column_info_t&); } // namespace pgrouting -#endif // INCLUDE_C_COMMON_GET_CHECK_DATA_HPP_ +#endif // INCLUDE_CPP_COMMON_GET_CHECK_DATA_HPP_ diff --git a/include/cpp_common/get_data.hpp b/include/cpp_common/get_data.hpp index adf43a8c0b7..b9b93393c0f 100644 --- a/include/cpp_common/get_data.hpp +++ b/include/cpp_common/get_data.hpp @@ -29,13 +29,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_CPP_COMMON_GET_DATA_HPP_ #pragma once +#include "c_common/postgres_connection.h" + #include #include -#include "c_common/postgres_connection.h" -#include "c_types/info_t.hpp" +#include "cpp_common/info_t.hpp" #include "cpp_common/get_check_data.hpp" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/alloc.hpp" namespace pgrouting { @@ -101,6 +102,62 @@ void get_data( (*total_pgtuples) = total_tuples; } +namespace pgget { +/** @brief Retrives the tuples + * @tparam Data_type Scructure of data + * @tparam Func fetcher function + * @param[in] sql Query to be processed + * @param[in] flag useful flag depending on data + * @param[in] info information about the data + * @param[in] func fetcher function to be used + */ +template +std::vector get_data( + const std::string& sql, + bool flag, + std::vector info, + Func func) { + const int tuple_limit = 1000000; + + size_t total_tuples; + size_t valid_pgtuples; + + auto SPIplan = pgr_SPI_prepare(sql.c_str()); + auto SPIportal = pgr_SPI_cursor_open(SPIplan); + + bool moredata = true; + total_tuples = valid_pgtuples = 0; + + int64_t default_id = 0; + std::vector tuples; + + while (moredata == true) { + SPI_cursor_fetch(SPIportal, true, tuple_limit); + auto tuptable = SPI_tuptable; + auto tupdesc = SPI_tuptable->tupdesc; + if (total_tuples == 0) fetch_column_info(tupdesc, info); + + size_t ntuples = SPI_processed; + total_tuples += ntuples; + + if (ntuples > 0) { + tuples.reserve(total_tuples); + for (size_t t = 0; t < ntuples; t++) { + tuples.push_back(func(tuptable->vals[t], tupdesc, info, + &default_id, + &valid_pgtuples, flag)); + } + SPI_freetuptable(tuptable); + } else { + moredata = false; + } + } + + SPI_cursor_close(SPIportal); + return tuples; +} + +} // namespace pgget } // namespace pgrouting #endif // INCLUDE_CPP_COMMON_GET_DATA_HPP_ diff --git a/include/cpp_common/identifier.h b/include/cpp_common/identifier.hpp similarity index 90% rename from include/cpp_common/identifier.h rename to include/cpp_common/identifier.hpp index dd0d743a42b..8606a4d5562 100644 --- a/include/cpp_common/identifier.h +++ b/include/cpp_common/identifier.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** - * +File: identifier.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_IDENTIFIER_H_ -#define INCLUDE_CPP_COMMON_IDENTIFIER_H_ +#ifndef INCLUDE_CPP_COMMON_IDENTIFIER_HPP_ +#define INCLUDE_CPP_COMMON_IDENTIFIER_HPP_ #pragma once #if defined(__MINGW32__) || defined(_MSC_VER) @@ -58,4 +58,4 @@ class Identifier { } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_IDENTIFIER_H_ +#endif // INCLUDE_CPP_COMMON_IDENTIFIER_HPP_ diff --git a/include/cpp_common/identifiers.hpp b/include/cpp_common/identifiers.hpp index 8d682763729..4cc68806c38 100644 --- a/include/cpp_common/identifiers.hpp +++ b/include/cpp_common/identifiers.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: identifiers.hpp +File: identifiers.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers diff --git a/include/c_types/info_t.hpp b/include/cpp_common/info_t.hpp similarity index 91% rename from include/c_types/info_t.hpp rename to include/cpp_common/info_t.hpp index b4f20301d29..3bb6e71429c 100644 --- a/include/c_types/info_t.hpp +++ b/include/cpp_common/info_t.hpp @@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_INFO_T_HPP_ -#define INCLUDE_C_TYPES_INFO_T_HPP_ +#ifndef INCLUDE_CPP_COMMON_INFO_T_HPP_ +#define INCLUDE_CPP_COMMON_INFO_T_HPP_ #pragma once #include @@ -54,4 +54,4 @@ struct Column_info_t { } // namespace pgrouting -#endif // INCLUDE_C_TYPES_INFO_T_HPP_ +#endif // INCLUDE_CPP_COMMON_INFO_T_HPP_ diff --git a/include/cpp_common/interruption.h b/include/cpp_common/interruption.hpp similarity index 91% rename from include/cpp_common/interruption.h rename to include/cpp_common/interruption.hpp index 1706610fa7e..9140b7a4bb1 100644 --- a/include/cpp_common/interruption.h +++ b/include/cpp_common/interruption.hpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: interruption.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_CPP_COMMON_INTERRUPTION_H_ -#define INCLUDE_CPP_COMMON_INTERRUPTION_H_ +#ifndef INCLUDE_CPP_COMMON_INTERRUPTION_HPP_ +#define INCLUDE_CPP_COMMON_INTERRUPTION_HPP_ #ifdef _MSC_VER #define __PGR_PRETTY_FUNCTION__ __FUNCSIG__ @@ -51,7 +52,9 @@ extern "C" { /* * https://doxygen.postgresql.org/c_8h.html#a166c1d950e659804f0e3247aad99a81f */ +#ifndef PGDLLIMPORT #define PGDLLIMPORT +#endif /* * https://doxygen.postgresql.org/miscadmin_8h_source.html @@ -86,5 +89,6 @@ extern "C" { } +#include "cpp_common/undefPostgresDefine.hpp" -#endif // INCLUDE_CPP_COMMON_INTERRUPTION_H_ +#endif // INCLUDE_CPP_COMMON_INTERRUPTION_HPP_ diff --git a/include/cpp_common/line_vertex.h b/include/cpp_common/line_vertex.hpp similarity index 92% rename from include/cpp_common/line_vertex.h rename to include/cpp_common/line_vertex.hpp index fa5d1ddc9dc..f5f6a3c519e 100644 --- a/include/cpp_common/line_vertex.h +++ b/include/cpp_common/line_vertex.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: line_vertex.h +File: line_vertex.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -29,14 +29,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_LINE_VERTEX_H_ -#define INCLUDE_CPP_COMMON_LINE_VERTEX_H_ +#ifndef INCLUDE_CPP_COMMON_LINE_VERTEX_HPP_ +#define INCLUDE_CPP_COMMON_LINE_VERTEX_HPP_ #pragma once #include #include -#include "c_types/edge_t.h" +#include "cpp_common/edge_t.hpp" @@ -96,4 +96,4 @@ class Line_vertex { } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_LINE_VERTEX_H_ +#endif // INCLUDE_CPP_COMMON_LINE_VERTEX_HPP_ diff --git a/include/cpp_common/linear_directed_graph.h b/include/cpp_common/linear_directed_graph.hpp similarity index 86% rename from include/cpp_common/linear_directed_graph.h rename to include/cpp_common/linear_directed_graph.hpp index 46a0e3007fb..4597d931f9f 100644 --- a/include/cpp_common/linear_directed_graph.h +++ b/include/cpp_common/linear_directed_graph.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** - * +File: linear_directed_graph.hpp Copyright (c) 2017 Anthony Nicola Tasca atasca10@gmail.com @@ -23,14 +23,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_CPP_COMMON_LINEAR_DIRECTED_GRAPH_H_ -#define INCLUDE_CPP_COMMON_LINEAR_DIRECTED_GRAPH_H_ +#ifndef INCLUDE_CPP_COMMON_LINEAR_DIRECTED_GRAPH_HPP_ +#define INCLUDE_CPP_COMMON_LINEAR_DIRECTED_GRAPH_HPP_ #pragma once #include #include -#include "cpp_common/basic_edge.h" -#include "cpp_common/line_vertex.h" +#include "cpp_common/basic_edge.hpp" +#include "cpp_common/line_vertex.hpp" namespace pgrouting { @@ -56,4 +56,4 @@ typedef boost::adjacency_list < boost::vecS, boost::vecS, } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_LINEAR_DIRECTED_GRAPH_H_ +#endif // INCLUDE_CPP_COMMON_LINEAR_DIRECTED_GRAPH_HPP_ diff --git a/include/cpp_common/pgr_messages.h b/include/cpp_common/messages.hpp similarity index 93% rename from include/cpp_common/pgr_messages.h rename to include/cpp_common/messages.hpp index 87d05a69e49..2f87b1075ee 100644 --- a/include/cpp_common/pgr_messages.h +++ b/include/cpp_common/messages.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: pgr_messages.h +File: messages.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_PGR_MESSAGES_H_ -#define INCLUDE_CPP_COMMON_PGR_MESSAGES_H_ +#ifndef INCLUDE_CPP_COMMON_MESSAGES_HPP_ +#define INCLUDE_CPP_COMMON_MESSAGES_HPP_ #pragma once @@ -99,4 +98,4 @@ class Pgr_messages { } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_PGR_MESSAGES_H_ +#endif // INCLUDE_CPP_COMMON_MESSAGES_HPP_ diff --git a/include/c_types/pickDeliver/orders_t.h b/include/cpp_common/orders_t.hpp similarity index 72% rename from include/c_types/pickDeliver/orders_t.h rename to include/cpp_common/orders_t.hpp index 80ad37532ed..1c6e58897ce 100644 --- a/include/c_types/pickDeliver/orders_t.h +++ b/include/cpp_common/orders_t.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: orders_t.h +File: orders_t.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -26,23 +26,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_PICKDELIVER_ORDERS_T_H_ -#define INCLUDE_C_TYPES_PICKDELIVER_ORDERS_T_H_ +#ifndef INCLUDE_CPP_COMMON_ORDERS_T_HPP_ +#define INCLUDE_CPP_COMMON_ORDERS_T_HPP_ #pragma once -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif +#include -/************************************************************************** - * pickDelivery types - * ***********************************************************************/ -/* - * its with either (foo_x, foo_y) pairs (for euclidean or with foo_node_id (for matrix) - */ struct Orders_t { int64_t id; double demand; @@ -64,4 +53,4 @@ struct Orders_t { double deliver_service_t; }; -#endif // INCLUDE_C_TYPES_PICKDELIVER_ORDERS_T_H_ +#endif // INCLUDE_CPP_COMMON_ORDERS_T_HPP_ diff --git a/include/cpp_common/path_t.h b/include/cpp_common/path_t.hpp similarity index 89% rename from include/cpp_common/path_t.h rename to include/cpp_common/path_t.hpp index 52ecab78841..5e862bab73e 100644 --- a/include/cpp_common/path_t.h +++ b/include/cpp_common/path_t.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: path_t.h +File: path_t.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_PATH_T_H_ -#define INCLUDE_CPP_COMMON_PATH_T_H_ +#ifndef INCLUDE_CPP_COMMON_PATH_T_HPP_ +#define INCLUDE_CPP_COMMON_PATH_T_HPP_ #pragma once #include @@ -41,4 +41,4 @@ struct Path_t { int64_t pred; }; -#endif // INCLUDE_CPP_COMMON_PATH_T_H_ +#endif // INCLUDE_CPP_COMMON_PATH_T_HPP_ diff --git a/include/cpp_common/pgdata_fetchers.hpp b/include/cpp_common/pgdata_fetchers.hpp index e2566352e52..5a435476b63 100644 --- a/include/cpp_common/pgdata_fetchers.hpp +++ b/include/cpp_common/pgdata_fetchers.hpp @@ -4,8 +4,10 @@ File: pgdata_fetchers.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org +Copyright (c) 2024 Celia Virginia Vergara Castillo +- Return (C++) structure Copyright (c) 2023 Celia Virginia Vergara Castillo -mail: vicky at erosion.dev +- cat into one file Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com Copyright (c) 2016 Rohith Reddy @@ -32,8 +34,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_C_COMMON_PGDATA_FETCHERS_HPP_ -#define INCLUDE_C_COMMON_PGDATA_FETCHERS_HPP_ +#ifndef INCLUDE_CPP_COMMON_PGDATA_FETCHERS_HPP_ +#define INCLUDE_CPP_COMMON_PGDATA_FETCHERS_HPP_ #pragma once /* for HeapTuple, TupleDesc */ @@ -44,84 +46,86 @@ extern "C" { #include -using II_t_rt = struct II_t_rt; -using IID_t_rt = struct IID_t_rt; -using Coordinate_t = struct Coordinate_t; -using Delauny_t = struct Delauny_t; -using Edge_bool_t = struct Edge_bool_t; -using Edge_t = struct Edge_t; -using CostFlow_t = struct CostFlow_t; -using Edge_xy_t = struct Edge_xy_t; -using Orders_t = struct Orders_t; -using Restriction_t = struct Restriction_t; -using Point_on_edge_t = struct Point_on_edge_t; -using Vehicle_t = struct Vehicle_t; +#include "cpp_common/undefPostgresDefine.hpp" + +#include "cpp_common/info_t.hpp" +#include "c_types/ii_t_rt.h" +#include "cpp_common/coordinate_t.hpp" +#include "cpp_common/delauny_t.hpp" +#include "c_types/edge_bool_t_rt.h" +#include "cpp_common/costFlow_t.hpp" +#include "cpp_common/edge_xy_t.hpp" +#include "cpp_common/edge_t.hpp" +#include "c_types/iid_t_rt.h" +#include "cpp_common/orders_t.hpp" +#include "cpp_common/restriction_t.hpp" +#include "cpp_common/point_on_edge_t.hpp" +#include "cpp_common/vehicle_t.hpp" namespace pgrouting { -using Column_info_t = struct Column_info_t; +namespace pgget { -void fetch_combination( +II_t_rt fetch_combination( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, II_t_rt*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_coordinate( +Coordinate_t fetch_coordinate( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, Coordinate_t*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_delauny( +Delauny_t fetch_delauny( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, Delauny_t*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_basic_edge( +Edge_bool_t fetch_basic_edge( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, Edge_bool_t*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_edge( +Edge_t fetch_edge( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, Edge_t*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_costFlow_edge( +Edge_xy_t fetch_edge_xy( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, CostFlow_t*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_edge_with_xy( +CostFlow_t fetch_costFlow_edge( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, Edge_xy_t*, size_t*, bool); + int64_t*, size_t*, bool); -void pgr_fetch_row( +IID_t_rt pgr_fetch_row( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, IID_t_rt*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_orders( +Orders_t fetch_orders( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, Orders_t*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_restriction( +Restriction_t fetch_restriction( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, Restriction_t*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_point( +Point_on_edge_t fetch_point( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, Point_on_edge_t*, size_t*, bool); + int64_t*, size_t*, bool); -void fetch_vehicle( +Vehicle_t fetch_vehicle( const HeapTuple, const TupleDesc &, const std::vector &, - int64_t*, Vehicle_t*, size_t*, bool); - - + int64_t*, size_t*, bool); +} // namespace pgget } // namespace pgrouting -#endif // INCLUDE_C_COMMON_PGDATA_FETCHERS_HPP_ +#endif // INCLUDE_CPP_COMMON_PGDATA_FETCHERS_HPP_ diff --git a/include/cpp_common/pgdata_getters.hpp b/include/cpp_common/pgdata_getters.hpp new file mode 100644 index 00000000000..dcbd8c9e5bb --- /dev/null +++ b/include/cpp_common/pgdata_getters.hpp @@ -0,0 +1,115 @@ +/*PGR-GNU***************************************************************** +File: pgdata_getters.hpp + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2024 Celia Virginia Vergara Castillo +- Return C++ container +Copyright (c) 2023 Celia Virginia Vergara Castillo +- cat into one file +Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI +mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com +Copyright (c) 2016 Rohith Reddy +Copyright (c) 2016 Andrea Nardelli +mail: nrd.nardelli at gmail.com +Copyright (c) 2015 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev + +------ + +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_CPP_COMMON_PGDATA_GETTERS_HPP_ +#define INCLUDE_CPP_COMMON_PGDATA_GETTERS_HPP_ +#pragma once + +#include +#include +#include +#include +#include + + +#include "cpp_common/info_t.hpp" +#include "c_types/ii_t_rt.h" +#include "cpp_common/coordinate_t.hpp" +#include "cpp_common/delauny_t.hpp" +#include "c_types/edge_bool_t_rt.h" +#include "cpp_common/costFlow_t.hpp" +#include "cpp_common/edge_xy_t.hpp" +#include "cpp_common/edge_t.hpp" +#include "c_types/iid_t_rt.h" +#include "cpp_common/orders_t.hpp" +#include "cpp_common/restriction_t.hpp" +#include "cpp_common/point_on_edge_t.hpp" +#include "cpp_common/vehicle_t.hpp" + +typedef struct ArrayType ArrayType; + +namespace pgrouting { +namespace pgget { + +/** @brief Enforces the input array to be @b NOT empty */ +std::vector get_intArray(ArrayType*, bool); + +/** @brief Reads a postgres array saving it as set */ +std::set get_intSet(ArrayType*); + +/** @brief Read rows of combinations */ +std::vector get_combinations(const std::string&); + +/** @brief Read rows of matrix */ +std::vector get_coordinates(const std::string&); + +/** @brief Read rows of delauny triangles */ +std::vector get_delauny(const std::string&); + +/** @brief Read edges */ +std::vector get_edges(const std::string&, bool, bool); + +/** @brief Read edges with x, y endpoints */ +std::vector get_edges_xy(const std::string&, bool); + +/** @brief Read edges for flow */ +std::vector get_flow_edges(const std::string&); + +/** @brief Read edges for cost */ +std::vector get_costFlow_edges(const std::string&); + +/** @brief Read basic edges */ +std::vector get_basic_edges(const std::string&); + +/** @brief Read rows of matrix */ +std::vector get_matrixRows(const std::string&); + +/** @brief Reads the pick-Deliver orders */ +std::vector get_orders(const std::string&, bool); + +/** @brief Read rows of points */ +std::vector get_points(const std::string&); + +/** @brief Read rows of matrix */ +std::vector get_restrictions(const std::string&); + +/** @brief Reads the vehicles */ +std::vector get_vehicles(const std::string&, bool); + +} // namespace pgget +} // namespace pgrouting + +#endif // INCLUDE_CPP_COMMON_PGDATA_GETTERS_HPP_ diff --git a/include/cpp_common/pgr_base_graph.hpp b/include/cpp_common/pgr_base_graph.hpp deleted file mode 100644 index 0e3914e2729..00000000000 --- a/include/cpp_common/pgr_base_graph.hpp +++ /dev/null @@ -1,1081 +0,0 @@ -/*PGR-GNU***************************************************************** - * -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com ------- - -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*/ - -/*! @file */ - -#ifndef INCLUDE_CPP_COMMON_PGR_BASE_GRAPH_HPP_ -#define INCLUDE_CPP_COMMON_PGR_BASE_GRAPH_HPP_ -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "c_types/graph_enum.h" - -#include "cpp_common/basic_vertex.h" -#include "cpp_common/xy_vertex.h" -#include "cpp_common/basic_edge.h" - -#include "cpp_common/pgr_assert.h" - -namespace pgrouting { - -/*! @brief boost::graph simplified to pgRouting needs - This class gives the handling basics of a boost::graph of kind G - where G: - can be an undirected graph or a directed graph. -Requiremets: -============ -A vertex class T_V ------------------- -Current Available vertex classes: -- Basic_vertex -- XY_vertex -An edge class T_E ------------------ -Current Available edge classes: -- Basic_edge -extract_vertices function -------------------------- -Data obtained from postgresql is stored in -A C array of Edge_t type. -~~~~{.c} -std::vector< T_V > -extract_vertices(Edge_t *, size_t) -~~~~ -Data obtained from postgresql is stored in -o a vector container. -~~~~{.c} -std::vector< T_V > -extract_vertices(std::vector< Edge_t >) -~~~~ -Boost Graph -------------- -The code is prepared to be used for: -- boost::adjacency_list graph type -- boost::undirectedS when the graph is UNDIRECTED -- boost::bidirectionalS when the graph is DIRECTED -~~~~{.c} -boost::adjacency_list -< boost::vecS, // not tested with other values -boost::vecS, // not tested with other values -boost::undirectedS, // USinG UNDIRECTED -Basic_vertex, // the vertex class -Basic_edge > // the edge class -~~~~ -Example Usage: -============= -For this example we will use: -- Basic_vertex -- Basic_edge -- Edge_t -Create Graph type ------------------ -~~~~{.c} -typedef typename -graph::Pgr_base_graph < -boost::adjacency_list < -boost::vecS, - boost::vecS, - boost::bidirectionalS, - Basic_vertex, - Basic_edge >, - Basic_vertex, - Basic_edge > - DirectedGraph; -~~~~ -Initializing the graph ------------------------------- -Graph initialization is for seting the Vertices of the graph. -//TODO discuss if also the edges -Vector of unique vertices of the graph -~~~~{.c} -size_t total_edges; -Edge_t *my_edges = NULL; -pgr_get_edges(edges_sql, &my_edges, &total_tuples, true, false, &err_msg); -std::vector< Basic_Vertex > vertices(pgrouting::extract_vertices(my_edges)); -~~~~ -There are several ways to initialize the graph -~~~~{.c} -// 1. Initializes an empty graph -pgrouting::DirectedGraph digraph(gType); -// 2. Initializes a graph based on the vertices -pgrouting::DirectedGraph digraph( - verices, - gType); -vertices.clear(); -3. Initializes a graph based on the extracted vertices -pgrouting::DirectedGraph digraph( - pgrouting::extract_vertices(my_edges, total_edges); - gType); -4. Initializes a graph based on the extracted vertices -pgrouting::DirectedGraph digraph( - pgrouting::extract_vertices(my_edges); - gType); -~~~~ -1. Initializes an empty graph - - vertices vector size is 0 -2. Initializes a graph based on the vertices: - - vertices vector size is vertices.size() - - the vertices are inserted - - vertices container can be clared to free memory -3. Initializes a graph based on the vertices extracted - - from edges stored on a C array - - the vertices are inserted -4. Initializes a graph based on the vertices extracted - - from edges stored on a vector - - the vertices are inserted -Fill the graph ---------------------- -After initializing the graph with the vertices, the edges can be added. -~~~~{.c} -// inserting edges from a C array -digraph.insert_edges(my_edges, total_edges); -// adding more edges to the graph from a vector container -digraph.insert_edges(new_edges); -~~~~ -*/ - -namespace graph { -template -class Pgr_base_graph; - -} // namespace graph - - -/** @name Graph types - Type | pgRouting - :---------: | :--------------------- - UndirectedGraph | Basic undirected graph - DirectedGraph | Basic directed graph - xyUndirectedGraph | X & Y values stored on the vertex - xyDirectedGraph | X & Y values stored on the vertex - */ -//@{ -typedef graph::Pgr_base_graph < -boost::adjacency_list < boost::vecS, boost::vecS, - boost::undirectedS, - Basic_vertex, Basic_edge >, - Basic_vertex, Basic_edge > UndirectedGraph; - -typedef graph::Pgr_base_graph < -boost::adjacency_list < boost::vecS, boost::vecS, - boost::bidirectionalS, - Basic_vertex, Basic_edge >, - Basic_vertex, Basic_edge > DirectedGraph; - -typedef graph::Pgr_base_graph < -boost::adjacency_list < boost::listS, boost::vecS, - boost::undirectedS, - XY_vertex, Basic_edge >, - XY_vertex, Basic_edge > xyUndirectedGraph; - -typedef graph::Pgr_base_graph < -boost::adjacency_list < boost::listS, boost::vecS, - boost::bidirectionalS, - XY_vertex, Basic_edge >, - XY_vertex, Basic_edge > xyDirectedGraph; - -//@} - - -namespace graph { - -template -class Pgr_base_graph { - public: - /** @name Graph related types - Type | boost meaning | pgRouting meaning - :---------: | :-------------------- | :---------------------- - G | boost::adjacency_list | Graph - V | vertex_descriptor | Think of it as local ID of a vertex - E | edge_descriptor | Think of it as local ID of an edge - V_i | vertex_iterator | To cycle the vertices of the Graph - E_i | edge_iterator | To cycle the edges of the Graph - EO_i | out_edge_iterator | To cycle the out going edges of a vertex - EI_i | in_edge_iterator | To cycle the in coming edges of a vertex (only in bidirectional graphs) - */ - //@{ - typedef G B_G; - typedef T_E G_T_E; - typedef T_V G_T_V; - typedef typename boost::graph_traits < G >::vertex_descriptor V; - typedef typename boost::graph_traits < G >::edge_descriptor E; - typedef typename boost::graph_traits < G >::vertex_iterator V_i; - typedef typename boost::graph_traits < G >::edge_iterator E_i; - typedef typename boost::graph_traits < G >::out_edge_iterator EO_i; - typedef typename boost::graph_traits < G >::in_edge_iterator EI_i; - - typedef typename boost::graph_traits < G >::vertices_size_type - vertices_size_type; - typedef typename boost::graph_traits < G >::edges_size_type - edges_size_type; - typedef typename boost::graph_traits < G >::degree_size_type - degree_size_type; - - //@} - - /** @name Id handling related types - Type | Meaning | pgRouting Meaning - :---------: | :------------- | :---------------------- - id_to_V | maps id -> V | given an id store the V - LI | Left Iterator | iterates over id_to_V - */ - //@{ - - typedef typename std::map< int64_t, V > id_to_V; - typedef typename id_to_V::const_iterator LI; - - //@} - - //! @name The Graph - //@{ - G graph; //!< The graph - graphType m_gType; //!< type (DIRECTED or UNDIRECTED) - //@} - - //! @name Id mapping handling - //@{ - - id_to_V vertices_map; //!< id -> graph id - - typename boost::property_map::type vertIndex; - - typedef std::map IndexMap; - IndexMap mapIndex; - boost::associative_property_map propmapIndex; - - //@} - - //! @name Graph Modification - //@{ - //! Used for storing the removed_edges - - std::deque< T_E > removed_edges; - - //@} - - - - //! @name The Graph - //@{ - //! @brief Constructor - /*! - - Prepares the graph to be of type gtype - - inserts the vertices - - The vertices must be checked (if necessary) before calling the constructor - */ - Pgr_base_graph< G , T_V, T_E >( - const std::vector< T_V > &vertices, graphType gtype) - : graph(vertices.size()), -#if 0 - m_num_vertices(vertices.size()), -#endif - m_gType(gtype), - vertIndex(boost::get(boost::vertex_index, graph)), - propmapIndex(mapIndex) { - // add_vertices(vertices); - // This code does not work with contraction -#if 0 - pgassert(pgrouting::check_vertices(vertices) == 0); -#endif - size_t i = 0; - for (auto vi = boost::vertices(graph).first; - vi != boost::vertices(graph).second; ++vi) { - vertices_map[vertices[i].id] = (*vi); - graph[(*vi)].cp_members(vertices[i]); - // put(propmapIndex, *vi, num_vertices()); - pgassert(vertIndex[*vi] == i); - ++i; - } - - std::ostringstream log; - for (auto iter = vertices_map.begin(); - iter != vertices_map.end(); - iter++) { - log << "Key: " - << iter->first <<"\tValue:" << iter->second << "\n"; - } -#if 0 - /* expensive assertion */ - for (const auto vertex : vertices) { - pgassert(has_vertex(vertex.id)); - } -#endif - // pgassert(mapIndex.size() == vertices.size()); - } - - /*! - Prepares the _graph_ to be of type gtype with 0 vertices - */ - explicit Pgr_base_graph< G , T_V, T_E >(graphType gtype) - : graph(0), -#if 0 - m_num_vertices(0), -#endif - m_gType(gtype), - vertIndex(boost::get(boost::vertex_index, graph)), - propmapIndex(mapIndex) { - } - - - //! @name Insert edges - //@{ - /*! @brief Inserts *count* edges of type *T* into the graph - * - * Converts the edges to a std::vector & calls the overloaded - * twin function. - * - * @param edges - * @param count - */ - template < typename T > - void insert_edges(const T *edges, size_t count) { - insert_edges(std::vector < T >(edges, edges + count)); - } - - template < typename T > - void insert_edges_neg(const T *edges, size_t count) { - insert_edges(std::vector < T >(edges, edges + count), false); - } - - template < typename T> - void insert_edges(T *edges, size_t count, bool) { - for (size_t i = 0; i < count; ++i) { - pgassert(has_vertex(edges[i].source)); - pgassert(has_vertex(edges[i].target)); - graph_add_edge_no_create_vertex(edges[i]); - } - } - - template < typename T > - void insert_negative_edges(const T *edges, int64_t count) { - insert_negative_edges(std::vector < T >(edges, edges + count)); - } - - /*! @brief Inserts *count* edges of type *Edge_t* into the graph - The set of edges should not have an illegal vertex defined - When the graph is empty calls: - - @b extract_vertices - and throws an exception if there are illegal vertices. - When developing: - - if an illegal vertex is found an exception is thrown - - That means that the set of vertices should be checked in the - code that is being developed - No edge is inserted when there is an error on the vertices - @param edges - @param normal - */ - template - void - insert_edges(const std::vector &edges, bool normal = true) { -#if 0 - // This code does not work with contraction - if (num_vertices() == 0) { - auto vertices = pgrouting::extract_vertices(edges); - pgassert(pgrouting::check_vertices(vertices) == 0); - add_vertices(vertices); - } -#endif - for (const auto &edge : edges) { - graph_add_edge(edge, normal); - } - } - - template - void insert_min_edges_no_parallel(const T *edges, size_t count) { - insert_edges(std::vector(edges, edges + count)); - } - - template - void - insert_min_edges_no_parallel(const std::vector &edges) { - for (const auto edge : edges) { - graph_add_min_edge_no_parallel(edge); - } - } - - template < typename T > - void insert_negative_edges( - const std::vector &edges, - bool normal = true) { - for (const auto edge : edges) { - graph_add_neg_edge(edge, normal); - } - } - //@} - - private: - /*! @brief adds the vertices into the graph - * - * PRECONDITIONS: - * - The graph has not being initialized before - * - There are no dupicated vertices - * - * ~~~~~{.c} - * precondition(boost::num_vertices(graph) == 0); - * for (vertex : vertices) - * precondition(!has_vertex(vertex.id)); - * ~~~~~ - * - * - * POSTCONDITIONS: - * ~~~~~{.c} - * postcondition(boost::num_vertices(graph) == vertices.size()); - * for (vertex : vertices) - * postcondition(has_vertex(vertex.id)); - * ~~~~~ - * - * Example use: - * - * ~~~~~{.c} - * pgrouting::DirectedGraph digraph(gType); - * auto vertices(pgrouting::extract_vertices(data_edges, total_edges)); - * digraph.add_vertices(vertices); - * ~~~~~ - * - */ - void add_vertices( - std::vector< T_V > vertices) { - pgassert(num_vertices() == 0); - for (const auto vertex : vertices) { - pgassert(!has_vertex(vertex.id)); - - auto v = add_vertex(graph); - vertices_map[vertex.id] = v; - graph[v].cp_members(vertex); - // put(propmapIndex, v, num_vertices()); - - pgassert(has_vertex(vertex.id)); - } - // pgassert(mapIndex.size() == vertices.size()); - pgassert(num_vertices() == vertices.size()); - } - - - public: - //! @name boost wrappers with original id - //@{ - //! @brief get the out-degree of a vertex - - /*! - @returns 0: The out degree of a vertex that its not in the graph - @param [in] vertex_id original vertex id - */ - degree_size_type out_degree(int64_t vertex_id) const { - if (!has_vertex(vertex_id)) { - return 0; - } - auto v = get_V(vertex_id); - auto d = out_degree(v); - return d; - } - degree_size_type in_degree(int64_t vertex_id) const { - if (!has_vertex(vertex_id)) { - return 0; - } - return is_directed()? - in_degree(get_V(vertex_id)) - : out_degree(get_V(vertex_id)); - } - - - /*! @brief get the vertex descriptor of the vertex - When the vertex does not exist - - creates a new vetex - @return V: The vertex descriptor of the vertex - */ - V get_V(const T_V &vertex) { - auto vm_s(vertices_map.find(vertex.id)); - if (vm_s == vertices_map.end()) { - auto v = add_vertex(graph); - graph[v].cp_members(vertex); - vertices_map[vertex.id] = v; - put(propmapIndex, v, num_vertices()); - return v; - } - return vm_s->second; - } - - /*! @brief get the vertex descriptor of the vid - Call has_vertex(vid) before calling this function - @return V: The vertex descriptor of the vertex - */ - V get_V(int64_t vid) const { - pgassert(has_vertex(vid)); - return vertices_map.find(vid)->second; - } - - //! @brief True when vid is in the graph - bool has_vertex(int64_t vid) const { - return vertices_map.find(vid) != vertices_map.end(); - } - - - - //! @name to be or not to be - //@{ - - bool is_directed() const {return m_gType == DIRECTED;} - bool is_undirected() const {return m_gType == UNDIRECTED;} - bool is_source(V v_idx, E e_idx) const {return v_idx == source(e_idx);} - bool is_target(V v_idx, E e_idx) const {return v_idx == target(e_idx);} - - //@} - - //! @name boost wrappers with V - //@{ - - - T_E& operator[](E e_idx) {return graph[e_idx];} - const T_E& operator[](E e_idx) const {return graph[e_idx];} - - T_V& operator[](V v_idx) {return graph[v_idx];} - const T_V& operator[](V v_idx) const {return graph[v_idx];} - - V source(E e_idx) const {return boost::source(e_idx, graph);} - V target(E e_idx) const {return boost::target(e_idx, graph);} - V adjacent(V v_idx, E e_idx) const { - pgassert(is_source(v_idx, e_idx) || is_target(v_idx, e_idx)); - return is_source(v_idx, e_idx)? - target(e_idx) : - source(e_idx); - } - - - /*! @brief in degree of a vertex - * - * - when its undirected there is no "concept" of in degree - * - out degree is returned - * - on directed in degree of vertex is returned - */ - degree_size_type in_degree(V &v) const { - return is_directed()? - boost::in_degree(v, graph) : - boost::out_degree(v, graph); - } - - /*! @brief out degree of a vertex - * - * regardles of undirected or directed graph - * - out degree is returned - */ - degree_size_type out_degree(V &v) const { - return boost::out_degree(v, graph); - } - - //@} - - - //! @name edge disconection/reconnection - //@{ - //! @brief Disconnects all edges from p_from to p_to - /*! - - No edge is disconnected if the vertices id's do not exist in the graph - - All removed edges are stored for future reinsertion - - All parallel edges are disconnected (automatically by boost) - ![disconnect_edge(2,3) on an UNDIRECTED graph](disconnectEdgeUndirected.png) - ![disconnect_edge(2,3) on a DIRECTED graph](disconnectEdgeDirected.png) - @param [in] p_from original vertex id of the starting point of the edge - @param [in] p_to original vertex id of the ending point of the edge - */ - void disconnect_edge(int64_t p_from, int64_t p_to); - - - //! @brief Disconnects the outgoing edges of a vertex - /*! - - No edge is disconnected if it doesn't exist in the graph - - Removed edges are stored for future reinsertion - - all outgoing edges with the edge_id are removed if they exist - @param [in] vertex_id original vertex - @param [in] edge_id original edge_id - */ - void disconnect_out_going_edge(int64_t vertex_id, int64_t edge_id); - - - - - //! @brief Disconnects all incoming and outgoing edges from the vertex - /*! - boost::graph doesn't recommend th to insert/remove vertices, so a vertex removal is - simulated by disconnecting the vertex from the graph - - No edge is disconnected if the vertices id's do not exist in the graph - - All removed edges are stored for future reinsertion - - All parallel edges are disconnected (automatically by boost) - ![disconnect_vertex(2) on an UNDIRECTED graph](disconnectVertexUndirected.png) - ![disconnect_vertex(2) on a DIRECTED graph](disconnectVertexDirected.png) - @param [in] p_vertex original vertex id of the starting point of the edge - */ - void disconnect_vertex(int64_t p_vertex); - void disconnect_vertex(V vertex); - - - //! @brief Reconnects all edges that were removed - void restore_graph(); - - //@} - - //! @name only for stand by program - //@{ - - friend std::ostream& operator<<( - std::ostream &log, const Pgr_base_graph< G, T_V, T_E > &g) { - typename Pgr_base_graph< G, T_V, T_E >::EO_i out, out_end; - - for (auto vi = vertices(g.graph).first; - vi != vertices(g.graph).second; ++vi) { - if ((*vi) >= g.num_vertices()) break; - log << (*vi) << ": " << " out_edges_of(" << g.graph[(*vi)] << "):"; - for (boost::tie(out, out_end) = out_edges(*vi, g.graph); - out != out_end; ++out) { - log << ' ' - << g.graph[*out].id << "=(" - << g[g.source(*out)].id << ", " - << g[g.target(*out)].id << ") = " - << g.graph[*out].cost <<"\t"; - } - log << std::endl; - } - return log; - } - - //@} - - - int64_t get_edge_id(V from, V to, double &distance) const; - - E get_edge( - V from, - V to, - double &distance) const { - E e; - EO_i out_i, out_end; - V v_source, v_target; - double minCost = (std::numeric_limits::max)(); - E minEdge; - bool valid = false; - for (boost::tie(out_i, out_end) = boost::out_edges(from, graph); - out_i != out_end; ++out_i) { - e = *out_i; - if (!valid) { - minEdge = e; - valid = true; - } - v_target = target(e); - v_source = source(e); - if ((from == v_source) && (to == v_target) - && (distance == graph[e].cost)) { - return e; - } - if ((from == v_source) && (to == v_target) - && (minCost > graph[e].cost)) { - minCost = graph[e].cost; - minEdge = e; - } - } - return minEdge; - } - - size_t num_vertices() const { return boost::num_vertices(graph);} - size_t num_edges() const { return boost::num_edges(graph);} - - - void graph_add_edge(const T_E &edge); - - template < typename T > - void graph_add_edge(const T &edge, bool normal = true); - - template < typename T > - void graph_add_min_edge_no_parallel(const T &edge); - - template < typename T > - void graph_add_neg_edge(const T &edge, bool normal = true); - /** - * Use this function when the vertices are already inserted in the graph - */ - template < typename T> - void graph_add_edge_no_create_vertex(const T &edge) { - bool inserted; - E e; - if ((edge.cost < 0) && (edge.reverse_cost < 0)) - return; - -#if 0 - std::ostringstream log; - for (auto iter = vertices_map.begin(); - iter != vertices_map.end(); - iter++) { - log << "Key: " << iter->first <<"\tValue:" << iter->second << "\n"; - } - pgassertwm(has_vertex(edge.source), log.str().c_str()); - pgassert(has_vertex(edge.target)); -#endif - - auto vm_s = get_V(edge.source); - auto vm_t = get_V(edge.target); - - - if (edge.cost >= 0) { - boost::tie(e, inserted) = - boost::add_edge(vm_s, vm_t, graph); - graph[e].cost = edge.cost; - graph[e].id = edge.id; - } - - - if (edge.reverse_cost >= 0 && (is_directed() - || (is_undirected() && edge.cost != edge.reverse_cost))) { - boost::tie(e, inserted) = - boost::add_edge(vm_t, vm_s, graph); - graph[e].cost = edge.reverse_cost; - graph[e].id = edge.id; - } - } -}; - - - - -template < class G, typename T_V, typename T_E > -void -Pgr_base_graph< G, T_V, T_E >::disconnect_edge(int64_t p_from, int64_t p_to) { - T_E d_edge; - - // nothing to do, the vertex doesn't exist - if (!has_vertex(p_from) || !has_vertex(p_to)) return; - - EO_i out, out_end; - V g_from(get_V(p_from)); - V g_to(get_V(p_to)); - - // store the edges that are going to be removed - for (boost::tie(out, out_end) = out_edges(g_from, graph); - out != out_end; ++out) { - if (target(*out) == g_to) { - d_edge.id = graph[*out].id; - d_edge.source = graph[source(*out)].id; - d_edge.target = graph[target(*out)].id; - d_edge.cost = graph[*out].cost; - removed_edges.push_back(d_edge); - } - } - // the actual removal - boost::remove_edge(g_from, g_to, graph); -} - - - -template < class G, typename T_V, typename T_E > -void -Pgr_base_graph< G, T_V, T_E >::disconnect_out_going_edge( - int64_t vertex_id, int64_t edge_id) { - T_E d_edge; - - // nothing to do, the vertex doesn't exist - if (!has_vertex(vertex_id)) return; - auto v_from(get_V(vertex_id)); - - EO_i out, out_end; - bool change = true; - // store the edge that are going to be removed - while (change) { - change = false; - for (boost::tie(out, out_end) = out_edges(v_from, graph); - out != out_end; ++out) { - if (graph[*out].id == edge_id) { - d_edge.id = graph[*out].id; - d_edge.source = graph[source(*out)].id; - d_edge.target = graph[target(*out)].id; - d_edge.cost = graph[*out].cost; - removed_edges.push_back(d_edge); - boost::remove_edge((*out), graph); - change = true; - break; - } - } - } -} - - -template < class G, typename T_V, typename T_E > -void -Pgr_base_graph< G, T_V, T_E >::disconnect_vertex(int64_t vertex) { - if (!has_vertex(vertex)) return; - disconnect_vertex(get_V(vertex)); -} - -template < class G, typename T_V, typename T_E > -void -Pgr_base_graph< G, T_V, T_E >::disconnect_vertex(V vertex) { - T_E d_edge; - - EO_i out, out_end; - // store the edges that are going to be removed - for (boost::tie(out, out_end) = out_edges(vertex, graph); - out != out_end; ++out) { - d_edge.id = graph[*out].id; - d_edge.source = graph[source(*out)].id; - d_edge.target = graph[target(*out)].id; - d_edge.cost = graph[*out].cost; - removed_edges.push_back(d_edge); - } - - // special case - if (m_gType == DIRECTED) { - EI_i in, in_end; - for (boost::tie(in, in_end) = in_edges(vertex, graph); - in != in_end; ++in) { - d_edge.id = graph[*in].id; - d_edge.source = graph[source(*in)].id; - d_edge.target = graph[target(*in)].id; - d_edge.cost = graph[*in].cost; - removed_edges.push_back(d_edge); - } - } - - // delete incoming and outgoing edges from the vertex - boost::clear_vertex(vertex, graph); -} - -template < class G, typename T_V, typename T_E > -void -Pgr_base_graph< G, T_V, T_E >::restore_graph() { - while (removed_edges.size() != 0) { - graph_add_edge(removed_edges[0]); - removed_edges.pop_front(); - } -} - - - - -template < class G, typename T_V, typename T_E > -int64_t -Pgr_base_graph< G, T_V, T_E >::get_edge_id( - V from, - V to, - double &distance) const { - E e; - EO_i out_i, out_end; - V v_source, v_target; - double minCost = (std::numeric_limits::max)(); - int64_t minEdge = -1; - for (boost::tie(out_i, out_end) = boost::out_edges(from, graph); - out_i != out_end; ++out_i) { - e = *out_i; - v_target = target(e); - v_source = source(e); - if ((from == v_source) && (to == v_target) - && (distance == graph[e].cost)) - return graph[e].id; - if ((from == v_source) && (to == v_target) - && (minCost > graph[e].cost)) { - minCost = graph[e].cost; - minEdge = graph[e].id; - } - } - distance = minEdge == -1? 0: minCost; - return minEdge; -} - - -template < class G, typename T_V, typename T_E > -void -Pgr_base_graph< G, T_V, T_E >::graph_add_edge(const T_E &edge ) { - typename Pgr_base_graph< G, T_V, T_E >::LI vm_s, vm_t; - typename Pgr_base_graph< G, T_V, T_E >::E e; - - vm_s = vertices_map.find(edge.source); - if (vm_s == vertices_map.end()) { - vertices_map[edge.source]= num_vertices(); - vm_s = vertices_map.find(edge.source); - } - - vm_t = vertices_map.find(edge.target); - if (vm_t == vertices_map.end()) { - vertices_map[edge.target]= num_vertices(); - vm_t = vertices_map.find(edge.target); - } - - if (edge.cost >= 0) { - bool inserted; - boost::tie(e, inserted) = - boost::add_edge(vm_s->second, vm_t->second, graph); - graph[e].cp_members(edge); - } -} - - -template < class G, typename T_V, typename T_E > -template < typename T> -void -Pgr_base_graph< G, T_V, T_E >::graph_add_edge(const T &edge, bool normal) { - bool inserted; - typename Pgr_base_graph< G, T_V, T_E >::E e; - if ((edge.cost < 0) && (edge.reverse_cost < 0)) - return; - - /* - * true: for source - * false: for target - */ - auto vm_s = get_V(T_V(edge, true)); - auto vm_t = get_V(T_V(edge, false)); - - pgassert(vertices_map.find(edge.source) != vertices_map.end()); - pgassert(vertices_map.find(edge.target) != vertices_map.end()); - if (edge.cost >= 0) { - boost::tie(e, inserted) = - boost::add_edge(vm_s, vm_t, graph); - graph[e].cost = edge.cost; - graph[e].id = edge.id; - } - - if (edge.reverse_cost >= 0 - && (m_gType == DIRECTED - || (m_gType == UNDIRECTED && edge.cost != edge.reverse_cost))) { - boost::tie(e, inserted) = - boost::add_edge(vm_t, vm_s, graph); - - graph[e].cost = edge.reverse_cost; - graph[e].id = normal? edge.id : -edge.id; - } -} - -template < class G, typename T_V, typename T_E > -template < typename T> -void -Pgr_base_graph< G, T_V, T_E >::graph_add_min_edge_no_parallel(const T &edge) { - bool inserted; - typename Pgr_base_graph< G, T_V, T_E >::E e; - if ((edge.cost < 0) && (edge.reverse_cost < 0)) - return; - - /* - * true: for source - * false: for target - */ - auto vm_s = get_V(T_V(edge, true)); - auto vm_t = get_V(T_V(edge, false)); - - pgassert(vertices_map.find(edge.source) != vertices_map.end()); - pgassert(vertices_map.find(edge.target) != vertices_map.end()); - if (edge.cost >= 0) { - E e1; - bool found; - boost::tie(e1, found) = edge(vm_s, vm_t, graph); - if (found) { - if (edge.cost < graph[e1].cost) { - graph[e1].cost = edge.cost; - graph[e1].id = edge.id; - } - } else { - boost::tie(e, inserted) = - boost::add_edge(vm_s, vm_t, graph); - graph[e].cost = edge.cost; - graph[e].id = edge.id; - } - } - - if (edge.reverse_cost >= 0 - && (m_gType == DIRECTED - || (m_gType == UNDIRECTED && edge.cost != edge.reverse_cost))) { - E e1; - bool found; - boost::tie(e1, found) = edge(vm_t, vm_s, graph); - if (found) { - if (edge.reverse_cost < graph[e1].cost) { - graph[e1].cost = edge.reverse_cost; - graph[e1].id = edge.id; - } - } else { - boost::tie(e, inserted) = - boost::add_edge(vm_t, vm_s, graph); - - graph[e].cost = edge.reverse_cost; - graph[e].id = edge.id; - } - } -} - -#if 1 -/* -Add edges with negative cost(either cost or reverse_cost or both) -Reading them into graph as positive cost ( edge_cost = (-1)* edge_negative_cost) [L931 & L941] -To Do: Read and apply edges with negative cost in function as it is -*/ - -template < class G, typename T_V, typename T_E > -template < typename T> -void -Pgr_base_graph< G, T_V, T_E >::graph_add_neg_edge(const T &edge, bool normal) { - bool inserted; - typename Pgr_base_graph< G, T_V, T_E >::E e; - - auto vm_s = get_V(T_V(edge, true)); - auto vm_t = get_V(T_V(edge, false)); - - pgassert(vertices_map.find(edge.source) != vertices_map.end()); - pgassert(vertices_map.find(edge.target) != vertices_map.end()); - - boost::tie(e, inserted) = - boost::add_edge(vm_s, vm_t, graph); - if (edge.cost < 0) { - // reading negative edges as positive - graph[e].cost = (-0.5)*edge.cost; - } else { - graph[e].cost = edge.cost; - } - graph[e].id = edge.id; - - if (m_gType == DIRECTED - || (m_gType == UNDIRECTED && edge.cost > edge.reverse_cost)) { - boost::tie(e, inserted) = - boost::add_edge(vm_t, vm_s, graph); - if (edge.reverse_cost < 0) { - // reading negative edges as positive - graph[e].cost = (-0.5)*edge.reverse_cost; - } else { - graph[e].cost = edge.reverse_cost; - } - - graph[e].id = normal? edge.id : -edge.id; - } -} -#endif - -/****************** PRIVATE *******************/ - -} // namespace graph -} // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_PGR_BASE_GRAPH_HPP_ diff --git a/include/c_types/point_on_edge_t.h b/include/cpp_common/point_on_edge_t.hpp similarity index 83% rename from include/c_types/point_on_edge_t.h rename to include/cpp_common/point_on_edge_t.hpp index ef6f8701c55..757be20a996 100644 --- a/include/c_types/point_on_edge_t.h +++ b/include/cpp_common/point_on_edge_t.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: point_on_edge_t.h +File: point_on_edge_t.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -26,16 +26,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_POINT_ON_EDGE_T_H_ -#define INCLUDE_C_TYPES_POINT_ON_EDGE_T_H_ +#ifndef INCLUDE_CPP_COMMON_POINT_ON_EDGE_T_HPP_ +#define INCLUDE_CPP_COMMON_POINT_ON_EDGE_T_HPP_ #pragma once -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif +#include struct Point_on_edge_t { int64_t pid; @@ -45,4 +40,4 @@ struct Point_on_edge_t { int64_t vertex_id; // number is negative and is used for processing }; -#endif // INCLUDE_C_TYPES_POINT_ON_EDGE_T_H_ +#endif // INCLUDE_CPP_COMMON_POINT_ON_EDGE_T_HPP_ diff --git a/include/c_types/restriction_t.h b/include/cpp_common/restriction_t.hpp similarity index 82% rename from include/c_types/restriction_t.h rename to include/cpp_common/restriction_t.hpp index a27a77ace87..0bbd8eb559f 100644 --- a/include/c_types/restriction_t.h +++ b/include/cpp_common/restriction_t.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: restrict_t.h +File: restriction_t.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -26,16 +26,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_RESTRICTION_T_H_ -#define INCLUDE_C_TYPES_RESTRICTION_T_H_ +#ifndef INCLUDE_CPP_COMMON_RESTRICTION_T_HPP_ +#define INCLUDE_CPP_COMMON_RESTRICTION_T_HPP_ #pragma once -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif +#include +#include struct Restriction_t { double cost; @@ -43,4 +39,4 @@ struct Restriction_t { size_t via_size; }; -#endif // INCLUDE_C_TYPES_RESTRICTION_T_H_ +#endif // INCLUDE_CPP_COMMON_RESTRICTION_T_HPP_ diff --git a/include/cpp_common/rule.hpp b/include/cpp_common/rule.hpp index 34b8566a2ab..97e45aad5b7 100644 --- a/include/cpp_common/rule.hpp +++ b/include/cpp_common/rule.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: rule.hpp +File: rule.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org diff --git a/include/cpp_common/signalhandler.h b/include/cpp_common/signalhandler.h deleted file mode 100644 index b1795cf0c00..00000000000 --- a/include/cpp_common/signalhandler.h +++ /dev/null @@ -1,154 +0,0 @@ -/*PGR-GNU***************************************************************** - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ -/*PGR-MIT****************************************************************** - * - * file signalhandler.h - * - * Copyright 2014 Stephen Woodbridge - * Copyright 2014 Vicky Vergara - * - * This is free software; you can redistribute and/or modify it under - * the terms of the MIT License. Please file MIT-LICENSE for details. - * - *****************************************************************PGR-MIT*/ - -#ifndef INCLUDE_CPP_COMMON_SIGNALHANDLER_H_ -#define INCLUDE_CPP_COMMON_SIGNALHANDLER_H_ -#pragma once - -// defines NULL -#include -#include -#include - -// #include "./pgr_assert.h" - -class UserQuitException: public std::exception { - private: - const char *str; ///< str Holds the what() string for the exception. - - public: - virtual const char *what() const throw() { - return str; - } - - explicit UserQuitException(const char *_str): str(_str) {} -}; - - -class EventHandler { - public: - // Hook method for the signal hook method. - virtual void handleSignal(int signum) = 0; - - // ... other hook methods for other types of - // events such as timers, I/O, and - // synchronization objects. -}; - - -class SignalHandler { - public: - // Entry point. - static SignalHandler *instance(void); - - // Register an event handler for - // and return a pointer to any existing - // that was previously registered to handle . - EventHandler *registerHandler(int signum, EventHandler *eh); - - // Remove the for - // by setting the slot in the - // table to NULL. - void removeHandler(int signum); - - private: - // Ensure we're a Singleton. - SignalHandler(void) {} - - // Singleton pointer. - static SignalHandler *instance_; - - // Entry point adapter installed into - // (must be a static method or a stand-alone - // extern "C" function). - static void dispatcher(int signum); - - // Table of pointers to concrete s - // registered by applications. NSIG is the number of - // signals defined in . - static EventHandler *signalHandlers_[NSIG]; -}; - - -// --------------------------------------------------------- -// -- some concrete signal handlers -// --------------------------------------------------------- - -class SIGINT_Handler: public EventHandler { - public: - SIGINT_Handler(void): graceful_quit_(0) {} - - // Hook method. - virtual void handleSignal(int signum) { - if (signum == SIGINT) this->graceful_quit_ = 1; - } - - // Accessor. - sig_atomic_t gracefulQuit(void) { return this->graceful_quit_;} - - private: - sig_atomic_t graceful_quit_; -}; - - -class SIGQUIT_Handler: public EventHandler { - public: - SIGQUIT_Handler(void): abortive_quit_(0) {} - - // Hook method. - virtual void handleSignal(int signum) { - if (signum == SIGQUIT) this->abortive_quit_ = 1; - } - - // Accessor. - sig_atomic_t abortiveQuit(void) { return this->abortive_quit_;} - - private: - sig_atomic_t abortive_quit_; -}; - - -#define REG_SIGINT SIGINT_Handler sigint_handler; \ - SignalHandler::instance()->registerHandler(SIGINT, &sigint_handler); - -#define REG_SIGQUIT SIGQUIT_Handler sigquit_handler; \ - SignalHandler::instance()->registerHandler(SIGQUIT, &sigquit_handler); - -#define THROW_ON_SIGINT do { \ - if ( sigint_handler.gracefulQuit() == 1 ) \ - throw(UserQuitException("Abort on User Request!")); \ - } while (0); - -#endif // INCLUDE_CPP_COMMON_SIGNALHANDLER_H_ - diff --git a/include/cpp_common/trsp_pgfetch.hpp b/include/cpp_common/trsp_pgfetch.hpp new file mode 100644 index 00000000000..cfecff79e02 --- /dev/null +++ b/include/cpp_common/trsp_pgfetch.hpp @@ -0,0 +1,76 @@ +/*PGR-GNU***************************************************************** +File: trsp_pgfetch.hpp + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2023 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev +Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI +mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com +Copyright (c) 2016 Rohith Reddy +Copyright (c) 2016 Andrea Nardelli +mail: nrd.nardelli at gmail.com +Copyright (c) 2015 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev + +------ + +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*/ +/** @file +This is a copy of pgdata_fetchers.hpp + +The old version of TRSP +- Is the only function that has its own edge reader within its code, + hence the name of the file. +- The old version of TRSP will exist during 3.x series + + +@note +- The only function that remains is `fetch_edge` +- The old version of TRSP will be removed on V4 + + @todo: V4 TODO Delete this file +*/ + +#ifndef INCLUDE_CPP_COMMON_TRSP_PGFETCH_HPP_ +#define INCLUDE_CPP_COMMON_TRSP_PGFETCH_HPP_ + +/* for HeapTuple, TupleDesc */ +extern "C" { +#include +#include +} + +#include +#include "cpp_common/undefPostgresDefine.hpp" + +using Edge_t = struct Edge_rt; + +namespace pgrouting { +using Column_info_t = struct Column_info_t; + + +void fetch_edge( + const HeapTuple, const TupleDesc &, + const std::vector &, + int64_t*, Edge_t*, size_t*, bool); + + +} // namespace pgrouting + +#endif // INCLUDE_CPP_COMMON_TRSP_PGFETCH_HPP_ diff --git a/include/cpp_common/undefPostgresDefine.hpp b/include/cpp_common/undefPostgresDefine.hpp new file mode 100644 index 00000000000..ffa6b737bbd --- /dev/null +++ b/include/cpp_common/undefPostgresDefine.hpp @@ -0,0 +1,83 @@ +/*PGR-GNU***************************************************************** +File: undefPostgresDefine.hpp + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2024 Celia Virginia Vergara Castillo +Mail: vicky at erosion.dev + +------ + +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_CPP_COMMON_UNDEFPOSTGRESDEFINE_HPP_ +#define INCLUDE_CPP_COMMON_UNDEFPOSTGRESDEFINE_HPP_ + +/** @file undefPostgresDefine.hpp + +https://doxygen.postgresql.org/port_8h.html +Has the line +`#define snprintf pg_snprintf` + +Being `snprintf` part of [stdio.h](https://en.cppreference.com/w/cpp/header/cstdio) since C++11 +Work arount is to undef it. + +It's affecting boost 83+ + +Placing after including extern C postgres files +Example +~~~ c +extern "C" { +#include +#include +} + +#include + +#include "cpp_common/undefPostgresDefine.hpp" +~~~ + +*/ +#ifdef __cplusplus +#ifdef sprintf +#undef sprintf +#endif + +#ifdef snprintf +#undef snprintf +#endif + +#ifdef vsprintf +#undef vsprintf +#endif + +#ifdef vsnprintf +#undef vsnprintf +#endif + +#ifdef unlink +#undef unlink +#endif + +#ifdef bind +#undef bind +#endif + +#endif + +#endif // INCLUDE_CPP_COMMON_UNDEFPOSTGRESDEFINE_HPP_ diff --git a/include/c_types/pickDeliver/vehicle_t.h b/include/cpp_common/vehicle_t.hpp similarity index 79% rename from include/c_types/pickDeliver/vehicle_t.h rename to include/cpp_common/vehicle_t.hpp index 7f2bf1d2d6b..c469d86a0b3 100644 --- a/include/c_types/pickDeliver/vehicle_t.h +++ b/include/cpp_common/vehicle_t.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: vehicle_t.h +File: vehicle_t.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -26,20 +26,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_PICKDELIVER_VEHICLE_T_H_ -#define INCLUDE_C_TYPES_PICKDELIVER_VEHICLE_T_H_ +#ifndef INCLUDE_CPP_COMMON_VEHICLE_T_HPP_ +#define INCLUDE_CPP_COMMON_VEHICLE_T_HPP_ #pragma once -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif +#include -/* - * its with either (foo_x, foo_y) pairs for euclidean or with foo_node_id (for matrix) - */ struct Vehicle_t { int64_t id; double capacity; @@ -65,4 +57,4 @@ struct Vehicle_t { }; -#endif // INCLUDE_C_TYPES_PICKDELIVER_VEHICLE_T_H_ +#endif // INCLUDE_CPP_COMMON_VEHICLE_T_HPP_ diff --git a/include/cpp_common/xy_vertex.h b/include/cpp_common/xy_vertex.hpp similarity index 82% rename from include/cpp_common/xy_vertex.h rename to include/cpp_common/xy_vertex.hpp index fdacda27982..50b475aeac1 100644 --- a/include/cpp_common/xy_vertex.h +++ b/include/cpp_common/xy_vertex.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** - * +File: xy_vertex.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -27,15 +27,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_CPP_COMMON_XY_VERTEX_H_ -#define INCLUDE_CPP_COMMON_XY_VERTEX_H_ +#ifndef INCLUDE_CPP_COMMON_XY_VERTEX_HPP_ +#define INCLUDE_CPP_COMMON_XY_VERTEX_HPP_ #pragma once #include #include "cpp_common/bpoint.hpp" -#include "c_types/edge_xy_t.h" +#include "cpp_common/edge_xy_t.hpp" namespace pgrouting { @@ -80,16 +80,7 @@ std::vector < XY_vertex > extract_vertices( const std::vector &data_edges); -#if 0 -std::vector < XY_vertex > extract_vertices( - std::vector < XY_vertex > vertices, - const Edge_xy_t *data_edges, int64_t count); - -std::vector < XY_vertex > extract_vertices( - std::vector < XY_vertex > vertices, - const std::vector data_edges); -#endif } // namespace pgrouting -#endif // INCLUDE_CPP_COMMON_XY_VERTEX_H_ +#endif // INCLUDE_CPP_COMMON_XY_VERTEX_HPP_ diff --git a/include/dagShortestPath/dagShortestPath.hpp b/include/dagShortestPath/dagShortestPath.hpp new file mode 100644 index 00000000000..89797f13009 --- /dev/null +++ b/include/dagShortestPath/dagShortestPath.hpp @@ -0,0 +1,222 @@ +/*PGR-GNU***************************************************************** +File: dagShortestPath.hpp + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2018 Sourabh Garg +sourabh.garg.mat@gmail.com + +------ + +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_DAGSHORTESTPATH_DAGSHORTESTPATH_HPP_ +#define INCLUDE_DAGSHORTESTPATH_DAGSHORTESTPATH_HPP_ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" + +#include "c_types/ii_t_rt.h" + +namespace pgrouting { + +template +class Pgr_dag { + public: + typedef typename G::V V; + typedef typename G::E E; + + + /** dag 1 to many */ + std::deque dag( + G &graph, + int64_t start_vertex, + const std::set &end_vertex, + bool only_cost) { + std::deque paths; + + /* precondition */ + if (!graph.has_vertex(start_vertex)) return paths; + + /* adjust predecessors and distances vectors */ + clear(); + size_t n_goals = (std::numeric_limits::max)(); + predecessors.resize(graph.num_vertices()); + distances.resize( + graph.num_vertices(), + std::numeric_limits::infinity()); + + + auto v_source(graph.get_V(start_vertex)); + + std::set v_targets; + for (const auto &vertex : end_vertex) { + if (graph.has_vertex(vertex)) v_targets.insert(graph.get_V(vertex)); + } + if (v_targets.empty()) return paths; + + dag_1_to_many(graph, v_source, v_targets, n_goals); + paths = get_paths(graph, v_source, v_targets, only_cost); + + std::stable_sort(paths.begin(), paths.end(), + [](const Path &e1, const Path &e2)->bool { + return e1.end_id() < e2.end_id(); + }); + + return paths; + } + + + /** combinations */ + std::deque dag( + G &graph, + const std::map> &combinations, + bool only_cost) { + std::deque paths; + + for (const auto &c : combinations) { + auto result_paths = dag(graph, c.first, c.second, only_cost); + paths.insert( + paths.end(), + std::make_move_iterator(result_paths.begin()), + std::make_move_iterator(result_paths.end())); + } + + return paths; + } + + //@} + + private: + /** DAG 1 source to many targets */ + bool dag_1_to_many( + G &graph, + V source, + const std::set &targets, + size_t n_goals = (std::numeric_limits::max)()) { + CHECK_FOR_INTERRUPTS(); + try { + boost::dag_shortest_paths(graph.graph, source, + boost::predecessor_map(&predecessors[0]) + .weight_map(get(&G::G_T_E::cost, graph.graph)) + .distance_map(&distances[0]) + .distance_inf(std::numeric_limits::infinity()) + .visitor(dijkstra_many_goal_visitor(targets, n_goals))); + } catch(found_goals &) { + return true; + } catch (boost::exception const& ex) { + (void)ex; + throw; + } catch (std::exception &e) { + (void)e; + throw; + } catch (...) { + throw; + } + return true; + } + + + void clear() { + predecessors.clear(); + distances.clear(); + nodesInDistance.clear(); + } + + + + + // used when multiple goals + std::deque get_paths( + const G &graph, + V source, + std::set &targets, + bool only_cost) const { + std::deque paths; + for (const auto target : targets) { + paths.push_back(Path( + graph, + source, target, + predecessors, distances, + only_cost, true)); + } + return paths; + } + + + + //! @name members + //@{ + struct found_goals{}; //!< exception for termination + std::vector< V > predecessors; + std::vector< double > distances; + std::deque< V > nodesInDistance; + std::ostringstream log; + //@} + + + + //! class for stopping when all targets are found + class dijkstra_many_goal_visitor : public boost::default_dijkstra_visitor { + public: + explicit dijkstra_many_goal_visitor( + const std::set &goals, + size_t n_goals) : + m_goals(goals), + m_n_goals(n_goals) {} + template + void examine_vertex(V u, B_G &) { + auto s_it = m_goals.find(u); + if (s_it == m_goals.end()) return; + + // found one more goal + m_goals.erase(s_it); + + // all goals found + if (m_goals.size() == 0) throw found_goals(); + + // number of requested goals found + --m_n_goals; + if (m_n_goals == 0) throw found_goals(); + } + + private: + std::set m_goals; + size_t m_n_goals; + }; +}; + +} // namespace pgrouting + +#endif // INCLUDE_DAGSHORTESTPATH_DAGSHORTESTPATH_HPP_ diff --git a/include/dagShortestPath/pgr_dagShortestPath.hpp b/include/dagShortestPath/pgr_dagShortestPath.hpp deleted file mode 100644 index 36df617222b..00000000000 --- a/include/dagShortestPath/pgr_dagShortestPath.hpp +++ /dev/null @@ -1,367 +0,0 @@ -/*PGR-GNU***************************************************************** - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Copyright (c) 2018 Sourabh Garg -sourabh.garg.mat@gmail.com - ------- - -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_DAGSHORTESTPATH_PGR_DAGSHORTESTPATH_HPP_ -#define INCLUDE_DAGSHORTESTPATH_PGR_DAGSHORTESTPATH_HPP_ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" - -#include "c_types/ii_t_rt.h" - -namespace pgrouting { - -template < class G > -class Pgr_dag { - public: - typedef typename G::V V; - typedef typename G::E E; - - - //! Dijkstra 1 to 1 - Path dag( - G &graph, - int64_t start_vertex, - int64_t end_vertex, - bool only_cost = false) { - clear(); - - // adjust predecessors and distances vectors - predecessors.resize(graph.num_vertices()); - distances.resize( - graph.num_vertices(), - std::numeric_limits::infinity()); - - - if (!graph.has_vertex(start_vertex) - || !graph.has_vertex(end_vertex)) { - return Path(start_vertex, end_vertex); - } - - // get the graphs source and target - auto v_source(graph.get_V(start_vertex)); - auto v_target(graph.get_V(end_vertex)); - - // perform the algorithm - dag_1_to_1(graph, v_source, v_target); - - // get the results - return Path( - graph, - v_source, v_target, - predecessors, distances, - only_cost, true); - } - - - //! Dijkstra 1 to many - std::deque dag( - G &graph, - int64_t start_vertex, - const std::vector< int64_t > &end_vertex, - bool only_cost) { - // adjust predecessors and distances vectors - clear(); - size_t n_goals = (std::numeric_limits::max)(); - predecessors.resize(graph.num_vertices()); - distances.resize( - graph.num_vertices(), - std::numeric_limits::infinity()); - - - // get the graphs source and target - if (!graph.has_vertex(start_vertex)) - return std::deque(); - auto v_source(graph.get_V(start_vertex)); - - std::set< V > s_v_targets; - for (const auto &vertex : end_vertex) { - if (graph.has_vertex(vertex)) { - s_v_targets.insert(graph.get_V(vertex)); - } - } - - std::vector< V > v_targets(s_v_targets.begin(), s_v_targets.end()); - // perform the algorithm - dag_1_to_many(graph, v_source, v_targets, n_goals); - - std::deque< Path > paths; - // get the results // route id are the targets - paths = get_paths(graph, v_source, v_targets, only_cost); - - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.end_id() < e2.end_id(); - }); - - return paths; - } - - // preparation for many to 1 - std::deque dag( - G &graph, - const std::vector < int64_t > &start_vertex, - int64_t end_vertex, - bool only_cost) { - std::deque paths; - - for (const auto &start : start_vertex) { - paths.push_back( - dag(graph, start, end_vertex, only_cost)); - } - - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.start_id() < e2.start_id(); - }); - return paths; - } - - - // preparation for many to many - std::deque dag( - G &graph, - const std::vector< int64_t > &start_vertex, - const std::vector< int64_t > &end_vertex, - bool only_cost) { - // a call to 1 to many is faster for each of the sources - std::deque paths; - - for (const auto &start : start_vertex) { - auto r_paths = dag( - graph, - start, end_vertex, - only_cost); - paths.insert(paths.begin(), r_paths.begin(), r_paths.end()); - } - - std::sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.end_id() < e2.end_id(); - }); - std::stable_sort(paths.begin(), paths.end(), - [](const Path &e1, const Path &e2)->bool { - return e1.start_id() < e2.start_id(); - }); - return paths; - } - - // preparation for parallel arrays - std::deque dag( - G &graph, - const std::vector &combinations, - bool only_cost) { - std::deque paths; - - // group targets per distinct source - std::map< int64_t, std::vector > vertex_map; - for (const II_t_rt &comb : combinations) { - std::map< int64_t, std::vector >::iterator it = vertex_map.find(comb.d1.source); - if (it != vertex_map.end()) { - it->second.push_back(comb.d2.target); - } else { - std::vector targets{comb.d2.target}; - vertex_map[comb.d1.source] = targets; - } - } - - for (const auto &start_ends : vertex_map) { - auto result_paths = dag( - graph, - start_ends.first, - start_ends.second, - only_cost); - paths.insert( - paths.end(), - std::make_move_iterator(result_paths.begin()), - std::make_move_iterator(result_paths.end())); - } - - return paths; - } - - //@} - - private: - //! Call to Dijkstra 1 source to 1 target - bool dag_1_to_1( - G &graph, - V source, - V target) { - /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ - CHECK_FOR_INTERRUPTS(); - try { - boost::dag_shortest_paths(graph.graph, source, - boost::predecessor_map(&predecessors[0]) - .weight_map(get(&G::G_T_E::cost, graph.graph)) - .distance_map(&distances[0]) - .visitor(dijkstra_one_goal_visitor(target))); - } catch(found_goals &) { - return true; - } catch (boost::exception const& ex) { - (void)ex; - throw; - } catch (std::exception &e) { - (void)e; - throw; - } catch (...) { - throw; - } - return true; - } - - //! Dijkstra 1 source to many targets - bool dag_1_to_many( - G &graph, - V source, - const std::vector< V > &targets, - size_t n_goals = (std::numeric_limits::max)()) { - /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ - CHECK_FOR_INTERRUPTS(); - try { - boost::dag_shortest_paths(graph.graph, source, - boost::predecessor_map(&predecessors[0]) - .weight_map(get(&G::G_T_E::cost, graph.graph)) - .distance_map(&distances[0]) - .distance_inf(std::numeric_limits::infinity()) - .visitor(dijkstra_many_goal_visitor(targets, n_goals))); - } catch(found_goals &) { - return true; - } catch (boost::exception const& ex) { - (void)ex; - throw; - } catch (std::exception &e) { - (void)e; - throw; - } catch (...) { - throw; - } - return true; - } - - - void clear() { - predecessors.clear(); - distances.clear(); - nodesInDistance.clear(); - } - - - - - // used when multiple goals - std::deque get_paths( - const G &graph, - V source, - std::vector< V > &targets, - bool only_cost) const { - std::deque paths; - for (const auto target : targets) { - paths.push_back(Path( - graph, - source, target, - predecessors, distances, - only_cost, true)); - } - return paths; - } - - - - //! @name members - //@{ - struct found_goals{}; //!< exception for termination - std::vector< V > predecessors; - std::vector< double > distances; - std::deque< V > nodesInDistance; - std::ostringstream log; - //@} - - - //! @name Stopping classes - //@{ - //! class for stopping when 1 target is found - - class dijkstra_one_goal_visitor : public boost::default_dijkstra_visitor { - public: - explicit dijkstra_one_goal_visitor(V goal) : m_goal(goal) {} - template - void examine_vertex(V &u, B_G &) { - if (u == m_goal) throw found_goals(); - } - private: - V m_goal; - }; - - //! class for stopping when all targets are found - class dijkstra_many_goal_visitor : public boost::default_dijkstra_visitor { - public: - explicit dijkstra_many_goal_visitor( - const std::vector< V > &goals, - size_t n_goals) : - m_goals(goals.begin(), goals.end()), - m_n_goals(n_goals) {} - template - void examine_vertex(V u, B_G &) { - auto s_it = m_goals.find(u); - if (s_it == m_goals.end()) return; - - // found one more goal - m_goals.erase(s_it); - - // all goals found - if (m_goals.size() == 0) throw found_goals(); - - // number of requested goals found - --m_n_goals; - if (m_n_goals == 0) throw found_goals(); - } - - private: - std::set< V > m_goals; - size_t m_n_goals; - }; -}; - -} // namespace pgrouting - -#endif // INCLUDE_DAGSHORTESTPATH_PGR_DAGSHORTESTPATH_HPP_ diff --git a/include/dijkstra/dijkstra.hpp b/include/dijkstra/dijkstra.hpp index a4ed2825e5a..a51505d7fa0 100644 --- a/include/dijkstra/dijkstra.hpp +++ b/include/dijkstra/dijkstra.hpp @@ -1,5 +1,4 @@ /*PGR-GNU***************************************************************** - File: dijkstra.hpp Copyright (c) 2015 pgRouting developers @@ -32,8 +31,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_DIJKSTRA_PGR_DIJKSTRA_HPP_ -#define INCLUDE_DIJKSTRA_PGR_DIJKSTRA_HPP_ +#ifndef INCLUDE_DIJKSTRA_DIJKSTRA_HPP_ +#define INCLUDE_DIJKSTRA_DIJKSTRA_HPP_ #pragma once #include @@ -52,8 +51,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/ii_t_rt.h" #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "visitors/dijkstra_visitors.hpp" namespace detail { @@ -192,4 +191,4 @@ Path dijkstra( } // namespace pgrouting -#endif // INCLUDE_DIJKSTRA_PGR_DIJKSTRA_HPP_ +#endif // INCLUDE_DIJKSTRA_DIJKSTRA_HPP_ diff --git a/include/dijkstra/pgr_dijkstraVia.hpp b/include/dijkstra/dijkstraVia.hpp similarity index 94% rename from include/dijkstra/pgr_dijkstraVia.hpp rename to include/dijkstra/dijkstraVia.hpp index 5714b50f53b..0287870f90c 100644 --- a/include/dijkstra/pgr_dijkstraVia.hpp +++ b/include/dijkstra/dijkstraVia.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_dijkstraVia.hpp +File: dijkstraVia.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_DIJKSTRA_PGR_DIJKSTRAVIA_HPP_ -#define INCLUDE_DIJKSTRA_PGR_DIJKSTRAVIA_HPP_ +#ifndef INCLUDE_DIJKSTRA_DIJKSTRAVIA_HPP_ +#define INCLUDE_DIJKSTRA_DIJKSTRAVIA_HPP_ #pragma once #include @@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "dijkstra/dijkstra.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" namespace pgrouting { @@ -122,4 +122,4 @@ pgr_dijkstraVia( } // namespace pgrouting -#endif // INCLUDE_DIJKSTRA_PGR_DIJKSTRAVIA_HPP_ +#endif // INCLUDE_DIJKSTRA_DIJKSTRAVIA_HPP_ diff --git a/include/dijkstra/drivingDist.hpp b/include/dijkstra/drivingDist.hpp index 63894becc20..39858e4bf51 100644 --- a/include/dijkstra/drivingDist.hpp +++ b/include/dijkstra/drivingDist.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -file: drivingDist.hpp +File: drivingDist.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -34,31 +33,125 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_DIJKSTRA_DRIVEDIST_HPP_ -#define INCLUDE_DIJKSTRA_DRIVEDIST_HPP_ +#ifndef INCLUDE_DIJKSTRA_DRIVINGDIST_HPP_ +#define INCLUDE_DIJKSTRA_DRIVINGDIST_HPP_ #pragma once #include #include #include -#include -#include #include #include #include #include -#include + #include #include #include #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "visitors/dijkstra_visitors.hpp" +namespace bg_detail { + +/** @brief Dijkstra 1 to distance + * + * Used on: + * - 1 to distance + * - many to distance + * - On the first call of many to distance with equi_cost + * + * @param [in] bg boost graph + * @param [in] root vertex root of the spanning tree + * @param [in] distance maximum distance. + * @param [in] predecessors predecessors list + * @param [in] distances distances from root + */ +template +void dijkstra_1_to_distance( + const B_G &bg, + V root, + std::vector &predecessors, + std::vector &distances, + double distance) { + CHECK_FOR_INTERRUPTS(); + try { + boost::dijkstra_shortest_paths(bg, root, + boost::predecessor_map(&predecessors[0]) + .weight_map(get(&T_E::cost, bg)) + .distance_map(&distances[0]) + .visitor(pgrouting::visitors::dijkstra_distance_visitor(distance, distances))); + } catch(pgrouting::found_goals &) { + /*No op*/ + } catch (boost::exception const&) { + throw; + } catch (std::exception&) { + throw; + } catch (...) { + throw; + } +} + +/** @brief Dijkstra 1 to distance no initialization + * + * Used on: + * On the subsequent calls of many to distance with equi_cost + * + * @param [in] bg boost graph + * @param [in] root vertex root of the spanning tree + * @param [in] distance maximum distance. + * @param [in] predecessors predecessors list + * @param [in] distances distances from root + */ +template +void dijkstra_1_to_distance_no_init( + const B_G &bg, + V root, + std::vector &predecessors, + std::vector &distances, + double distance) { + pgassert(predecessors.size() == num_vertices(bg)); + pgassert(distances.size() == num_vertices(bg)); + + distances[root] = 0; + /* + * Not using the default, because vertices visited from other roots are marked color black + */ + std::vector color_map(num_vertices(bg)); + auto vidx(boost::get(boost::vertex_index, bg)); + + CHECK_FOR_INTERRUPTS(); + try { + boost::dijkstra_shortest_paths_no_init(bg, root, + make_iterator_property_map(predecessors.begin(), vidx), + make_iterator_property_map(distances.begin(), vidx), + get(&G_T_E::cost, bg), + vidx, + std::less(), + boost::closed_plus(), + static_cast(0), + pgrouting::visitors::dijkstra_distance_visitor_no_init(root, distance, predecessors, distances, + color_map), + make_iterator_property_map(color_map.begin(), vidx, color_map[0])); + } catch(pgrouting::found_goals &) { + /* no op */ + } catch (boost::exception const& ex) { + (void)ex; + throw; + } catch (std::exception &e) { + (void)e; + throw; + } catch (...) { + throw; + } +} + +} // namespace bg_detail + namespace detail { /* notation: @@ -68,12 +161,13 @@ namespace detail { */ template void remove_details(const G &graph, - std::vector &distances, - std::vector &predecessors) { + const std::vector &distances, + std::vector &predecessors) { /* * find all the points that are predecessors */ std::set node_with_predecessor_point; + CHECK_FOR_INTERRUPTS(); for (V v = 0; v < predecessors.size() ; ++v) { /* * skipping unreachable nodes and or initial node @@ -97,10 +191,10 @@ void remove_details(const G &graph, pgassert(graph[u].id < 0); /* - * while u is a point and its predecessor is not itself + * while u is a point and it's predecessor is not itself */ + CHECK_FOR_INTERRUPTS(); while (graph[u].id < 0 && predecessors[u] != u) { - CHECK_FOR_INTERRUPTS(); pgassert(graph[u].id < 0); pgassert(distances[v] != std::numeric_limits::infinity()); v = u; @@ -119,13 +213,14 @@ void remove_details(const G &graph, * @param [in] distances An array of vertices @b id * @param [in] predecessors an array of predecessors * @param [in] distance the max distance + * @param [in] details the max distance */ template std::map get_depth( const G &graph, V root, - std::vector &distances, - std::vector &predecessors, + const std::vector& distances, + std::vector& predecessors, double distance, bool details) { std::map depth; @@ -179,461 +274,242 @@ std::map get_depth( return depth; } -} // namespace detail +/** @brief gets results for many vertices and equi costs + * + * @param [in] graph The graph that is being worked + * @param [in] roots a set of roots + * @param [in] predecessors an array of predecessors + * @param [in] noDetailsPredecessors veritces that do not have a predecessor + * @param [in] distances a map of distances + * @param [in] distance maximum distance + * @param [in] details flag to indicate to include points + * + * @pre one predecessor per root + */ +template +std::deque get_drivingDistance_with_equicost_paths( + const G &graph, + const std::set &roots, + std::deque> &predecessors, + std::vector &distances, + std::deque> &noDetailsPredecessors, + double distance, bool details) { + using Path = pgrouting::Path; + pgassert(roots.size() == predecessors.size()); -namespace pgrouting { -// TODO(v4) convert to functions + /* + * Creating all the result "paths" + */ + std::deque paths; + for (const auto r : roots) { + paths.push_back(Path(r, r)); + paths.back().push_back({r, -1, 0, 0, r}); + } -namespace algorithm { -template < class G > class Pgr_dijkstra; -} // namespace algorithm + /* + * Ciclying the vertices: + * To which vertex do they belong to? + */ + for (V v = 0; v < distances.size(); ++v) { + /* + * Sikiping distances greater than the one asked for + */ + if (!(distances[v] <= distance)) continue; + + for (auto i = roots.size(); i > 0; --i) { + const auto &predecessor = predecessors[i - 1]; + /* + * The vertex does not exist on the graph + * The predecessor = current then its unreachable to this vertex + */ + if (predecessor.empty()) break; + if (predecessor[v] == v) continue; -template -std::deque -pgr_drivingdistance( + auto u = details? predecessor[v] : noDetailsPredecessors[i - 1][v]; + /* + * precalculating cost to find the edge + */ + auto cost = distances[v] - distances[predecessor[v]]; + auto edge_id = graph.get_edge_id(predecessor[v], v, cost); + pgassert(edge_id != -1); + /* + * real cost is with real predecessor + */ + cost = details? cost : distances[v] - distances[u]; + paths[i - 1].push_back({graph[v].id, edge_id, cost, distances[v], graph[u].id}); + break; + } + } + + for (auto &path : paths) { + path.sort_by_node_agg_cost(); + } + return paths; +} + +/* preparation for many to distance with equicost + * + * The distances vector does not change + * The predecessors vector does not change + * The first @b valid execution is done normally: + * - The distances will have: + * - inf + * - values < distance + * - values > distance + * Subsequent @b valid executions + * - will not change the: + * - values < distance + * Don't know yet what happens to predecessors + */ +template +std::deque drivingDistance_with_equicost( G &graph, - const std::vector &start_vids, - double distance, - bool equicost, + const std::set &roots, std::vector> &depths, - bool details) { - algorithm::Pgr_dijkstra fn_dijkstra; - return fn_dijkstra.drivingDistance(graph, start_vids, distance, equicost, depths, details); -} + double distance, bool details) { + using V = typename G::V; + using E = typename G::E; + using T_E = typename G::G_T_E; + using B_G = typename G::B_G; -namespace algorithm { + depths.resize(roots.size()); + std::vector predecessors(graph.num_vertices()); + std::vector distances(graph.num_vertices(), std::numeric_limits::infinity()); -template < class G > -class Pgr_dijkstra { - public: - typedef typename G::V V; - typedef typename G::E E; - - //! @name drivingDistance - //@{ - //! 1 to distance - Path drivingDistance( - G &graph, - int64_t start_vertex, - double distance) { - if (execute_drivingDistance( - graph, - start_vertex, - distance)) { - auto path = Path(graph, - start_vertex, - distance, - predecessors, - distances); - - std::sort(path.begin(), path.end(), - [](const Path_t &l, const Path_t &r) - {return l.node < r.node;}); - std::stable_sort(path.begin(), path.end(), - [](const Path_t &l, const Path_t &r) - {return l.agg_cost < r.agg_cost;}); - return path; + std::deque> pred(roots.size()); + std::deque> noDetailsPredecessors(roots.size()); + + size_t i = 0; + for (const auto &root : roots) { + /* + * The vertex does not exist Nothing to do + */ + if (!(graph.has_vertex(root))) continue; + + std::iota(predecessors.begin(), predecessors.end(), 0); + bg_detail::dijkstra_1_to_distance_no_init(graph.graph, graph.get_V(root), predecessors, + distances, distance); + + pred[i] = predecessors; + depths[i] = detail::get_depth(graph, graph.get_V(root), distances, predecessors, distance, details); + if (!details) { + noDetailsPredecessors[i] = predecessors; } + ++i; + } - /* The result is empty */ - Path p(start_vertex, start_vertex); - p.push_back({start_vertex, -1, 0, 0, 0}); - return p; - } - - // preparation for many to distance - std::deque drivingDistance( - G &graph, - const std::vector &start_vertex, - double distance, - bool equicost, - std::vector> &depths, - bool details) { - if (equicost) { - return drivingDistance_with_equicost( - graph, - start_vertex, - depths, - distance, details); - } else { - return drivingDistance_no_equicost( - graph, - start_vertex, - depths, - distance, details); - } - } - - - - - - - //@} - - - private: - /** Call to Dijkstra 1 to distance - * - * Used on: - * 1 to distance - * many to distance - * On the first call of many to distance with equi_cost - */ - bool dijkstra_1_to_distance( - G &graph, - V source, - double distance) { - /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ - CHECK_FOR_INTERRUPTS(); - try { - boost::dijkstra_shortest_paths(graph.graph, source, - boost::predecessor_map(&predecessors[0]) - .weight_map(get(&G::G_T_E::cost, graph.graph)) - .distance_map(&distances[0]) - .visitor(visitors::dijkstra_distance_visitor(distance, nodesInDistance, distances))); - } catch(found_goals &) { - /*No op*/ - } catch (boost::exception const&) { - throw; - } catch (std::exception&) { - throw; - } catch (...) { - throw; - } - return true; - } - - /** Call to Dijkstra 1 to distance no init - * - * Used on: - * On the subsequent calls of many to distance with equi_cost - */ - bool dijkstra_1_to_distance_no_init( - G &graph, - V source, - double distance) { - pgassert(predecessors.size() == graph.num_vertices()); - pgassert(distances.size() == graph.num_vertices()); - distances[source] = 0; - std::vector color_map(graph.num_vertices()); - /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ - CHECK_FOR_INTERRUPTS(); - try { - boost::dijkstra_shortest_paths_no_init(graph.graph, source, - make_iterator_property_map( - predecessors.begin(), - graph.vertIndex), - make_iterator_property_map( - distances.begin(), - graph.vertIndex), - get(&G::G_T_E::cost, graph.graph), - graph.vertIndex, - std::less(), - boost::closed_plus(), - static_cast(0), - visitors::dijkstra_distance_visitor_no_init(log, source, distance, predecessors, distances, - color_map), - boost::make_iterator_property_map( - color_map.begin(), - graph.vertIndex, - color_map[0])); - } catch(found_goals &) { - return true; - } catch (boost::exception const& ex) { - (void)ex; - throw; - } catch (std::exception &e) { - (void)e; - throw; - } catch (...) { - throw; - } + /* + * predecessors of root vertices are themselves + */ + for (const auto &root : roots) { + for (auto &p : pred) { + if (!p.empty() && graph.has_vertex(root)) + p[graph.get_V(root)] = graph.get_V(root); + } + } - return true; - } - - - /** @brief to use with driving distance - * - * Prepares the execution for a driving distance: - * - * @param graph - * @param start_vertex - * @param distance - * - * Results are kept on predecessor & distances - * - * @returns bool @b True when results are found - */ - bool execute_drivingDistance( - G &graph, - int64_t start_vertex, - double distance) { - clear(); - - predecessors.resize(graph.num_vertices()); - distances.resize( - graph.num_vertices(), - std::numeric_limits::infinity()); - - // get source; - if (!graph.has_vertex(start_vertex)) { - return false; - } + return get_drivingDistance_with_equicost_paths( + graph, + roots, + pred, + distances, + noDetailsPredecessors, + distance, details); +} - return dijkstra_1_to_distance( - graph, - graph.get_V(start_vertex), - distance); - } - - - /** @brief to use with driving distance - * - * Prepares the execution for a driving distance: - * - * @param graph - * @param start_vertex - * @param distance - * - * Results are kept on predecessor & distances - * - * @returns bool @b True when results are found - */ - bool execute_drivingDistance_no_init( - G &graph, - V start_vertex, - double distance) { - pgassert(predecessors.size() == graph.num_vertices()); - pgassert(distances.size() == graph.num_vertices()); - - std::iota(predecessors.begin(), predecessors.end(), 0); - - return dijkstra_1_to_distance_no_init( - graph, - start_vertex, - distance); - } - - /* preparation for many to distance with equicost - * - * Idea: - * The distances vector does not change - * The predecessors vector does not change - * The first @b valid execution is done normally: - * - The distances will have: - * - inf - * - values < distance - * - values > distance - * Subsequent @b valid executions - * - will not change the: - * - values < distance - * Don't know yet what happens to predecessors - */ - std::deque drivingDistance_with_equicost( - G &graph, - const std::vector &start_vertex, - std::vector> &depths, - double distance, bool details) { - clear(); - log << "Number of edges:" << boost::num_edges(graph.graph) << "\n"; - - depths.resize(start_vertex.size()); - predecessors.resize(graph.num_vertices()); - distances.resize( - graph.num_vertices(), - std::numeric_limits::infinity()); - - /* - * Vector to store the different predessesors - * each is of size = graph.num_vertices() - * - * TODO(gsoc) - * - figure out less storage if possible - */ - std::deque< std::vector> pred(start_vertex.size()); - std::deque< std::vector> nodetailspred(start_vertex.size()); - - // perform the algorithm - size_t i = 0; - for (const auto &vertex : start_vertex) { - nodesInDistance.clear(); - /* - * The vertex does not exist - * Nothing to do - */ - if (!(graph.has_vertex(vertex))) continue; - - if (execute_drivingDistance_no_init( - graph, graph.get_V(vertex), distance)) { - pred[i] = predecessors; - depths[i] = detail::get_depth(graph, graph.get_V(vertex), distances, predecessors, distance, details); - if (!details) { - nodetailspred[i] = predecessors; - } - } - ++i; - } +/** @brief gets results for many vertices and equi costs + * + * @param [in] graph The graph that is being worked + * @param [in] roots a set of roots + * @param [in] depths a vector of map of depths + * @param [in] distance maximum distance + * @param [in] details flag to indicate to include points + */ +template +std::deque drivingDistance_no_equicost( + const G &graph, + const std::set &roots, + std::vector> &depths, + double distance, bool details) { + using Path = pgrouting::Path; + using B_G = typename G::B_G; + using V = typename G::V; + using T_E = typename G::G_T_E; + std::deque paths; - /* - * predecessors of vertices in the set are themselves - */ - for (const auto &vertex : start_vertex) { - for (auto &p : pred) { - if (!p.empty() && graph.has_vertex(vertex)) - p[graph.get_V(vertex)] = graph.get_V(vertex); - } - } + for (const auto &root : roots) { + if (graph.has_vertex(root)) { + std::vector predecessors(graph.num_vertices()); + std::vector distances(graph.num_vertices(), std::numeric_limits::infinity()); + bg_detail::dijkstra_1_to_distance( + graph.graph, graph.get_V(root), predecessors, distances, distance); - return get_drivingDistance_with_equicost_paths( - graph, - start_vertex, - pred, - nodetailspred, - distance, details); - } - - /** @brief gets results in form of a container of paths - * - * @param [in] graph The graph that is being worked - * @param [in] start_vertex An array of vertices @b id - * @param [in] pred an array of predecessors - * @param [in] distance the max distance - * @pre one predecessor per root - */ - std::deque< Path > get_drivingDistance_with_equicost_paths( - G &graph, - const std::vector &start_vertex, - std::deque> &pred, - std::deque> &nodetailspred, - double distance, bool details) { - /* - * precondition - */ - pgassert(start_vertex.size() == pred.size()); - - - /* - * Creating all the result "paths" - */ - std::deque paths; - for (const auto vertex : start_vertex) { - paths.push_back(Path(vertex, vertex)); - paths.back().push_back({vertex, -1, 0, 0, vertex}); - } + auto path = Path(graph, root, distance, predecessors, distances); + path.sort_by_node_agg_cost(); + depths.push_back(detail::get_depth(graph, graph.get_V(root), distances, predecessors, distance, details)); + /* + * When details are not wanted update costs + */ + if (!details) { + for (auto &pathstop : path) { + auto node = graph.get_V(pathstop.node); - /* - * Ciclying the distances: - * To which vertex do they belong to? - */ - for (V d = 0; d < distances.size(); ++d) { - /* - * Sikiping distances greater than the one asked for - */ - if (!(distances[d] <= distance)) continue; - - for (auto i = start_vertex.size(); i > 0; --i) { - /* - * The vertex does not exist on the graph - */ - if (pred[i - 1].empty()) break; - - - /* - * The predecessor = current then - * its unreachable to this vertex - */ - if (pred[i - 1][d] == d) continue; - - auto cost = distances[d] - distances[pred[i - 1][d]]; - auto edge_id = graph.get_edge_id(pred[i - 1][d], d, cost); - int64_t pred_node = details? graph[pred[i - 1][d]].id : graph[nodetailspred[i - 1][d]].id; - pgassert(edge_id != -1); - paths[i - 1].push_back( - {graph[d].id, - edge_id, - details? cost : distances[d] - distances[nodetailspred[i - 1][d]], - distances[d], pred_node}); - break; - } - } + /* skip points */ + if (graph[node].id < 0) continue; + + pathstop.cost = distances[node] - distances[predecessors[node]]; + } + } + paths.push_back(path); + + } else { + Path p(root, root); + p.push_back({root, -1, 0, 0, root}); + paths.push_back(p); + + std::map m; + m[root] = 0; + depths.push_back(m); + } + } + return paths; +} - for (auto &path : paths) { - path.sort_by_node_agg_cost(); - } - return paths; - } - - - // preparation for many to distance No equicost - std::deque drivingDistance_no_equicost( - G &graph, - const std::vector< int64_t > &start_vertex, - std::vector> &depths, - double distance, bool details) { - // perform the algorithm - std::deque paths; - for (const auto &vertex : start_vertex) { - if (execute_drivingDistance(graph, vertex, distance)) { - auto path = Path( - graph, - vertex, - distance, - predecessors, - distances); - path.sort_by_node_agg_cost(); - auto root = graph.get_V(vertex); - depths.push_back(detail::get_depth(graph, root, distances, predecessors, distance, details)); - /* - * When details are not wanted update costs - */ - if (!details) { - for (auto &pathstop : path) { - auto node = graph.get_V(pathstop.node); - - /* skip points */ - if (graph[node].id < 0) continue; - - pathstop.cost = distances[node] - distances[predecessors[node]]; - } - log << "Updated costs of path " << path; - } - paths.push_back(path); - - } else { - Path p(vertex, vertex); - p.push_back({vertex, -1, 0, 0, vertex}); - paths.push_back(p); - std::map m; - m[vertex] = 0; - depths.push_back(m); - } - } - return paths; - } + +} // namespace detail - void clear() { - predecessors.clear(); - distances.clear(); - nodesInDistance.clear(); - } +namespace pgrouting { +namespace algorithm { - //! @name members - //@{ - std::vector predecessors; - std::vector distances; - std::deque nodesInDistance; - std::ostringstream log; - //@} -}; +template +std::deque drivingDistance( + const G &graph, + const std::set &roots, + double distance, + bool equicost, + std::vector> &depths, + bool details) { + if (equicost) { + return detail::drivingDistance_with_equicost( + graph, + roots, + depths, + distance, details); + } else { + return detail::drivingDistance_no_equicost( + graph, + roots, + depths, + distance, details); + } +} } // namespace algorithm } // namespace pgrouting -#endif // INCLUDE_DIJKSTRA_DRIVEDIST_HPP_ +#endif // INCLUDE_DIJKSTRA_DRIVINGDIST_HPP_ diff --git a/include/dominator/pgr_lengauerTarjanDominatorTree_driver.hpp b/include/dominator/lengauerTarjanDominatorTree_driver.hpp similarity index 88% rename from include/dominator/pgr_lengauerTarjanDominatorTree_driver.hpp rename to include/dominator/lengauerTarjanDominatorTree_driver.hpp index 18c5ece32d5..52c1d844a8a 100644 --- a/include/dominator/pgr_lengauerTarjanDominatorTree_driver.hpp +++ b/include/dominator/lengauerTarjanDominatorTree_driver.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_lengauerTarjanDominatorTree_driver.hpp +File: lengauerTarjanDominatorTree_driver.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -28,8 +28,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_DOMINATOR_PGR_LENGAUERTARJANDOMINATORTREE_DRIVER_HPP_ -#define INCLUDE_DOMINATOR_PGR_LENGAUERTARJANDOMINATORTREE_DRIVER_HPP_ +#ifndef INCLUDE_DOMINATOR_LENGAUERTARJANDOMINATORTREE_DRIVER_HPP_ +#define INCLUDE_DOMINATOR_LENGAUERTARJANDOMINATORTREE_DRIVER_HPP_ #pragma once #include @@ -41,9 +41,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/interruption.h" -#include "cpp_common/pgr_messages.h" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/interruption.hpp" +#include "cpp_common/messages.hpp" +#include "cpp_common/base_graph.hpp" +#include "c_types/ii_t_rt.h" namespace pgrouting { @@ -91,5 +92,5 @@ class Pgr_LTDTree : public pgrouting::Pgr_messages { }; } // namespace functions } // namespace pgrouting -#endif // INCLUDE_DOMINATOR_PGR_LENGAUERTARJANDOMINATORTREE_DRIVER_HPP_ +#endif // INCLUDE_DOMINATOR_LENGAUERTARJANDOMINATORTREE_DRIVER_HPP_ diff --git a/include/drivers/allpairs/floydWarshall_driver.h b/include/drivers/allpairs/floydWarshall_driver.h index a1850be4b4c..568923868b4 100644 --- a/include/drivers/allpairs/floydWarshall_driver.h +++ b/include/drivers/allpairs/floydWarshall_driver.h @@ -34,11 +34,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using IID_t_rt = struct IID_t_rt; #else # include -typedef struct Edge_t Edge_t; +#include typedef struct IID_t_rt IID_t_rt; #endif @@ -49,16 +48,14 @@ extern "C" { #endif void -do_pgr_floydWarshall( - Edge_t *data_edges, - size_t total_tuples, - bool directedFlag, - - // return values - IID_t_rt **ret_matrix, - size_t *return_tuple_count, - char ** log_msg, - char ** err_msg); +pgr_do_floydWarshall( + char*, + bool, + + IID_t_rt**, + size_t*, + char**, + char**); #ifdef __cplusplus } diff --git a/include/drivers/allpairs/johnson_driver.h b/include/drivers/allpairs/johnson_driver.h index 97c3a96b462..2d4306ea941 100644 --- a/include/drivers/allpairs/johnson_driver.h +++ b/include/drivers/allpairs/johnson_driver.h @@ -33,11 +33,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using IID_t_rt = struct IID_t_rt; #else # include -typedef struct Edge_t Edge_t; +#include typedef struct IID_t_rt IID_t_rt; #endif @@ -47,17 +46,14 @@ typedef struct IID_t_rt IID_t_rt; extern "C" { #endif -// CREATE OR REPLACE FUNCTION pgr_johnson(edges_sql TEXT, directed BOOLEAN, void -do_pgr_johnson( - Edge_t *data_edges, - size_t total_tuples, - bool directed, - IID_t_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** err_msg); +pgr_do_johnson( + char*, + bool, + IID_t_rt**, size_t*, + char**, + char**); #ifdef __cplusplus } diff --git a/include/drivers/alpha_shape/alphaShape_driver.h b/include/drivers/alpha_shape/alphaShape_driver.h index 40e28d5e33c..0928967b1ff 100644 --- a/include/drivers/alpha_shape/alphaShape_driver.h +++ b/include/drivers/alpha_shape/alphaShape_driver.h @@ -29,10 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #ifdef __cplusplus # include using GeomText_t = struct GeomText_t; -using Edge_xy_t = struct Edge_xy_t; #else # include -typedef struct Edge_xy_t Edge_xy_t; typedef struct GeomText_t GeomText_t; #endif @@ -40,18 +38,13 @@ typedef struct GeomText_t GeomText_t; extern "C" { #endif - void do_alphaShape( - Edge_xy_t *edgesArr, - size_t edgesTotal, +void pgr_do_alphaShape( + char*, - double alpha, + double, - GeomText_t **return_tuples, - size_t *return_count, - char **log_msg, - char **notice_msg, - - char **err_msg); + GeomText_t**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/astar/astar_driver.h b/include/drivers/astar/astar_driver.h index 4f7728f2261..3636de7c6be 100644 --- a/include/drivers/astar/astar_driver.h +++ b/include/drivers/astar/astar_driver.h @@ -31,17 +31,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_ASTAR_ASTAR_DRIVER_H_ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_xy_t = struct Edge_xy_t; -using II_t_rt = struct II_t_rt; using Path_rt = struct Path_rt; #else # include # include -typedef struct Edge_xy_t Edge_xy_t; -typedef struct II_t_rt II_t_rt; typedef struct Path_rt Path_rt; #endif @@ -49,16 +58,16 @@ typedef struct Path_rt Path_rt; extern "C" { #endif - void pgr_do_astar( - Edge_xy_t*, size_t, - II_t_rt*, size_t, - int64_t*, size_t, - int64_t*, size_t, +void pgr_do_astar( + char*, + char*, + ArrayType*, + ArrayType*, - bool, int, double, double, bool, bool, + bool, int, double, double, bool, bool, - Path_rt**, size_t*, - char**, char**, char**); + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/bdAstar/bdAstar_driver.h b/include/drivers/bdAstar/bdAstar_driver.h index c73dac74b6e..21d4d23b7e0 100644 --- a/include/drivers/bdAstar/bdAstar_driver.h +++ b/include/drivers/bdAstar/bdAstar_driver.h @@ -31,19 +31,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_BDASTAR_BDASTAR_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_xy_t = struct Edge_xy_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_xy_t Edge_xy_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus @@ -51,29 +59,15 @@ extern "C" { #endif void pgr_do_bdAstar( - Edge_xy_t *data_edges, - size_t total_edges, - - II_t_rt *combinations, - size_t total_combinations, - - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, + char*, + char*, + ArrayType*, ArrayType*, - bool directed, - int heuristic, - double factor, - double epsilon, - bool only_cost, + bool, int, double, double, bool, - Path_rt **return_tuples, - size_t *return_count, + Path_rt**, size_t*, - char** log_msg, - char** notice_msg, - char** err_msg); + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/bdDijkstra/bdDijkstra_driver.h b/include/drivers/bdDijkstra/bdDijkstra_driver.h index 6a13b338a8a..9c7ef5e6e7a 100644 --- a/include/drivers/bdDijkstra/bdDijkstra_driver.h +++ b/include/drivers/bdDijkstra/bdDijkstra_driver.h @@ -7,7 +7,7 @@ Mail: project@pgrouting.org Function's developer: Copyright (c) 2015 Celia Virginia Vergara Castillo -Mail: vicky_vergara@hotmail.com +Mail: vicky at erosion.dev ------ @@ -31,45 +31,43 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_BDDIJKSTRA_BDDIJKSTRA_DRIVER_H_ #pragma once -/* for size-t */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus extern "C" { #endif - void do_pgr_bdDijkstra( - Edge_t *data_edges, - size_t total_edges, - - II_t_rt *combinations, - size_t total_combinations, - - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, +void pgr_do_bdDijkstra( + char*, + char*, + ArrayType*, ArrayType*, - bool directed, - bool only_cost, + bool, bool, - Path_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/bellman_ford/bellman_ford_driver.h b/include/drivers/bellman_ford/bellman_ford_driver.h index 3dfb8c77164..436dc27046b 100644 --- a/include/drivers/bellman_ford/bellman_ford_driver.h +++ b/include/drivers/bellman_ford/bellman_ford_driver.h @@ -31,43 +31,43 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_BELLMAN_FORD_BELLMAN_FORD_DRIVER_H_ #pragma once -/* for size-t */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus extern "C" { #endif - void - do_pgr_bellman_ford( - Edge_t *data_edges, - size_t total_tuples, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, - bool directed, - bool only_cost, - Path_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_bellman_ford( + char*, + char*, + ArrayType*, ArrayType*, + + bool, bool, + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/bellman_ford/bellman_ford_neg_driver.h b/include/drivers/bellman_ford/bellman_ford_neg_driver.h index e60b115f04e..a64fab4ad04 100644 --- a/include/drivers/bellman_ford/bellman_ford_neg_driver.h +++ b/include/drivers/bellman_ford/bellman_ford_neg_driver.h @@ -31,44 +31,43 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_BELLMAN_FORD_BELLMAN_FORD_NEG_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include -using Edge_t = struct Edge_t; +# include using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include -typedef struct Edge_t Edge_t; +# include typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus extern "C" { #endif - void - do_pgr_bellman_ford_neg( - Edge_t *positive_edges, - size_t total_positive_edges, - Edge_t *negative_edges, - size_t total_negative_edges, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, - bool directed, - bool only_cost, - - Path_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_bellman_ford_neg( + char*, + char*, + char*, + ArrayType*, ArrayType*, + + bool, bool, + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/bellman_ford/edwardMoore_driver.h b/include/drivers/bellman_ford/edwardMoore_driver.h index 578699912aa..a2669127aa9 100644 --- a/include/drivers/bellman_ford/edwardMoore_driver.h +++ b/include/drivers/bellman_ford/edwardMoore_driver.h @@ -31,42 +31,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_BELLMAN_FORD_EDWARDMOORE_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus extern "C" { #endif - void do_pgr_edwardMoore( - Edge_t *data_edges, - size_t total_tuples, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, - bool directed, - - Path_rt **return_tuples, - size_t *return_count, - - char ** log_msg, - char ** notice_msg, - char ** err_msg); + void pgr_do_edwardMoore( + char*, + char*, + ArrayType*, ArrayType*, + + bool, + + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h b/include/drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h index 09420970d67..e7ff1d17572 100644 --- a/include/drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h +++ b/include/drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h @@ -31,51 +31,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_BREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_DRIVER_H_ #pragma once -/* for size-t */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif - #ifdef __cplusplus extern "C" { #endif - /********************************************************* - TEXT, - ANYARRAY, - ANYARRAY, - directed BOOLEAN DEFAULT true - ********************************************************/ - - - void do_pgr_binaryBreadthFirstSearch( - Edge_t *data_edges, - size_t total_tuples, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, - bool directed, - - Path_rt **return_tuples, - size_t *return_count, - - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_binaryBreadthFirstSearch( + char*, + char*, + ArrayType*, ArrayType*, + bool, + + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/breadthFirstSearch/breadthFirstSearch_driver.h b/include/drivers/breadthFirstSearch/breadthFirstSearch_driver.h index 61c4d1546bd..30711861b35 100644 --- a/include/drivers/breadthFirstSearch/breadthFirstSearch_driver.h +++ b/include/drivers/breadthFirstSearch/breadthFirstSearch_driver.h @@ -31,16 +31,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_BREADTHFIRSTSEARCH_BREADTHFIRSTSEARCH_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using MST_rt = struct MST_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct MST_rt MST_rt; #endif @@ -50,30 +60,17 @@ typedef struct MST_rt MST_rt; extern "C" { #endif - /********************************************************* - TEXT, - ANYARRAY, - max_depth BIGINT DEFAULT 9223372036854775807, - directed BOOLEAN DEFAULT true - ********************************************************/ - - - void do_pgr_breadthFirstSearch( - Edge_t *data_edges, - size_t total_tuples, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t max_depth, - bool directed, - MST_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_breadthFirstSearch( + char*, + ArrayType*, + int64_t, + bool, + MST_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus -} + } #endif #endif // INCLUDE_DRIVERS_BREADTHFIRSTSEARCH_BREADTHFIRSTSEARCH_DRIVER_H_ diff --git a/include/drivers/chinese/chinesePostman_driver.h b/include/drivers/chinese/chinesePostman_driver.h index 5ed32edecbd..59a6264a9f7 100644 --- a/include/drivers/chinese/chinesePostman_driver.h +++ b/include/drivers/chinese/chinesePostman_driver.h @@ -31,14 +31,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_CHINESE_CHINESEPOSTMAN_DRIVER_H_ #pragma once -/* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; #else # include -typedef struct Edge_t Edge_t; +#include typedef struct Path_rt Path_rt; #endif @@ -47,24 +45,13 @@ typedef struct Path_rt Path_rt; extern "C" { #endif - /********************************************************* - TEXT, - BIGINT, - BIGINT, - ********************************************************/ +void pgr_do_directedChPP( + char*, + bool, - void - do_pgr_directedChPP( - Edge_t *data_edges, - size_t total_edges, - bool only_cost, - Path_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); - + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/circuits/hawickcircuits_driver.h b/include/drivers/circuits/hawickCircuits_driver.h similarity index 82% rename from include/drivers/circuits/hawickcircuits_driver.h rename to include/drivers/circuits/hawickCircuits_driver.h index 4a7d00cb8a6..000c4ba12bb 100644 --- a/include/drivers/circuits/hawickcircuits_driver.h +++ b/include/drivers/circuits/hawickCircuits_driver.h @@ -30,8 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #ifndef INCLUDE_DRIVERS_CIRCUITS_HAWICKCIRCUITS_DRIVER_H_ #define INCLUDE_DRIVERS_CIRCUITS_HAWICKCIRCUITS_DRIVER_H_ - -/* for size-t */ #ifdef __cplusplus # include #else @@ -46,16 +44,11 @@ extern "C" { #endif void -do_hawickCircuits( - Edge_t *, // data_edges - size_t, // total_tuples - circuits_rt **, // return_tuples - size_t *, // return_count - - char **, // log_msg - char **, // notice_msg - char **); // err_msg +pgr_do_hawickCircuits( + char*, + circuits_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/coloring/bipartite_driver.h b/include/drivers/coloring/bipartite_driver.h index 8bc3bb5dfc7..0ee76c78ab0 100644 --- a/include/drivers/coloring/bipartite_driver.h +++ b/include/drivers/coloring/bipartite_driver.h @@ -34,11 +34,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using II_t_rt = struct II_t_rt; #else # include -typedef struct Edge_t Edge_t; typedef struct II_t_rt II_t_rt; #endif @@ -47,20 +45,12 @@ typedef struct II_t_rt II_t_rt; extern "C" { #endif -/********************************************************* - edges_sql TEXT, - - ********************************************************/ void -do_pgr_bipartite( - Edge_t *data_edges, - size_t total_tuples, - II_t_rt **return_tuples, - size_t *return_count, - char **log_msg, - char **notice_msg, - char **err_msg); +pgr_do_bipartite( + char*, + II_t_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/coloring/edgeColoring_driver.h b/include/drivers/coloring/edgeColoring_driver.h index 13110039c10..4b0b9104e12 100644 --- a/include/drivers/coloring/edgeColoring_driver.h +++ b/include/drivers/coloring/edgeColoring_driver.h @@ -31,36 +31,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_COLORING_EDGECOLORING_DRIVER_H_ -/* for size-t */ #ifdef __cplusplus # include +using II_t_rt = struct II_t_rt; #else # include -#endif - -typedef struct Edge_t Edge_t; typedef struct II_t_rt II_t_rt; +#endif #ifdef __cplusplus extern "C" { #endif -/********************************************************* - edges_sql TEXT, - - ********************************************************/ - void -do_pgr_edgeColoring( - Edge_t *data_edges, - size_t total_tuples, - II_t_rt **return_tuples, - size_t *return_count, - - char **log_msg, - char **notice_msg, - char **err_msg); +pgr_do_edgeColoring( + char*, + II_t_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/coloring/sequentialVertexColoring_driver.h b/include/drivers/coloring/sequentialVertexColoring_driver.h index f1098cc89d6..7880cdbea01 100644 --- a/include/drivers/coloring/sequentialVertexColoring_driver.h +++ b/include/drivers/coloring/sequentialVertexColoring_driver.h @@ -31,14 +31,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_COLORING_SEQUENTIALVERTEXCOLORING_DRIVER_H_ #pragma once -/* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using II_t_rt = struct II_t_rt; #else # include -typedef struct Edge_t Edge_t; typedef struct II_t_rt II_t_rt; #endif @@ -47,23 +44,11 @@ typedef struct II_t_rt II_t_rt; extern "C" { #endif - /************************************************** - * - * pgr_sequentialVertexColoring( - * edges_sql TEXT - * ); - * - *************************************************/ - void do_pgr_sequentialVertexColoring( - Edge_t *data_edges, - size_t total_edges, +void pgr_do_sequentialVertexColoring( + char*, - II_t_rt **return_tuples, - size_t *return_count, - - char ** log_msg, - char ** notice_msg, - char ** err_msg); + II_t_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/components/articulationPoints_driver.h b/include/drivers/components/articulationPoints_driver.h index 7b15b88679f..ab6b5ef024c 100644 --- a/include/drivers/components/articulationPoints_driver.h +++ b/include/drivers/components/articulationPoints_driver.h @@ -47,22 +47,11 @@ typedef struct Edge_t Edge_t; extern "C" { #endif - /********************************************************* - TEXT, - BIGINT, - BIGINT, - ********************************************************/ - - - void - do_pgr_articulationPoints( - Edge_t *data_edges, - size_t total_edges, - int64_t **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_articulationPoints( + char*, + int64_t**, size_t*, + + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/components/biconnectedComponents_driver.h b/include/drivers/components/biconnectedComponents_driver.h index d4d642d9eb2..cac3ab1ff7c 100644 --- a/include/drivers/components/biconnectedComponents_driver.h +++ b/include/drivers/components/biconnectedComponents_driver.h @@ -47,23 +47,11 @@ typedef struct II_t_rt II_t_rt; extern "C" { #endif - /********************************************************* - TEXT, - BIGINT, - BIGINT, - ********************************************************/ - - - void - do_pgr_biconnectedComponents( - Edge_t *data_edges, - size_t total_edges, - II_t_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_biconnectedComponents( + char*, + II_t_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/components/bridges_driver.h b/include/drivers/components/bridges_driver.h index a279ac3ed30..df661aa5976 100644 --- a/include/drivers/components/bridges_driver.h +++ b/include/drivers/components/bridges_driver.h @@ -31,15 +31,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_COMPONENTS_BRIDGES_DRIVER_H_ #pragma once -/* for size-t */ #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; #else # include # include -typedef struct Edge_t Edge_t; #endif @@ -48,23 +45,11 @@ typedef struct Edge_t Edge_t; extern "C" { #endif - /********************************************************* - TEXT, - BIGINT, - BIGINT, - ********************************************************/ - - - void - do_pgr_bridges( - Edge_t *data_edges, - size_t total_edges, - int64_t **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_bridges( + char*, + int64_t**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/components/connectedComponents_driver.h b/include/drivers/components/connectedComponents_driver.h index 75fbeb93976..8c64127971a 100644 --- a/include/drivers/components/connectedComponents_driver.h +++ b/include/drivers/components/connectedComponents_driver.h @@ -31,14 +31,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_COMPONENTS_CONNECTEDCOMPONENTS_DRIVER_H_ #pragma once -/* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using II_t_rt = struct II_t_rt; #else # include -typedef struct Edge_t Edge_t; typedef struct II_t_rt II_t_rt; #endif @@ -47,23 +44,11 @@ typedef struct II_t_rt II_t_rt; extern "C" { #endif - /********************************************************* - TEXT, - BIGINT, - BIGINT, - ********************************************************/ - - - void - do_pgr_connectedComponents( - Edge_t *data_edges, - size_t total_edges, - II_t_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_connectedComponents( + char*, + II_t_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/components/makeConnected_driver.h b/include/drivers/components/makeConnected_driver.h index baafdab98bb..d2daa9af564 100644 --- a/include/drivers/components/makeConnected_driver.h +++ b/include/drivers/components/makeConnected_driver.h @@ -31,14 +31,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_COMPONENTS_MAKECONNECTED_DRIVER_H_ #pragma once -/* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using II_t_rt = struct II_t_rt; #else # include -typedef struct Edge_t Edge_t; typedef struct II_t_rt II_t_rt; #endif @@ -47,20 +44,11 @@ typedef struct II_t_rt II_t_rt; extern "C" { #endif - /********************************************************* - TEXT - ********************************************************/ - - - void do_pgr_makeConnected( - Edge_t *data_edges, - size_t total_tuples, - II_t_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_makeConnected( + char*, + II_t_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/components/strongComponents_driver.h b/include/drivers/components/strongComponents_driver.h index 7bb3c2a8179..614851b240f 100644 --- a/include/drivers/components/strongComponents_driver.h +++ b/include/drivers/components/strongComponents_driver.h @@ -31,14 +31,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_COMPONENTS_STRONGCOMPONENTS_DRIVER_H_ #pragma once -/* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using II_t_rt = struct II_t_rt; #else # include -typedef struct Edge_t Edge_t; typedef struct II_t_rt II_t_rt; #endif @@ -47,23 +44,11 @@ typedef struct II_t_rt II_t_rt; extern "C" { #endif - /********************************************************* - TEXT, - BIGINT, - BIGINT, - ********************************************************/ - - - void - do_pgr_strongComponents( - Edge_t *data_edges, - size_t total_edges, - II_t_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_strongComponents( + char*, + II_t_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/contraction/contractGraph_driver.h b/include/drivers/contraction/contractGraph_driver.h index 15dff915628..28719d6ef39 100644 --- a/include/drivers/contraction/contractGraph_driver.h +++ b/include/drivers/contraction/contractGraph_driver.h @@ -30,17 +30,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_CONTRACTION_CONTRACTGRAPH_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include using contracted_rt = struct contracted_rt; -using Edge_t = struct Edge_t; #else # include # include typedef struct contracted_rt contracted_rt; -typedef struct Edge_t Edge_t; #endif @@ -48,29 +58,14 @@ typedef struct Edge_t Edge_t; extern "C" { #endif - /********************************************************* - edges_sql TEXT, - contraction_order BIGINT[], - forbidden_vertices BIGINT[] DEFAULT ARRAY[]::BIGINT[], - max_cycles integer DEFAULT 1, - directed BOOLEAN DEFAULT true - ********************************************************/ - void - do_pgr_contractGraph( - Edge_t *data_edges, - size_t total_tuples, - int64_t *forbidden_vertices, - size_t size_forbidden_vertices, - int64_t *contraction_order, - size_t size_contraction_order, - int64_t max_cycles, - bool directed, - contracted_rt **return_tuples, - size_t *return_count, - char **log_msg, - char **notice_msg, - char **err_msg); +void pgr_do_contractGraph( + char*, + ArrayType*, ArrayType*, + + int64_t, bool, + contracted_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/dagShortestPath/dagShortestPath_driver.h b/include/drivers/dagShortestPath/dagShortestPath_driver.h index 701609ca162..955cf5844ec 100644 --- a/include/drivers/dagShortestPath/dagShortestPath_driver.h +++ b/include/drivers/dagShortestPath/dagShortestPath_driver.h @@ -31,19 +31,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_DAGSHORTESTPATH_DAGSHORTESTPATH_DRIVER_H_ #pragma once -/* for size-t */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus @@ -51,23 +60,13 @@ extern "C" { #endif - void - do_pgr_dagShortestPath( - Edge_t *data_edges, - size_t total_tuples, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, - bool directed, - bool only_cost, - Path_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_dagShortestPath( + char*, + char*, + ArrayType*, ArrayType*, + bool, bool, + Path_rt **, size_t*, + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/dijkstra/dijkstraVia_driver.h b/include/drivers/dijkstra/dijkstraVia_driver.h index 522ad614532..594219cb4c7 100644 --- a/include/drivers/dijkstra/dijkstraVia_driver.h +++ b/include/drivers/dijkstra/dijkstraVia_driver.h @@ -1,11 +1,13 @@ /*PGR-GNU***************************************************************** -File: dijkstraViaVertex.c +File: dijkstraVia_driver.h Generated with Template by: Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org Function's developer: Copyright (c) 2015 Celia Virginia Vergara Castillo +Mail: vicky at erosion.dev ------ @@ -29,42 +31,41 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_DIJKSTRA_DIJKSTRAVIA_DRIVER_H_ #pragma once -/* for size-t */ #ifdef __cplusplus -# include +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + +#ifdef __cplusplus # include -using Edge_t = struct Edge_t; +# include using Routes_t = struct Routes_t; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Routes_t Routes_t; #endif - #ifdef __cplusplus extern "C" { #endif - /* - CREATE OR REPLACE FUNCTION pgr_dijkstraViaVertices( - sql text, - vertices anyarray, - directed boolean default true, - */ - void - do_pgr_dijkstraVia( - Edge_t *data_edges, size_t total_edges, - int64_t *via_vidsArr, size_t size_via_vidsArr, - bool directed, - bool strict, - bool U_turn_on_edge, - Routes_t **return_tuples, size_t *return_count, - - char** log_msg, - char** notice_msg, - char** err_msg); +void pgr_do_dijkstraVia( + char*, + ArrayType*, + + bool, bool, bool, + + Routes_t**, size_t *, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/dijkstra/dijkstra_driver.h b/include/drivers/dijkstra/dijkstra_driver.h index 84d85112960..a5d32e6e894 100644 --- a/include/drivers/dijkstra/dijkstra_driver.h +++ b/include/drivers/dijkstra/dijkstra_driver.h @@ -35,19 +35,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #ifndef INCLUDE_DRIVERS_DIJKSTRA_DIJKSTRA_DRIVER_H_ #define INCLUDE_DRIVERS_DIJKSTRA_DIJKSTRA_DRIVER_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus @@ -55,10 +65,9 @@ extern "C" { #endif void pgr_do_dijkstra( - Edge_t*, size_t, - II_t_rt*, size_t, - int64_t*, size_t, - int64_t*, size_t, + char*, + char*, + ArrayType*, ArrayType*, bool, bool, bool, int64_t, bool, @@ -66,7 +75,6 @@ void pgr_do_dijkstra( Path_rt**, size_t*, char**, char**, char**); - #ifdef __cplusplus } #endif diff --git a/include/drivers/dominator/lengauerTarjanDominatorTree_driver.h b/include/drivers/dominator/lengauerTarjanDominatorTree_driver.h index 7c201fb958f..a3460f74b71 100644 --- a/include/drivers/dominator/lengauerTarjanDominatorTree_driver.h +++ b/include/drivers/dominator/lengauerTarjanDominatorTree_driver.h @@ -31,14 +31,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_DOMINATOR_LENGAUERTARJANDOMINATORTREE_DRIVER_H_ #pragma once -/* for size-t */ #ifdef __cplusplus +# include # include -using Edge_t = struct Edge_t; using II_t_rt = struct II_t_rt; #else # include -typedef struct Edge_t Edge_t; +# include typedef struct II_t_rt II_t_rt; #endif @@ -48,20 +47,13 @@ typedef struct II_t_rt II_t_rt; extern "C" { #endif -/********************************************************* - edges_sql TEXT, - - ********************************************************/ -void -do_pgr_LTDTree( - Edge_t *data_edges, - size_t total_tuples, - int64_t root_vertex, - II_t_rt **return_tuples, - size_t *return_count, - char **log_msg, - char **notice_msg, - char **err_msg); +void pgr_do_LTDTree( + char*, + + int64_t, + + II_t_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/driving_distance/drivedist_driver.h b/include/drivers/driving_distance/driving_distance_driver.h similarity index 71% rename from include/drivers/driving_distance/drivedist_driver.h rename to include/drivers/driving_distance/driving_distance_driver.h index 2d98ed3f63e..7a37facf8c0 100644 --- a/include/drivers/driving_distance/drivedist_driver.h +++ b/include/drivers/driving_distance/driving_distance_driver.h @@ -27,18 +27,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_DRIVERS_DRIVING_DISTANCE_DRIVEDIST_DRIVER_H_ -#define INCLUDE_DRIVERS_DRIVING_DISTANCE_DRIVEDIST_DRIVER_H_ +#ifndef INCLUDE_DRIVERS_DRIVING_DISTANCE_DRIVING_DISTANCE_DRIVER_H_ +#define INCLUDE_DRIVERS_DRIVING_DISTANCE_DRIVING_DISTANCE_DRIVER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using MST_rt = struct MST_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct MST_rt MST_rt; #endif @@ -46,16 +57,15 @@ typedef struct MST_rt MST_rt; extern "C" { #endif -void pgr_do_drivingdist( - Edge_t* , size_t , - int64_t* , size_t , - double , - bool, bool, - MST_rt** , size_t* r, - char **, char **, char **); +void pgr_do_drivingDistance( + char*, + ArrayType*, + double, bool, bool, + MST_rt**, size_t*, + char**, char**, char **); #ifdef __cplusplus } #endif -#endif // INCLUDE_DRIVERS_DRIVING_DISTANCE_DRIVEDIST_DRIVER_H_ +#endif // INCLUDE_DRIVERS_DRIVING_DISTANCE_DRIVING_DISTANCE_DRIVER_H_ diff --git a/include/drivers/driving_distance/withPoints_dd_driver.h b/include/drivers/driving_distance/driving_distance_withPoints_driver.h similarity index 66% rename from include/drivers/driving_distance/withPoints_dd_driver.h rename to include/drivers/driving_distance/driving_distance_withPoints_driver.h index 6f7897f1721..c4d1c8fba2e 100644 --- a/include/drivers/driving_distance/withPoints_dd_driver.h +++ b/include/drivers/driving_distance/driving_distance_withPoints_driver.h @@ -29,23 +29,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_DRIVERS_DRIVING_DISTANCE_WITHPOINTS_DD_DRIVER_H_ -#define INCLUDE_DRIVERS_DRIVING_DISTANCE_WITHPOINTS_DD_DRIVER_H_ +#ifndef INCLUDE_DRIVERS_DRIVING_DISTANCE_DRIVING_DISTANCE_WITHPOINTS_DRIVER_H_ +#define INCLUDE_DRIVERS_DRIVING_DISTANCE_DRIVING_DISTANCE_WITHPOINTS_DRIVER_H_ #pragma once -/* for size-t */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Point_on_edge_t = struct Point_on_edge_t; -using Edge_t = struct Edge_t; -using Path_rt = struct Path_rt; using MST_rt = struct MST_rt; #else # include # include -typedef struct Point_on_edge_t Point_on_edge_t; -typedef struct Edge_t Edge_t; typedef struct MST_rt MST_rt; #endif @@ -53,19 +61,19 @@ typedef struct MST_rt MST_rt; extern "C" { #endif - void pgr_do_withPointsDD( - Edge_t*, size_t, - Point_on_edge_t*, size_t, - Edge_t*, size_t, - int64_t*, size_t, +void pgr_do_withPointsDD( + char*, + char*, + char*, + ArrayType*, - double, char, bool, bool, bool, + double, char, bool, bool, bool, - MST_rt**, size_t*, - char**, char**, char **); + MST_rt**, size_t*, + char**, char**, char **); #ifdef __cplusplus } #endif -#endif // INCLUDE_DRIVERS_DRIVING_DISTANCE_WITHPOINTS_DD_DRIVER_H_ +#endif // INCLUDE_DRIVERS_DRIVING_DISTANCE_DRIVING_DISTANCE_WITHPOINTS_DRIVER_H_ diff --git a/include/drivers/lineGraph/lineGraphFull_driver.h b/include/drivers/lineGraph/lineGraphFull_driver.h index c12b64032c0..6498e71b7ef 100644 --- a/include/drivers/lineGraph/lineGraphFull_driver.h +++ b/include/drivers/lineGraph/lineGraphFull_driver.h @@ -34,11 +34,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using Line_graph_full_rt = struct Line_graph_full_rt; #else # include -typedef struct Edge_t Edge_t; typedef struct Line_graph_full_rt Line_graph_full_rt; #endif @@ -46,16 +44,11 @@ typedef struct Line_graph_full_rt Line_graph_full_rt; extern "C" { #endif - void - do_pgr_lineGraphFull( - Edge_t *data_edges, - size_t total_edges, - Line_graph_full_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_lineGraphFull( + char*, + Line_graph_full_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/lineGraph/lineGraph_driver.h b/include/drivers/lineGraph/lineGraph_driver.h index bbbc6550376..d77933e5b94 100644 --- a/include/drivers/lineGraph/lineGraph_driver.h +++ b/include/drivers/lineGraph/lineGraph_driver.h @@ -34,10 +34,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; +using Edge_rt = struct Edge_rt; #else # include -typedef struct Edge_t Edge_t; +#include +typedef struct Edge_rt Edge_rt; #endif @@ -45,23 +46,13 @@ typedef struct Edge_t Edge_t; extern "C" { #endif - /********************************************************* - TEXT, - directed BOOLEAN DEFAULT true, - ********************************************************/ +void pgr_do_lineGraph( + char*, + bool, - void - do_pgr_lineGraph( - Edge_t *data_edges, - size_t total_edges, - bool directed, - Edge_t **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); - + Edge_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/max_flow/edge_disjoint_paths_driver.h b/include/drivers/max_flow/edge_disjoint_paths_driver.h index 785531b7c72..0b11e46d6cd 100644 --- a/include/drivers/max_flow/edge_disjoint_paths_driver.h +++ b/include/drivers/max_flow/edge_disjoint_paths_driver.h @@ -31,19 +31,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_MAX_FLOW_EDGE_DISJOINT_PATHS_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif @@ -51,23 +59,15 @@ typedef struct II_t_rt II_t_rt; extern "C" { #endif - void - do_pgr_edge_disjoint_paths( - Edge_t *data_edges, - size_t total_tuples, - II_t_rt *combinations, - size_t total_combinations, - int64_t *source_vertices, - size_t size_source_verticesArr, - int64_t *sink_vertices, - size_t size_sink_verticesArr, - bool directed, - Path_rt **return_tuples, - size_t *return_count, - char** log_msg, - char** notice_msg, - char** err_msg); +void pgr_do_edge_disjoint_paths( + char*, + char*, + ArrayType*, ArrayType*, + + bool, + Path_rt**, size_t *, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/max_flow/max_flow_driver.h b/include/drivers/max_flow/max_flow_driver.h index e7d485607d8..5641624ee5f 100644 --- a/include/drivers/max_flow/max_flow_driver.h +++ b/include/drivers/max_flow/max_flow_driver.h @@ -31,45 +31,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_MAX_FLOW_MAX_FLOW_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Flow_t = struct Flow_t; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Flow_t Flow_t; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus extern "C" { #endif - void - do_pgr_max_flow( - Edge_t *data_edges, - size_t total_tuples, - - II_t_rt *combinations, - size_t total_combinations, - - int64_t* source_vertices, - size_t size_source_verticesArr, - int64_t* sink_vertices, - size_t size_sink_verticesArr, - int algorithm, - bool only_flow, - Flow_t **return_tuples, - size_t *return_count, - char** log_msg, - char** notice_msg, - char** err_msg); +void pgr_do_max_flow( + char*, + char*, + ArrayType*, ArrayType*, + + int, bool, + Flow_t**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/max_flow/maximum_cardinality_matching_driver.h b/include/drivers/max_flow/maximum_cardinality_matching_driver.h index d720e99588f..c196b614857 100644 --- a/include/drivers/max_flow/maximum_cardinality_matching_driver.h +++ b/include/drivers/max_flow/maximum_cardinality_matching_driver.h @@ -31,13 +31,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_MAX_FLOW_MAXIMUM_CARDINALITY_MATCHING_DRIVER_H_ #pragma once -#include - #ifdef __cplusplus -using Edge_bool_t = struct Edge_bool_t; +#include using Only_int_rt = struct Only_int_rt; #else -typedef struct Edge_bool_t Edge_bool_t; +#include +#include typedef struct Only_int_rt Only_int_rt; #endif @@ -45,9 +44,11 @@ typedef struct Only_int_rt Only_int_rt; extern "C" { #endif - void - do_pgr_maximum_cardinality_matching( - Edge_bool_t*, size_t, bool, +void pgr_do_maximum_cardinality_matching( + char*, + + bool, + Only_int_rt **, size_t *, char**, char**, char **); diff --git a/include/drivers/max_flow/minCostMaxFlow_driver.h b/include/drivers/max_flow/minCostMaxFlow_driver.h index 2b0b7c8e917..d09087c9d94 100644 --- a/include/drivers/max_flow/minCostMaxFlow_driver.h +++ b/include/drivers/max_flow/minCostMaxFlow_driver.h @@ -31,19 +31,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_MAX_FLOW_MINCOSTMAXFLOW_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using CostFlow_t = struct CostFlow_t; using Flow_t = struct Flow_t; -using II_t_rt = struct II_t_rt; #else # include # include typedef struct Flow_t Flow_t; -typedef struct Flow_t Flow_t; -typedef struct II_t_rt II_t_rt; #endif @@ -52,22 +60,15 @@ typedef struct II_t_rt II_t_rt; extern "C" { #endif - void - do_pgr_minCostMaxFlow( - CostFlow_t *data_edges, - size_t total_edges, - II_t_rt *combinations, - size_t total_combinations, - int64_t* source_vertices, - size_t size_source_verticesArr, - int64_t* sink_vertices, - size_t size_sink_verticesArr, - bool only_cost, - Flow_t **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_minCostMaxFlow( + char*, + char*, + ArrayType*, ArrayType*, + + bool, + + Flow_t**, size_t*, + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/metrics/betweennessCentrality_driver.h b/include/drivers/metrics/betweennessCentrality_driver.h new file mode 100644 index 00000000000..29d2a2e9787 --- /dev/null +++ b/include/drivers/metrics/betweennessCentrality_driver.h @@ -0,0 +1,64 @@ +/*PGR-GNU***************************************************************** +File: betweennessCentrality_driver.h + +Generated with Template by: +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2024 Arun Thakur +Mail: bedupako12mas at gmail.com + +------ + +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_METRICS_BETWEENNESSCENTRALITY_DRIVER_H_ +#define INCLUDE_DRIVERS_METRICS_BETWEENNESSCENTRALITY_DRIVER_H_ +#pragma once + +/* for size-t */ +#ifdef __cplusplus +# include +using IID_t_rt = struct IID_t_rt; +#else +# include +#include +typedef struct IID_t_rt IID_t_rt; +#endif + + + +#ifdef __cplusplus +extern "C" { +#endif + +void +pgr_do_betweennessCentrality( + char*, + bool, + + IID_t_rt**, + size_t*, + char**, + char**); + +#ifdef __cplusplus +} +#endif + +#endif // INCLUDE_DRIVERS_METRICS_BETWEENNESSCENTRALITY_DRIVER_H_ diff --git a/include/drivers/mincut/stoerWagner_driver.h b/include/drivers/mincut/stoerWagner_driver.h index 950889fe3f0..2aa3bac5cd9 100644 --- a/include/drivers/mincut/stoerWagner_driver.h +++ b/include/drivers/mincut/stoerWagner_driver.h @@ -34,29 +34,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using StoerWagner_t = struct StoerWagner_t; #else # include -typedef struct Edge_t Edge_t; typedef struct StoerWagner_t StoerWagner_t; #endif - #ifdef __cplusplus extern "C" { #endif - void - do_pgr_stoerWagner( - Edge_t *data_edges, - size_t total_edges, - StoerWagner_t **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_stoerWagner( + char*, + + StoerWagner_t**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/ordering/cuthillMckeeOrdering_driver.h b/include/drivers/ordering/cuthillMckeeOrdering_driver.h index fe4309ec2bd..d36657f3973 100644 --- a/include/drivers/ordering/cuthillMckeeOrdering_driver.h +++ b/include/drivers/ordering/cuthillMckeeOrdering_driver.h @@ -49,14 +49,11 @@ extern "C" { #endif void -do_cuthillMckeeOrdering( - Edge_t*, size_t, // edges +pgr_do_cuthillMckeeOrdering( + char*, - II_t_rt**, size_t*, // results - - char **, // log msg - char **, // notice msg - char **); // err msg + II_t_rt**, size_t*, + char **, char **, char **); #ifdef __cplusplus diff --git a/include/drivers/pickDeliver/pickDeliverEuclidean_driver.h b/include/drivers/pickDeliver/pickDeliverEuclidean_driver.h index dbde1c8e13a..115f80b090b 100644 --- a/include/drivers/pickDeliver/pickDeliverEuclidean_driver.h +++ b/include/drivers/pickDeliver/pickDeliverEuclidean_driver.h @@ -35,13 +35,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /* for size-t */ #ifdef __cplusplus # include -using Orders_t = struct Orders_t; -using Vehicle_t = struct Vehicle_t; using Schedule_rt = struct Schedule_rt; #else # include -typedef struct Orders_t Orders_t; -typedef struct Vehicle_t Vehicle_t; typedef struct Schedule_rt Schedule_rt; #endif @@ -49,27 +45,15 @@ typedef struct Schedule_rt Schedule_rt; extern "C" { #endif - /********************************************************* - orders_sql TEXT, - max_vehicles INTEGER, - capacity FLOAT, - max_cycles INTEGER, - ********************************************************/ - void do_pgr_pickDeliverEuclidean( - Orders_t *pd_orders_arr, size_t total_pd_orders, - Vehicle_t *vehicles_arr, size_t total_vehicles, +void pgr_do_pickDeliverEuclidean( + char*, + char*, - double factor, - int max_cycles, - int initial_solution_id, + double, int, int, - Schedule_rt **return_tuples, - size_t *return_count, - - char **log_msg, - char **notice_msg, - char **err_msg); + Schedule_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/pickDeliver/pickDeliver_driver.h b/include/drivers/pickDeliver/pickDeliver_driver.h index 13968152028..730f88b8934 100644 --- a/include/drivers/pickDeliver/pickDeliver_driver.h +++ b/include/drivers/pickDeliver/pickDeliver_driver.h @@ -35,43 +35,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /* for size-t */ #ifdef __cplusplus # include -using Orders_t = struct Orders_t; -using Vehicle_t = struct Vehicle_t; using Schedule_rt = struct Schedule_rt; -using IID_t_rt = struct IID_t_rt; #else # include -typedef struct Orders_t Orders_t; -typedef struct Vehicle_t Vehicle_t; typedef struct Schedule_rt Schedule_rt; -typedef struct IID_t_rt IID_t_rt; #endif #ifdef __cplusplus extern "C" { #endif - /********************************************************* - orders_sql TEXT, - max_vehicles INTEGER, - capacity FLOAT, - max_cycles INTEGER, - ********************************************************/ - void do_pgr_pickDeliver( - Orders_t *pd_orders_arr, size_t total_pd_orders, - Vehicle_t *vehicles_arr, size_t total_vehicles, - IID_t_rt *matrix_cells_arr, size_t total_cells, - - double factor, - int max_cycles, - int initial_solution_id, - - Schedule_rt **return_tuples, - size_t *return_count, - - char **log_msg, - char **notice_msg, - char **err_msg); +void pgr_do_pickDeliver( + char*, + char*, + char*, + + double, int, int, + + Schedule_rt**, size_t*, + + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/planar/boyerMyrvold_driver.h b/include/drivers/planar/boyerMyrvold_driver.h index e4a83a2a71c..8baa6c5d9ba 100644 --- a/include/drivers/planar/boyerMyrvold_driver.h +++ b/include/drivers/planar/boyerMyrvold_driver.h @@ -33,25 +33,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using IID_t_rt = struct IID_t_rt; #else # include -typedef struct Edge_t Edge_t; typedef struct IID_t_rt IID_t_rt; #endif #ifdef __cplusplus extern "C" { #endif - void do_pgr_boyerMyrvold( - Edge_t *data_edges, - size_t total_tuples, - IID_t_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); + void pgr_do_pgr_boyerMyrvold( + char*, + IID_t_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/planar/isPlanar_driver.h b/include/drivers/planar/isPlanar_driver.h index decf784a861..ac351861327 100644 --- a/include/drivers/planar/isPlanar_driver.h +++ b/include/drivers/planar/isPlanar_driver.h @@ -31,23 +31,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_PLANAR_ISPLANAR_DRIVER_H_ #pragma once -#ifdef __cplusplus -# include -using Edge_t = struct Edge_t; -#else -# include -typedef struct Edge_t Edge_t; +#ifndef __cplusplus +#include #endif #ifdef __cplusplus extern "C" { #endif - bool do_pgr_isPlanar( - Edge_t *data_edges, - size_t total_tuples, - char ** log_msg, - char ** notice_msg, - char ** err_msg); + bool pgr_do_isPlanar( + char*, + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/spanningTree/kruskal_driver.h b/include/drivers/spanningTree/kruskal_driver.h index 6b559638e9b..7cf11e1f20a 100644 --- a/include/drivers/spanningTree/kruskal_driver.h +++ b/include/drivers/spanningTree/kruskal_driver.h @@ -31,40 +31,41 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_SPANNINGTREE_KRUSKAL_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using MST_rt = struct MST_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct MST_rt MST_rt; #endif #ifdef __cplusplus extern "C" { #endif - void - do_pgr_kruskal( - Edge_t *data_edges, - size_t total_edges, - - int64_t *root, - size_t total_roots, - char* fn_suffix, +void pgr_do_kruskal( + char*, + ArrayType*, - int64_t max_depth, - double distance, + char*, int64_t, double, - MST_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); + MST_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/spanningTree/prim_driver.h b/include/drivers/spanningTree/prim_driver.h index a7e24eed2ac..0ea5408bcdb 100644 --- a/include/drivers/spanningTree/prim_driver.h +++ b/include/drivers/spanningTree/prim_driver.h @@ -31,40 +31,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_SPANNINGTREE_PRIM_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include +using MST_rt = struct MST_rt; #else # include # include +typedef struct MST_rt MST_rt; #endif -typedef struct Edge_t Edge_t; -typedef struct MST_rt MST_rt; #ifdef __cplusplus extern "C" { #endif -void do_pgr_prim( - Edge_t *data_edges, - size_t total_edges, - - int64_t *rootsArr, - size_t size_rootsArr, - - char* fn_suffix, - - int64_t max_depth, - double distance, +void pgr_do_prim( + char*, + ArrayType*, - MST_rt **return_tuples, - size_t *return_count, + char*, int64_t, double, - char ** log_msg, - char ** notice_msg, - char ** err_msg); + MST_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/spanningTree/randomSpanningTree_driver.h b/include/drivers/spanningTree/randomSpanningTree_driver.h index 434887d3b5c..febaa96ada4 100644 --- a/include/drivers/spanningTree/randomSpanningTree_driver.h +++ b/include/drivers/spanningTree/randomSpanningTree_driver.h @@ -31,31 +31,40 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_SPANNINGTREE_RANDOMSPANNINGTREE_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include +using SpanTree_rt = struct SpanTree_rt; #else # include +typedef SpanTree_rt SpanTree_rt; #endif -typedef struct Edge_t Edge_t; -typedef SpanTree_rt SpanTree_rt; #ifdef __cplusplus extern "C" { #endif - void - do_pgr_randomSpanningTree( - Edge_t *data_edges, - size_t total_edges, - int64_t root_vertex, - bool directed, - SpanTree_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_randomSpanningTree( + char*, + ArrayType*, + + int64_t, double, + + SpanTree_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/topologicalSort/topologicalSort_driver.h b/include/drivers/topologicalSort/topologicalSort_driver.h index f0c88a91326..183b19084fb 100644 --- a/include/drivers/topologicalSort/topologicalSort_driver.h +++ b/include/drivers/topologicalSort/topologicalSort_driver.h @@ -31,14 +31,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #ifndef INCLUDE_DRIVERS_TOPOLOGICALSORT_TOPOLOGICALSORT_DRIVER_H_ #define INCLUDE_DRIVERS_TOPOLOGICALSORT_TOPOLOGICALSORT_DRIVER_H_ -/* for size-t */ #ifdef __cplusplus # include -using Edge_t = struct Edge_t; using I_rt = struct I_rt; #else # include -typedef struct Edge_t Edge_t; typedef struct I_rt I_rt; #endif @@ -46,18 +43,11 @@ typedef struct I_rt I_rt; extern "C" { #endif - // CREATE OR REPLACE FUNCTION pgr_topologicalSort( - // sql text, - void do_pgr_topologicalSort( - Edge_t *data_edges, - size_t total_tuples, +void pgr_do_topologicalSort( + char*, - I_rt **return_tuples, - size_t *return_count, - - char** log_msg, - char** notice_msg, - char** err_msg); + I_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/transitiveClosure/transitiveClosure_driver.h b/include/drivers/transitiveClosure/transitiveClosure_driver.h index dd191f85f8c..428d5d93ac1 100644 --- a/include/drivers/transitiveClosure/transitiveClosure_driver.h +++ b/include/drivers/transitiveClosure/transitiveClosure_driver.h @@ -30,35 +30,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_TRANSITIVECLOSURE_TRANSITIVECLOSURE_DRIVER_H_ #pragma once -/* for size-t */ #ifdef __cplusplus # include using TransitiveClosure_rt = struct TransitiveClosure_rt; -using Edge_t = struct Edge_t; #else # include typedef struct TransitiveClosure_rt TransitiveClosure_rt; -typedef struct Edge_t Edge_t; #endif #ifdef __cplusplus extern "C" { #endif - /********************************************************* - edges_sql TEXT, - - ********************************************************/ - void - do_pgr_transitiveClosure( - Edge_t *data_edges, - size_t total_tuples, - TransitiveClosure_rt **return_tuples, - size_t *return_count, - char **log_msg, - char **notice_msg, - char **err_msg); +void pgr_do_transitiveClosure( + char*, + TransitiveClosure_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/traversal/depthFirstSearch_driver.h b/include/drivers/traversal/depthFirstSearch_driver.h index f5df64ad3fb..a157a54e3ec 100644 --- a/include/drivers/traversal/depthFirstSearch_driver.h +++ b/include/drivers/traversal/depthFirstSearch_driver.h @@ -31,7 +31,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_TRAVERSAL_DEPTHFIRSTSEARCH_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include @@ -48,32 +60,14 @@ typedef struct MST_rt MST_rt; extern "C" { #endif - /************************************************** - * - * pgr_depthFirstSearch( - * edges_sql TEXT, - * root_vids ANYARRAY, - * directed BOOLEAN DEFAULT true - * max_depth BIGINT DEFAULT 9223372036854775807, - * ); - * - *************************************************/ - void do_pgr_depthFirstSearch( - Edge_t *data_edges, - size_t total_edges, - - int64_t *rootsArr, - size_t size_rootsArr, - - bool directed, - int64_t max_depth, - - MST_rt **return_tuples, - size_t *return_count, - - char ** log_msg, - char ** notice_msg, - char ** err_msg); +void pgr_do_depthFirstSearch( + char*, + ArrayType*, + + bool, int64_t, + + MST_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/trsp/trspVia_driver.h b/include/drivers/trsp/trspVia_driver.h index 60547961d31..01129c15a68 100644 --- a/include/drivers/trsp/trspVia_driver.h +++ b/include/drivers/trsp/trspVia_driver.h @@ -29,40 +29,44 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_TRSP_TRSPVIA_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Routes_t = struct Routes_t; -using Restriction_t = struct Restriction_t; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Routes_t Routes_t; -typedef struct Restriction_t Restriction_t; #endif - #ifdef __cplusplus extern "C" { #endif -void do_trspVia( - Edge_t *, size_t, // edges - Restriction_t *, size_t, // restrictions - int64_t *, size_t, // vias - - bool, // directed - bool, // strict - bool, // U_turn_on_edge +void pgr_do_trspVia( + char*, + char*, + ArrayType*, - Routes_t **, size_t *, // tuples + bool, + bool, + bool, - char**, // log - char**, // notice - char**); // err + Routes_t **, size_t *, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/trsp/trspVia_withPoints_driver.h b/include/drivers/trsp/trspVia_withPoints_driver.h index 08ed20c48d5..816e5ca61aa 100644 --- a/include/drivers/trsp/trspVia_withPoints_driver.h +++ b/include/drivers/trsp/trspVia_withPoints_driver.h @@ -29,20 +29,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_TRSP_TRSPVIA_WITHPOINTS_DRIVER_H_ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #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; -using Restriction_t = struct Restriction_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; -typedef struct Restriction_t Restriction_t; #endif @@ -52,26 +59,19 @@ extern "C" { /** @brief Process pgr_trsp_withPointsVia */ void -do_trspVia_withPoints( - Edge_t*, size_t, // edges - Restriction_t *, size_t, // restrictions - 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 +pgr_do_trspVia_withPoints( + char*, + char*, + char*, + char*, + ArrayType*, + + bool, + char, bool, + bool, bool, + + Routes_t**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/trsp/trsp_core.h b/include/drivers/trsp/trsp_deprecated_driver.h similarity index 85% rename from include/trsp/trsp_core.h rename to include/drivers/trsp/trsp_deprecated_driver.h index 07f5dc97452..ba4c0bb64ed 100644 --- a/include/trsp/trsp_core.h +++ b/include/drivers/trsp/trsp_deprecated_driver.h @@ -1,6 +1,6 @@ /*PGR-GNU***************************************************************** -FILE: trsp.h +FILE: trsp_deprecated_driver.h Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -23,8 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_TRSP_TRSP_CORE_H_ -#define INCLUDE_TRSP_TRSP_CORE_H_ +#ifndef INCLUDE_DRIVERS_TRSP_TRSP_DEPRECATED_DRIVER_H_ +#define INCLUDE_DRIVERS_TRSP_TRSP_DEPRECATED_DRIVER_H_ #ifdef __cplusplus # include @@ -32,10 +32,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #else # include # include +#include #endif typedef struct restrict_t restrict_t; -typedef struct Edge_t Edge_t; +typedef struct Edge_rt Edge_t; typedef struct path_element_tt path_element_tt; #ifdef __cplusplus @@ -62,4 +63,4 @@ int trsp_edge_wrapper( } #endif -#endif // INCLUDE_TRSP_TRSP_CORE_H_ +#endif // INCLUDE_DRIVERS_TRSP_TRSP_DEPRECATED_DRIVER_H_ diff --git a/include/drivers/trsp/trsp_driver.h b/include/drivers/trsp/trsp_driver.h index f4b113f3f8d..96b67cb7989 100644 --- a/include/drivers/trsp/trsp_driver.h +++ b/include/drivers/trsp/trsp_driver.h @@ -32,41 +32,44 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_TRSP_TRSP_DRIVER_H_ #pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus #include #include -using Restriction_t = struct Restriction_t; using Path_rt = struct Path_rt; -using Edge_t = struct Edge_t; -using II_t_rt = struct II_t_rt; #else #include #include -typedef struct Restriction_t Restriction_t; typedef struct Path_rt Path_rt; -typedef struct Edge_t Edge_t; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus extern "C" { #endif -void do_trsp( - Edge_t *, size_t, // edges - Restriction_t *, size_t, // restrictions - - II_t_rt *, size_t, // combinations - int64_t *, size_t, // starts - int64_t *, size_t, // ends - - bool, // directed +void pgr_do_trsp( + char*, + char*, + char*, + ArrayType*, ArrayType*, - Path_rt **, size_t *, // tuples + bool, - char**, // log - char**, // notice - char**); // err + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/trsp/trsp_withPoints_driver.h b/include/drivers/trsp/trsp_withPoints_driver.h index ac5bfb82ba4..14d273cf3d2 100644 --- a/include/drivers/trsp/trsp_withPoints_driver.h +++ b/include/drivers/trsp/trsp_withPoints_driver.h @@ -29,47 +29,46 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_TRSP_TRSP_WITHPOINTS_DRIVER_H_ #pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus #include #include -using Restriction_t = struct Restriction_t; using Path_rt = struct Path_rt; -using Edge_t = struct Edge_t; -using II_t_rt = struct II_t_rt; -using Point_on_edge_t = struct Point_on_edge_t; #else #include #include -typedef struct Restriction_t Restriction_t; typedef struct Path_rt Path_rt; -typedef struct Edge_t Edge_t; -typedef struct II_t_rt II_t_rt; -typedef struct Point_on_edge_t Point_on_edge_t; #endif #ifdef __cplusplus extern "C" { #endif -void do_trsp_withPoints( - Edge_t *, size_t, // edges - Restriction_t *, size_t, // restrictions - Point_on_edge_t *, size_t, // points - Edge_t *, size_t, // edges of points - - II_t_rt *, size_t, // combinations - int64_t *, size_t, // starts - int64_t *, size_t, // ends - - bool, // directed - char, // driving_side - bool, // details +void pgr_do_trsp_withPoints( + char*, + char*, + char*, + char*, + char*, + ArrayType*, ArrayType*, - Path_rt **, size_t *, // tuples + bool, char, bool, - char**, // log - char**, // notice - char**); // err + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/tsp/TSP_driver.h b/include/drivers/tsp/TSP_driver.h index 38756e15bce..5317c6b3b3f 100644 --- a/include/drivers/tsp/TSP_driver.h +++ b/include/drivers/tsp/TSP_driver.h @@ -37,12 +37,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # include # include using TSP_tour_rt = struct TSP_tour_rt; -using IID_t_rt = struct IID_t_rt; #else # include # include +#include typedef struct TSP_tour_rt TSP_tour_rt; -typedef struct IID_t_rt IID_t_rt; #endif #ifdef __cplusplus @@ -50,17 +49,15 @@ extern "C" { #endif void -do_pgr_tsp( - IID_t_rt *distances, size_t total_distances, - int64_t start_vid, - int64_t end_vid, - bool strict, +pgr_do_tsp( + char*, - TSP_tour_rt **results, - size_t *total_results, - char **log_msg, - char **notice_msg, - char **err_msg); + int64_t, + int64_t, + bool, + + TSP_tour_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/tsp/euclideanTSP_driver.h b/include/drivers/tsp/euclideanTSP_driver.h index eecdc7c0774..9f578719cc9 100644 --- a/include/drivers/tsp/euclideanTSP_driver.h +++ b/include/drivers/tsp/euclideanTSP_driver.h @@ -36,12 +36,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # include # include using TSP_tour_rt = struct TSP_tour_rt; -using Coordinate_t = struct Coordinate_t; #else # include # include typedef struct TSP_tour_rt TSP_tour_rt; -typedef struct Coordinate_t Coordinate_t; +#include #endif #ifdef __cplusplus @@ -49,17 +48,15 @@ extern "C" { #endif void -do_pgr_euclideanTSP( - Coordinate_t *coordinates, size_t total_coordinates, - int64_t start_vid, - int64_t end_vid, - bool strict, +pgr_do_euclideanTSP( + char*, - TSP_tour_rt **results, - size_t *total_results, - char **log_msg, - char **notice_msg, - char **err_msg); + int64_t, + int64_t, + bool, + + TSP_tour_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/withPoints/withPointsVia_driver.h b/include/drivers/withPoints/withPointsVia_driver.h index 33a0715492d..ca9bf2cba3e 100644 --- a/include/drivers/withPoints/withPointsVia_driver.h +++ b/include/drivers/withPoints/withPointsVia_driver.h @@ -29,17 +29,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_WITHPOINTS_WITHPOINTSVIA_DRIVER_H_ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #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 @@ -50,25 +59,18 @@ extern "C" { /** @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 +pgr_do_withPointsVia( + char*, + char*, + char*, + ArrayType*, + + bool, + char, + bool, bool, bool, + + Routes_t**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/withPoints/withPoints_driver.h b/include/drivers/withPoints/withPoints_driver.h index 08ccdb2e179..9b39a329c0b 100644 --- a/include/drivers/withPoints/withPoints_driver.h +++ b/include/drivers/withPoints/withPoints_driver.h @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: many_to_many_withPoints_driver.h +File: withPoints_driver.h Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -30,58 +30,45 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_WITHPOINTS_WITHPOINTS_DRIVER_H_ #pragma once -/* for size-t */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Point_on_edge_t = struct Point_on_edge_t; -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Point_on_edge_t Point_on_edge_t; -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif #ifdef __cplusplus extern "C" { #endif - void do_pgr_withPoints( - Edge_t *edges, - size_t total_edges, - - Point_on_edge_t *points, - size_t total_points, - - Edge_t *edges_of_points, - size_t total_edges_of_points, - - II_t_rt *combinations, - size_t total_combinations, - - int64_t *start_pidsArr, - size_t size_start_pidsArr, - - int64_t *end_pidsArr, - size_t size_end_pidsArr, - +void pgr_do_withPoints( + char*, + char*, + char*, + char*, + ArrayType*, ArrayType*, - char driving_side, - bool details, - bool directed, - bool only_cost, - bool normal, + char, bool, bool, bool, bool, - Path_rt **return_tuples, - size_t *return_count, - char** log_msg, - char** notice_msg, - char** err_msg); + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus } diff --git a/include/drivers/yen/ksp_driver.h b/include/drivers/yen/ksp_driver.h index 26bf0592d6e..39a4bdca6cc 100644 --- a/include/drivers/yen/ksp_driver.h +++ b/include/drivers/yen/ksp_driver.h @@ -32,31 +32,39 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_YEN_KSP_DRIVER_H_ #pragma once -/* for size-t */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; -typedef struct II_t_rt II_t_rt; #endif - #ifdef __cplusplus extern "C" { #endif void pgr_do_ksp( - Edge_t*, size_t, - II_t_rt*, size_t, - int64_t*, size_t, - int64_t*, size_t, + char*, + char*, + ArrayType*, ArrayType*, + int64_t*, + int64_t*, size_t, bool, bool, diff --git a/include/drivers/yen/turnRestrictedPath_driver.h b/include/drivers/yen/turnRestrictedPath_driver.h index 11066bdb9ff..7d50c129d9c 100644 --- a/include/drivers/yen/turnRestrictedPath_driver.h +++ b/include/drivers/yen/turnRestrictedPath_driver.h @@ -35,14 +35,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #ifdef __cplusplus # include # include -using Edge_t = struct Edge_t; -using Restriction_t = struct Restriction_t; using Path_rt = struct Path_rt; #else # include # include -typedef struct Edge_t Edge_t; -typedef struct Restriction_t Restriction_t; +#include typedef struct Path_rt Path_rt; #endif @@ -51,39 +48,21 @@ typedef struct Path_rt Path_rt; extern "C" { #endif - /********************************************************* +void pgr_do_turnRestrictedPath( + char*, + char*, - TEXT, -- edges_sql - TEXT, -- restrictions_sql - BIGINT, -- source - BIGINT, -- target - directed BOOLEAN DEFAULT true, - only_cost BOOLEAN DEFAULT false, - strict BOOLEAN DEFAULT false - ********************************************************/ + int64_t, + int64_t, + size_t, + bool, + bool, + bool, + bool, - void do_pgr_turnRestrictedPath( - Edge_t *data_edges, - size_t total_edges, - - Restriction_t *restrictions, - size_t total_restrictions, - - int64_t start_vid, - int64_t end_vid, - - size_t k, - bool directed, - bool heap_paths, - bool stop_on_first, - bool strict, - - Path_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg); + Path_rt **, size_t *, + char**, char**, char**); #ifdef __cplusplus diff --git a/include/drivers/yen/withPoints_ksp_driver.h b/include/drivers/yen/withPoints_ksp_driver.h index 70c1860634c..da45c12f47a 100644 --- a/include/drivers/yen/withPoints_ksp_driver.h +++ b/include/drivers/yen/withPoints_ksp_driver.h @@ -33,46 +33,51 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_DRIVERS_YEN_WITHPOINTS_KSP_DRIVER_H_ #pragma once -/* for size-t */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + +#include "cpp_common/undefPostgresDefine.hpp" + #ifdef __cplusplus -# include # include -using Point_on_edge_t = struct Point_on_edge_t; -using Edge_t = struct Edge_t; +# include using Path_rt = struct Path_rt; -using II_t_rt = struct II_t_rt; #else # include # include -typedef struct Point_on_edge_t Point_on_edge_t; -typedef struct Edge_t Edge_t; typedef struct Path_rt Path_rt; #endif - #ifdef __cplusplus extern "C" { #endif - int pgr_do_withPointsKsp( - Edge_t*, size_t, - Point_on_edge_t*, size_t, - Edge_t*, size_t, - II_t_rt*, size_t, - int64_t*, size_t, - int64_t*, size_t, - size_t, - bool, bool, - char, - bool, +void pgr_do_withPointsKsp( + char*, + char*, + char*, + char*, + ArrayType*, ArrayType*, + int64_t*, int64_t*, + size_t, - Path_rt**, size_t*, - char**, char**, char**); +bool, bool, char, bool, + Path_rt**, size_t*, + char**, char**, char**); #ifdef __cplusplus - } +} #endif #endif // INCLUDE_DRIVERS_YEN_WITHPOINTS_KSP_DRIVER_H_ diff --git a/include/lineGraph/pgr_lineGraphFull.hpp b/include/lineGraph/lineGraphFull.hpp similarity index 92% rename from include/lineGraph/pgr_lineGraphFull.hpp rename to include/lineGraph/lineGraphFull.hpp index 786f9dd7162..a6cf3dff594 100644 --- a/include/lineGraph/pgr_lineGraphFull.hpp +++ b/include/lineGraph/lineGraphFull.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_lineGraphFull.hpp +File: lineGraphFull.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_LINEGRAPH_PGR_LINEGRAPHFULL_HPP_ -#define INCLUDE_LINEGRAPH_PGR_LINEGRAPHFULL_HPP_ +#ifndef INCLUDE_LINEGRAPH_LINEGRAPHFULL_HPP_ +#define INCLUDE_LINEGRAPH_LINEGRAPHFULL_HPP_ #pragma once @@ -37,14 +37,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/line_vertex.h" +#include"c_types/line_graph_full_rt.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/line_vertex.hpp" namespace pgrouting { namespace graph { -template -class Pgr_lineGraphFull : public Pgr_base_graph { +template +class Pgr_lineGraphFull : public Pgr_base_graph { public: typedef typename boost::graph_traits < G >::vertex_descriptor V; typedef typename boost::graph_traits < G >::edge_descriptor E; @@ -54,20 +55,20 @@ class Pgr_lineGraphFull : public Pgr_base_graph { typedef typename boost::graph_traits < G >::in_edge_iterator EI_i; - explicit Pgr_lineGraphFull< G, T_V, T_E >(const graphType >ype) - : Pgr_base_graph< G, T_V, T_E >(gtype), + explicit Pgr_lineGraphFull< G, T_V, T_E, t_directed>() + : Pgr_base_graph(), m_num_edges(0) { } - explicit Pgr_lineGraphFull< G, T_V, T_E >(const pgrouting::DirectedGraph &digraph) - : Pgr_base_graph< G, T_V, T_E >(graphType::DIRECTED) { + explicit Pgr_lineGraphFull(const pgrouting::DirectedGraph &digraph) + : Pgr_base_graph() { apply_transformation(digraph); store_edge_costs(digraph); } friend std::ostream& operator<<( - std::ostream &log, const Pgr_lineGraphFull< G, T_V, T_E > &g) { - typename Pgr_base_graph< G, T_V, T_E >::EO_i out, out_end; + std::ostream &log, const Pgr_lineGraphFull &g) { + typename Pgr_base_graph::EO_i out, out_end; for (auto vi = vertices(g.graph).first; vi != vertices(g.graph).second; ++vi) { @@ -143,11 +144,6 @@ class Pgr_lineGraphFull : public Pgr_base_graph { } } -#if 0 - log << "e_source = " << e_source - << " e_target = " << e_target - << "\n"; -#endif Line_graph_full_rt edge = { ++count, vertex_id_map[e_source], @@ -306,4 +302,4 @@ class Pgr_lineGraphFull : public Pgr_base_graph { } // namespace graph } // namespace pgrouting -#endif // INCLUDE_LINEGRAPH_PGR_LINEGRAPHFULL_HPP_ +#endif // INCLUDE_LINEGRAPH_LINEGRAPHFULL_HPP_ diff --git a/include/lineGraph/pgr_lineGraph.hpp b/include/lineGraph/pgr_lineGraph.hpp deleted file mode 100644 index f7f6b6b0ec2..00000000000 --- a/include/lineGraph/pgr_lineGraph.hpp +++ /dev/null @@ -1,221 +0,0 @@ -/*PGR-GNU***************************************************************** -File: pgr_lineGraph.hpp - -Generated with Template by: -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2017 Vidhan Jain -Mail: vidhanj1307@gmail.com - ------- - -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_LINEGRAPH_PGR_LINEGRAPH_HPP_ -#define INCLUDE_LINEGRAPH_PGR_LINEGRAPH_HPP_ -#pragma once - - -#include -#include -#include -#include -#include - -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/line_vertex.h" - -namespace pgrouting { - -namespace graph { - -template -class Pgr_lineGraph : public Pgr_base_graph { - public: - typedef typename boost::graph_traits < G >::vertex_descriptor V; - typedef typename boost::graph_traits < G >::edge_descriptor E; - typedef typename boost::graph_traits < G >::vertex_iterator V_i; - typedef typename boost::graph_traits < G >::out_edge_iterator EO_i; - typedef typename boost::graph_traits < G >::in_edge_iterator EI_i; - - - explicit Pgr_lineGraph< G, T_V, T_E >(graphType gtype) - : Pgr_base_graph< G, T_V, T_E >(gtype) { - } - - explicit Pgr_lineGraph< G, T_V, T_E >(const pgrouting::DirectedGraph &digraph) - : Pgr_base_graph< G, T_V, T_E >(graphType::DIRECTED) { - insert_vertices(digraph); - create_edges(digraph); - } - - - friend std::ostream& operator<<( - std::ostream &log, const Pgr_lineGraph< G, T_V, T_E > &g) { - typename Pgr_base_graph< G, T_V, T_E >::EO_i out, out_end; - - for (auto vi = vertices(g.graph).first; - vi != vertices(g.graph).second; ++vi) { - if ((*vi) >= g.num_vertices()) break; - log << (*vi) << ": " << " out_edges_of(" << g.graph[(*vi)] << "):"; - for (boost::tie(out, out_end) = out_edges(*vi, g.graph); - out != out_end; ++out) { - log << ' ' - << g.graph[*out].id << "=(" - << g[g.source(*out)].id << ", " - << g[g.target(*out)].id << ")\t"; - } - log << std::endl; - } - return log; - } - - - std::vector< Edge_t > - get_postgres_results_directed() { - std::vector< Edge_t > results; - - typename boost::graph_traits < G >::edge_iterator edgeIt, edgeEnd; - std::map < std::pair, Edge_t > unique; - int64_t count = 0; - - for (boost::tie(edgeIt, edgeEnd) = boost::edges(this->graph); - edgeIt != edgeEnd; edgeIt++) { - E e = *edgeIt; - auto e_source = this->graph[this->source(e)].vertex_id; - auto e_target = this->graph[this->target(e)].vertex_id; - - if (unique.find({e_target, e_source}) != unique.end()) { - unique[std::pair(e_target, - e_source)].reverse_cost = 1.0; - continue; - } - e_source *= -1; - e_target *= -1; - if (unique.find({e_target, e_source}) != unique.end()) { - unique[std::pair(e_target, - e_source)].reverse_cost = 1.0; - continue; - } - e_source *= -1; - e_target *= -1; - - Edge_t edge = { - ++count, - e_source, - e_target, - 1.0, - -1.0 - }; - unique[std::pair(e_source, e_target)] = edge; - } - for (const auto &edge : unique) { - results.push_back(edge.second); - } - return results; - } - - void insert_vertices( - const pgrouting::DirectedGraph& digraph) { - auto es = boost::edges(digraph.graph); - for (auto eit = es.first; eit != es.second; ++eit) { - auto edge = *eit; - Line_vertex vertex({ - digraph[edge].id, - digraph[boost::source(edge, digraph.graph)].id, - digraph[boost::target(edge, digraph.graph)].id, - digraph[edge].cost, - -1}); - add_one_vertex(vertex); - } - } - - - - private: - template < typename T> - void - graph_add_edge( - const T &source, - const T &target) { - bool inserted; - E e; - - auto vm_s = this->get_V(source); - auto vm_t = this->get_V(target); - - boost::tie(e, inserted) = - boost::add_edge(vm_s, vm_t, this->graph); - - this->graph[e].id = static_cast(this->num_edges()); - } - - void create_edges( - const pgrouting::DirectedGraph& digraph) { - V_i vertexIt, vertexEnd; - EO_i e_outIt, e_outEnd; - EI_i e_inIt, e_inEnd; - - - /* for (each vertex v in original graph) */ - for (boost::tie(vertexIt, vertexEnd) = boost::vertices(digraph.graph); - vertexIt != vertexEnd; vertexIt++) { - auto vertex = *vertexIt; - - /* for( all incoming edges in to vertex v) */ - for (boost::tie(e_outIt, e_outEnd) = - boost::out_edges(vertex, digraph.graph); - e_outIt != e_outEnd; - e_outIt++) { - /* for( all outgoing edges out from vertex v) */ - for (boost::tie(e_inIt, e_inEnd) = - boost::in_edges(vertex, digraph.graph); - e_inIt != e_inEnd; e_inIt++) { - /* - Prevent self-edges from being created in the Line Graph - */ - - graph_add_edge( - (digraph.graph[*e_inIt]).id, - (digraph.graph[*e_outIt]).id); - } - } - } - } - - V add_one_vertex( - T_V vertex) { - auto v = add_vertex(this->graph); - this->vertices_map[vertex.id] = v; - this->graph[v].cp_members(vertex); - - pgassert(boost::num_vertices(this->graph) == this->num_vertices()); - return v; - } - - private: - std::map < int64_t, Edge_t > m_edges; - - public: - std::ostringstream log; -}; -} // namespace graph -} // namespace pgrouting - -#endif // INCLUDE_LINEGRAPH_PGR_LINEGRAPH_HPP_ diff --git a/include/max_flow/pgr_costFlowGraph.hpp b/include/max_flow/costFlowGraph.hpp similarity index 92% rename from include/max_flow/pgr_costFlowGraph.hpp rename to include/max_flow/costFlowGraph.hpp index 9a6ea25bf47..73c45c00364 100644 --- a/include/max_flow/pgr_costFlowGraph.hpp +++ b/include/max_flow/costFlowGraph.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_costFlowGraph.hpp +File: costFlowGraph.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_MAX_FLOW_PGR_COSTFLOWGRAPH_HPP_ -#define INCLUDE_MAX_FLOW_PGR_COSTFLOWGRAPH_HPP_ +#ifndef INCLUDE_MAX_FLOW_COSTFLOWGRAPH_HPP_ +#define INCLUDE_MAX_FLOW_COSTFLOWGRAPH_HPP_ #pragma once #include @@ -58,4 +58,4 @@ typedef boost::property_map < CostFlowGraph, } // namespace pgrouting -#endif // INCLUDE_MAX_FLOW_PGR_COSTFLOWGRAPH_HPP_ +#endif // INCLUDE_MAX_FLOW_COSTFLOWGRAPH_HPP_ diff --git a/include/max_flow/pgr_flowgraph.hpp b/include/max_flow/flowgraph.hpp similarity index 92% rename from include/max_flow/pgr_flowgraph.hpp rename to include/max_flow/flowgraph.hpp index 9d390c354c0..dfd9b2fe36f 100644 --- a/include/max_flow/pgr_flowgraph.hpp +++ b/include/max_flow/flowgraph.hpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: flowgraph.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_MAX_FLOW_PGR_FLOWGRAPH_HPP_ -#define INCLUDE_MAX_FLOW_PGR_FLOWGRAPH_HPP_ +#ifndef INCLUDE_MAX_FLOW_FLOWGRAPH_HPP_ +#define INCLUDE_MAX_FLOW_FLOWGRAPH_HPP_ #pragma once #include @@ -51,4 +52,4 @@ typedef boost::adjacency_list @@ -35,15 +36,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "max_flow/pgr_flowgraph.hpp" +#include "max_flow/flowgraph.hpp" #include #include #include #include "c_types/flow_t.h" -#include "c_types/edge_t.h" +#include "cpp_common/edge_t.hpp" #include "c_types/path_rt.h" -#include "cpp_common/interruption.h" +#include "cpp_common/interruption.hpp" namespace pgrouting { @@ -197,4 +198,4 @@ class PgrFlowGraph { } // namespace graph } // namespace pgrouting -#endif // INCLUDE_MAX_FLOW_PGR_MAXFLOW_HPP_ +#endif // INCLUDE_MAX_FLOW_MAXFLOW_HPP_ diff --git a/include/max_flow/pgr_maximumcardinalitymatching.hpp b/include/max_flow/maximumcardinalitymatching.hpp similarity index 86% rename from include/max_flow/pgr_maximumcardinalitymatching.hpp rename to include/max_flow/maximumcardinalitymatching.hpp index 71daa693f24..f10b2bd0e77 100644 --- a/include/max_flow/pgr_maximumcardinalitymatching.hpp +++ b/include/max_flow/maximumcardinalitymatching.hpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: maximumcardinalitymatching.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -29,8 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_MAX_FLOW_PGR_MAXIMUMCARDINALITYMATCHING_HPP_ -#define INCLUDE_MAX_FLOW_PGR_MAXIMUMCARDINALITYMATCHING_HPP_ +#ifndef INCLUDE_MAX_FLOW_MAXIMUMCARDINALITYMATCHING_HPP_ +#define INCLUDE_MAX_FLOW_MAXIMUMCARDINALITYMATCHING_HPP_ #pragma once #include @@ -77,11 +78,11 @@ class PgrCardinalityGraph { return E_to_id[e]; } - PgrCardinalityGraph(Edge_bool_t *data_edges, size_t total_tuples) { + explicit PgrCardinalityGraph(const std::vector &edges) { std::set vertices; - for (size_t i = 0; i < total_tuples; ++i) { - vertices.insert(data_edges[i].source); - vertices.insert(data_edges[i].target); + for (const auto &e : edges) { + vertices.insert(e.source); + vertices.insert(e.target); } for (int64_t id : vertices) { V v = add_vertex(boost_graph); @@ -90,14 +91,14 @@ class PgrCardinalityGraph { } bool added; - for (size_t i = 0; i < total_tuples; ++i) { - V v1 = get_boost_vertex(data_edges[i].source); - V v2 = get_boost_vertex(data_edges[i].target); + for (const auto &e : edges) { + V v1 = get_boost_vertex(e.source); + V v2 = get_boost_vertex(e.target); E e1; E e2; - if (data_edges[i].going) { + if (e.going) { boost::tie(e1, added) = boost::add_edge(v1, v2, boost_graph); - E_to_id.insert(std::pair(e1, data_edges[i].id)); + E_to_id.insert(std::pair(e1, e.id)); } } } @@ -151,4 +152,4 @@ class PgrCardinalityGraph { } // namespace flow } // namespace pgrouting -#endif // INCLUDE_MAX_FLOW_PGR_MAXIMUMCARDINALITYMATCHING_HPP_ +#endif // INCLUDE_MAX_FLOW_MAXIMUMCARDINALITYMATCHING_HPP_ diff --git a/include/max_flow/pgr_minCostMaxFlow.hpp b/include/max_flow/minCostMaxFlow.hpp similarity index 94% rename from include/max_flow/pgr_minCostMaxFlow.hpp rename to include/max_flow/minCostMaxFlow.hpp index 7d5320da438..3d91bb26835 100644 --- a/include/max_flow/pgr_minCostMaxFlow.hpp +++ b/include/max_flow/minCostMaxFlow.hpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: minCostMaxFlow.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_MAX_FLOW_PGR_MINCOSTMAXFLOW_HPP_ -#define INCLUDE_MAX_FLOW_PGR_MINCOSTMAXFLOW_HPP_ +#ifndef INCLUDE_MAX_FLOW_MINCOSTMAXFLOW_HPP_ +#define INCLUDE_MAX_FLOW_MINCOSTMAXFLOW_HPP_ #pragma once #include @@ -39,8 +40,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_types/flow_t.h" -#include "c_types/costFlow_t.h" -#include "max_flow/pgr_costFlowGraph.hpp" +#include "cpp_common/costFlow_t.hpp" +#include "max_flow/costFlowGraph.hpp" namespace pgrouting { namespace graph { @@ -145,4 +146,4 @@ class PgrCostFlowGraph { } // namespace graph } // namespace pgrouting -#endif // INCLUDE_MAX_FLOW_PGR_MINCOSTMAXFLOW_HPP_ +#endif // INCLUDE_MAX_FLOW_MINCOSTMAXFLOW_HPP_ diff --git a/include/metrics/betweennessCentrality.hpp b/include/metrics/betweennessCentrality.hpp new file mode 100644 index 00000000000..8b145c09865 --- /dev/null +++ b/include/metrics/betweennessCentrality.hpp @@ -0,0 +1,144 @@ +/*PGR-GNU***************************************************************** +File: betweennessCentrality.hpp + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2024 Arun Thakur +Mail: bedupako12mas at gmail.com + +------ + +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_METRICS_BETWEENNESSCENTRALITY_HPP_ +#define INCLUDE_METRICS_BETWEENNESSCENTRALITY_HPP_ +#pragma once + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "c_types/iid_t_rt.h" +#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" +#include "cpp_common/alloc.hpp" + +namespace pgrouting { +template class Pgr_metrics; + +template +void +pgr_betweennesscentrality( + G &graph, + size_t &result_tuple_count, + IID_t_rt **postgres_rows) { + Pgr_metrics fn_centrality; + fn_centrality.betweennessCentrality(graph, result_tuple_count, postgres_rows); +} + +template +class Pgr_metrics { + public: + using Graph = typename G::B_G; + using V = typename G::V; + using E = typename G::E; + typedef typename boost::graph_traits::directed_category directed_category; + + void betweennessCentrality( + const G &graph, + size_t &result_tuple_count, + IID_t_rt **postgres_rows) { + // required parameters + std::vector centrality(boost::num_vertices(graph.graph), 0.0); + auto centrality_map = boost::make_iterator_property_map(centrality.begin(), + boost::get(boost::vertex_index, graph.graph)); + std::vector distance(boost::num_vertices(graph.graph), 0.0); + auto distance_map = boost::make_iterator_property_map(distance.begin(), + boost::get(boost::vertex_index, graph.graph)); + // dummy parameters + std::vector edge_centrality(boost::num_edges(graph.graph), 0.0); + auto edge_centrality_map = boost::make_iterator_property_map(edge_centrality.begin(), + boost::get(&pgrouting::Basic_edge::cost, + graph.graph)); + std::vector> incoming(boost::num_vertices(graph.graph)); + auto incoming_map = boost::make_iterator_property_map(incoming.begin(), + boost::get(boost::vertex_index, graph.graph), + std::vector()); + std::vector dependency(boost::num_vertices(graph.graph), 0.0); + auto dependency_map = boost::make_iterator_property_map(dependency.begin(), + boost::get(boost::vertex_index, graph.graph)); + std::vector path_count(boost::num_vertices(graph.graph), 0); + auto path_count_map = boost::make_iterator_property_map(path_count.begin(), + boost::get(boost::vertex_index, graph.graph)); + auto vertex_index = boost::get(boost::vertex_index, graph.graph); + + /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ + CHECK_FOR_INTERRUPTS(); + + boost::brandes_betweenness_centrality( + graph.graph, + centrality_map, + edge_centrality_map, + incoming_map, + distance_map, + dependency_map, + path_count_map, + vertex_index, + get(&pgrouting::Basic_edge::cost, graph.graph)); + + if (boost::num_vertices(graph.graph) > 2) { + boost::relative_betweenness_centrality( + graph.graph, + centrality_map); + } + + generate_results(graph, centrality, result_tuple_count, postgres_rows); + } + + private: + void generate_results( + const G &graph, + const std::vector centrality_results, + size_t &result_tuple_count, + IID_t_rt **postgres_rows) const { + result_tuple_count = centrality_results.size(); + *postgres_rows = pgr_alloc(result_tuple_count, (*postgres_rows)); + + size_t seq = 0; + for (typename G::V v_i = 0; v_i < graph.num_vertices(); ++v_i) { + (*postgres_rows)[seq].from_vid = graph[v_i].id; + (*postgres_rows)[seq].to_vid = 0; + (*postgres_rows)[seq].cost = centrality_results[v_i]; + if (std::is_same::value) { + (*postgres_rows)[seq].cost = centrality_results[v_i]/2.0; + } + seq++; + } + } +}; + +} // namespace pgrouting + +#endif // INCLUDE_METRICS_BETWEENNESSCENTRALITY_HPP_ diff --git a/include/mincut/pgr_stoerWagner.hpp b/include/mincut/stoerWagner.hpp similarity index 93% rename from include/mincut/pgr_stoerWagner.hpp rename to include/mincut/stoerWagner.hpp index fb5a7741e89..a70a401969f 100644 --- a/include/mincut/pgr_stoerWagner.hpp +++ b/include/mincut/stoerWagner.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_stoerWagner.hpp +File: stoerWagner.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_MINCUT_PGR_STOERWAGNER_HPP_ -#define INCLUDE_MINCUT_PGR_STOERWAGNER_HPP_ +#ifndef INCLUDE_MINCUT_STOERWAGNER_HPP_ +#define INCLUDE_MINCUT_STOERWAGNER_HPP_ #pragma once #include @@ -45,7 +45,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/base_graph.hpp" #include "c_types/stoerWagner_t.h" @@ -86,7 +86,7 @@ class Pgr_stoerWagner { auto t = target(*ei, graph.graph); if (get(parities, s) != get(parities, t)) { - StoerWagner_t tmp; + StoerWagner_t tmp = {}; tmp.cost = graph[*ei].cost; @@ -118,4 +118,4 @@ Pgr_stoerWagner< G >::stoerWagner( } -#endif // INCLUDE_MINCUT_PGR_STOERWAGNER_HPP_ +#endif // INCLUDE_MINCUT_STOERWAGNER_HPP_ diff --git a/include/ordering/cuthillMckeeOrdering.hpp b/include/ordering/cuthillMckeeOrdering.hpp index 26767e3ed2c..29997bf3fd0 100644 --- a/include/ordering/cuthillMckeeOrdering.hpp +++ b/include/ordering/cuthillMckeeOrdering.hpp @@ -42,9 +42,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" -#include "cpp_common/pgr_messages.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" +#include "cpp_common/messages.hpp" #include "c_types/ii_t_rt.h" diff --git a/include/planar/pgr_boyerMyrvold.hpp b/include/planar/boyerMyrvold.hpp similarity index 90% rename from include/planar/pgr_boyerMyrvold.hpp rename to include/planar/boyerMyrvold.hpp index 3134e767ab0..2c8258df5b0 100644 --- a/include/planar/pgr_boyerMyrvold.hpp +++ b/include/planar/boyerMyrvold.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_boyerMyrvold.hpp +File: boyerMyrvold.hpp Copyright (c) 2020 pgRouting developers Mail: project@pgrouting.org @@ -21,8 +21,8 @@ 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_PLANAR_PGR_BOYERMYRVOLD_HPP_ -#define INCLUDE_PLANAR_PGR_BOYERMYRVOLD_HPP_ +#ifndef INCLUDE_PLANAR_BOYERMYRVOLD_HPP_ +#define INCLUDE_PLANAR_BOYERMYRVOLD_HPP_ #pragma once #include @@ -35,9 +35,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_messages.h" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/messages.hpp" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "c_types/iid_t_rt.h" //****************************************** namespace pgrouting { @@ -89,4 +89,4 @@ class Pgr_boyerMyrvold : public pgrouting::Pgr_messages { } // namespace functions } // namespace pgrouting -#endif // INCLUDE_PLANAR_PGR_BOYERMYRVOLD_HPP_ +#endif // INCLUDE_PLANAR_BOYERMYRVOLD_HPP_ diff --git a/include/spanningTree/pgr_kruskal.hpp b/include/spanningTree/kruskal.hpp similarity index 92% rename from include/spanningTree/pgr_kruskal.hpp rename to include/spanningTree/kruskal.hpp index 53955242e51..23d588301ae 100644 --- a/include/spanningTree/pgr_kruskal.hpp +++ b/include/spanningTree/kruskal.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_kruskal.hpp +File: kruskal.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,14 +25,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_SPANNINGTREE_PGR_KRUSKAL_HPP_ -#define INCLUDE_SPANNINGTREE_PGR_KRUSKAL_HPP_ +#ifndef INCLUDE_SPANNINGTREE_KRUSKAL_HPP_ +#define INCLUDE_SPANNINGTREE_KRUSKAL_HPP_ #pragma once #include #include -#include "spanningTree/pgr_mst.hpp" -#include "cpp_common/interruption.h" +#include "spanningTree/mst.hpp" +#include "cpp_common/interruption.hpp" namespace pgrouting { namespace functions { @@ -119,4 +119,4 @@ Pgr_kruskal::kruskalDD( } // namespace functions } // namespace pgrouting -#endif // INCLUDE_SPANNINGTREE_PGR_KRUSKAL_HPP_ +#endif // INCLUDE_SPANNINGTREE_KRUSKAL_HPP_ diff --git a/include/spanningTree/pgr_mst.hpp b/include/spanningTree/mst.hpp similarity index 98% rename from include/spanningTree/pgr_mst.hpp rename to include/spanningTree/mst.hpp index 5ab84f5f394..af0e24b426a 100644 --- a/include/spanningTree/pgr_mst.hpp +++ b/include/spanningTree/mst.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_mst.hpp +File: mst.hpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_SPANNINGTREE_PGR_MST_HPP_ -#define INCLUDE_SPANNINGTREE_PGR_MST_HPP_ +#ifndef INCLUDE_SPANNINGTREE_MST_HPP_ +#define INCLUDE_SPANNINGTREE_MST_HPP_ #pragma once #include @@ -40,8 +40,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "spanningTree/details.hpp" namespace pgrouting { @@ -370,4 +370,4 @@ class Pgr_mst { } // namespace functions } // namespace pgrouting -#endif // INCLUDE_SPANNINGTREE_PGR_MST_HPP_ +#endif // INCLUDE_SPANNINGTREE_MST_HPP_ diff --git a/include/spanningTree/pgr_randomSpanningTree.hpp b/include/spanningTree/pgr_randomSpanningTree.hpp index fad84cd6f05..e385fd00b4e 100644 --- a/include/spanningTree/pgr_randomSpanningTree.hpp +++ b/include/spanningTree/pgr_randomSpanningTree.hpp @@ -42,7 +42,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/basePath_SSEC.hpp" #include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/interruption.hpp" template < class G > class Pgr_randomSpanningTree; // user's functions diff --git a/include/spanningTree/pgr_prim.hpp b/include/spanningTree/prim.hpp similarity index 95% rename from include/spanningTree/pgr_prim.hpp rename to include/spanningTree/prim.hpp index 00b7c52fdda..48b21a6452b 100644 --- a/include/spanningTree/pgr_prim.hpp +++ b/include/spanningTree/prim.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_prim.hpp +File: prim.hpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_SPANNINGTREE_PGR_PRIM_HPP_ -#define INCLUDE_SPANNINGTREE_PGR_PRIM_HPP_ +#ifndef INCLUDE_SPANNINGTREE_PRIM_HPP_ +#define INCLUDE_SPANNINGTREE_PRIM_HPP_ #pragma once #include @@ -35,8 +35,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "spanningTree/pgr_mst.hpp" -#include "cpp_common/interruption.h" +#include "spanningTree/mst.hpp" +#include "cpp_common/interruption.hpp" //****************************************** @@ -199,4 +199,4 @@ Pgr_prim::primDD( } // namespace functions } // namespace pgrouting -#endif // INCLUDE_SPANNINGTREE_PGR_PRIM_HPP_ +#endif // INCLUDE_SPANNINGTREE_PRIM_HPP_ diff --git a/include/topologicalSort/pgr_topologicalSort.hpp b/include/topologicalSort/topologicalSort.hpp similarity index 90% rename from include/topologicalSort/pgr_topologicalSort.hpp rename to include/topologicalSort/topologicalSort.hpp index b45dd639f78..9b0044546a3 100644 --- a/include/topologicalSort/pgr_topologicalSort.hpp +++ b/include/topologicalSort/topologicalSort.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_topologicalSort.hpp +File: topologicalSort.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -22,8 +22,8 @@ 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_TOPOLOGICALSORT_PGR_TOPOLOGICALSORT_HPP_ -#define INCLUDE_TOPOLOGICALSORT_PGR_TOPOLOGICALSORT_HPP_ +#ifndef INCLUDE_TOPOLOGICALSORT_TOPOLOGICALSORT_HPP_ +#define INCLUDE_TOPOLOGICALSORT_TOPOLOGICALSORT_HPP_ #pragma once @@ -42,8 +42,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "c_types//i_rt.h" // user's functions @@ -98,4 +98,4 @@ Pgr_topologicalSort< G >::topologicalSort( } -#endif // INCLUDE_TOPOLOGICALSORT_PGR_TOPOLOGICALSORT_HPP_ +#endif // INCLUDE_TOPOLOGICALSORT_TOPOLOGICALSORT_HPP_ diff --git a/include/transitiveClosure/pgr_transitiveClosure.hpp b/include/transitiveClosure/transitiveClosure.hpp similarity index 90% rename from include/transitiveClosure/pgr_transitiveClosure.hpp rename to include/transitiveClosure/transitiveClosure.hpp index 0a88925bf1f..214d1e85566 100644 --- a/include/transitiveClosure/pgr_transitiveClosure.hpp +++ b/include/transitiveClosure/transitiveClosure.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_contract.hpp +File: transitiveClosure.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_TRANSITIVECLOSURE_PGR_TRANSITIVECLOSURE_HPP_ -#define INCLUDE_TRANSITIVECLOSURE_PGR_TRANSITIVECLOSURE_HPP_ +#ifndef INCLUDE_TRANSITIVECLOSURE_TRANSITIVECLOSURE_HPP_ +#define INCLUDE_TRANSITIVECLOSURE_TRANSITIVECLOSURE_HPP_ #pragma once @@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" template < class G > class Pgr_transitiveClosure; @@ -72,4 +72,4 @@ Pgr_transitiveClosure< G >::transitiveClosure( -#endif // INCLUDE_TRANSITIVECLOSURE_PGR_TRANSITIVECLOSURE_HPP_ +#endif // INCLUDE_TRANSITIVECLOSURE_TRANSITIVECLOSURE_HPP_ diff --git a/include/traversal/pgr_depthFirstSearch.hpp b/include/traversal/depthFirstSearch.hpp similarity index 96% rename from include/traversal/pgr_depthFirstSearch.hpp rename to include/traversal/depthFirstSearch.hpp index b417985b752..30c10b708bf 100644 --- a/include/traversal/pgr_depthFirstSearch.hpp +++ b/include/traversal/depthFirstSearch.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_depthFirstSearch.hpp +File: depthFirstSearch.hpp Copyright (c) 2020 pgRouting developers Mail: project@pgrouting.org @@ -21,8 +21,8 @@ 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_TRAVERSAL_PGR_DEPTHFIRSTSEARCH_HPP_ -#define INCLUDE_TRAVERSAL_PGR_DEPTHFIRSTSEARCH_HPP_ +#ifndef INCLUDE_TRAVERSAL_DEPTHFIRSTSEARCH_HPP_ +#define INCLUDE_TRAVERSAL_DEPTHFIRSTSEARCH_HPP_ #pragma once #include @@ -32,8 +32,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" #include "c_types/mst_rt.h" @@ -213,4 +213,4 @@ class Pgr_depthFirstSearch { } // namespace functions } // namespace pgrouting -#endif // INCLUDE_TRAVERSAL_PGR_DEPTHFIRSTSEARCH_HPP_ +#endif // INCLUDE_TRAVERSAL_DEPTHFIRSTSEARCH_HPP_ diff --git a/include/trsp/GraphDefinition.h b/include/trsp/GraphDefinition.hpp similarity index 96% rename from include/trsp/GraphDefinition.h rename to include/trsp/GraphDefinition.hpp index f3a82b71ac0..ea10b83d67e 100644 --- a/include/trsp/GraphDefinition.h +++ b/include/trsp/GraphDefinition.hpp @@ -1,7 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: GraphDefinition.h - +File: GraphDefinition.hpp Copyright (c) 2012 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_TRSP_GRAPHDEFINITION_H_ -#define INCLUDE_TRSP_GRAPHDEFINITION_H_ +#ifndef INCLUDE_TRSP_GRAPHDEFINITION_HPP_ +#define INCLUDE_TRSP_GRAPHDEFINITION_HPP_ #include @@ -43,7 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // using namespace std; -using Edge_t = struct Edge_t; +using Edge_t = struct Edge_rt; typedef std::vector LongVector; typedef std::vector VectorOfLongVector; typedef std::pair PIB; @@ -161,4 +159,4 @@ class GraphDefinition { bool m_bIsGraphConstructed; }; -#endif // INCLUDE_TRSP_GRAPHDEFINITION_H_ +#endif // INCLUDE_TRSP_GRAPHDEFINITION_HPP_ diff --git a/include/trsp/edgeInfo.h b/include/trsp/edgeInfo.hpp similarity index 92% rename from include/trsp/edgeInfo.h rename to include/trsp/edgeInfo.hpp index 7f19c5d6f63..d015008c9cb 100644 --- a/include/trsp/edgeInfo.h +++ b/include/trsp/edgeInfo.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: edgeInfo.h +File: edgeInfo.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -23,14 +22,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_TRSP_EDGEINFO_H_ -#define INCLUDE_TRSP_EDGEINFO_H_ +#ifndef INCLUDE_TRSP_EDGEINFO_HPP_ +#define INCLUDE_TRSP_EDGEINFO_HPP_ #include -#include "c_types/edge_t.h" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/edge_t.hpp" +#include "cpp_common/assert.hpp" namespace pgrouting { namespace trsp { @@ -94,4 +93,4 @@ class EdgeInfo { } // namespace trsp } // namespace pgrouting -#endif // INCLUDE_TRSP_EDGEINFO_H_ +#endif // INCLUDE_TRSP_EDGEINFO_HPP_ diff --git a/include/trsp/pgr_trspHandler.h b/include/trsp/trspHandler.hpp similarity index 88% rename from include/trsp/pgr_trspHandler.h rename to include/trsp/trspHandler.hpp index 1e8550ec1de..772f6666972 100644 --- a/include/trsp/pgr_trspHandler.h +++ b/include/trsp/trspHandler.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: pgr_trspHandler.h +File: trspHandler.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -23,8 +22,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_TRSP_PGR_TRSPHANDLER_H_ -#define INCLUDE_TRSP_PGR_TRSPHANDLER_H_ +#ifndef INCLUDE_TRSP_TRSPHANDLER_HPP_ +#define INCLUDE_TRSP_TRSPHANDLER_HPP_ #include @@ -41,9 +40,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/basePath_SSEC.hpp" -#include "trsp/edgeInfo.h" +#include "trsp/edgeInfo.hpp" #include "cpp_common/rule.hpp" -#include "cpp_common/pgr_messages.h" +#include "cpp_common/messages.hpp" namespace pgrouting { namespace trsp { @@ -102,6 +101,15 @@ class Pgr_trspHandler : public pgrouting::Pgr_messages { public: + Pgr_trspHandler( + std::vector &edges, + const std::vector &new_edges, + const bool directed, + const std::vector &ruleList); + Pgr_trspHandler( + std::vector &edges, + const bool directed, + const std::vector &ruleList); Pgr_trspHandler( Edge_t *edges, const size_t edge_count, @@ -135,6 +143,7 @@ class Pgr_trspHandler : public pgrouting::Pgr_messages { void clear(); private: + void construct_graph(const std::vector&, const bool); void construct_graph( Edge_t *edges, const size_t edge_count, @@ -178,6 +187,8 @@ class Pgr_trspHandler : public pgrouting::Pgr_messages { void renumber_edges(Edge_t*, const size_t); void renumber_edges(Edge_t*, const size_t, std::vector&); + void renumber_edges(std::vector&); + void renumber_edges(std::vector&, std::vector&); void add_to_que( double cost, @@ -234,4 +245,4 @@ class Pgr_trspHandler : public pgrouting::Pgr_messages { } // namespace trsp } // namespace pgrouting -#endif // INCLUDE_TRSP_PGR_TRSPHANDLER_H_ +#endif // INCLUDE_TRSP_TRSPHANDLER_HPP_ diff --git a/include/tsp/tsp.hpp b/include/tsp/tsp.hpp index c08c6824b51..9f35c6ea223 100644 --- a/include/tsp/tsp.hpp +++ b/include/tsp/tsp.hpp @@ -40,9 +40,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_types/iid_t_rt.h" -#include "c_types/coordinate_t.h" -#include "cpp_common/pgr_messages.h" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/coordinate_t.hpp" +#include "cpp_common/messages.hpp" +#include "cpp_common/assert.hpp" namespace pgrouting { @@ -74,8 +74,8 @@ class TSP : public Pgr_messages { std::deque> result, size_t limit, int cycles); - TSP(IID_t_rt *, size_t, bool); - TSP(Coordinate_t *, size_t, bool); + explicit TSP(std::vector&); + explicit TSP(const std::vector&); TSP() = delete; #if BOOST_VERSION >= 106800 diff --git a/include/visitors/astar_visitors.hpp b/include/visitors/astar_visitors.hpp index 5d24e61627b..15ec4b44d03 100644 --- a/include/visitors/astar_visitors.hpp +++ b/include/visitors/astar_visitors.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -file: astar_visitors.hpp +File: astar_visitors.hpp Copyright (c) 2023 Celia Virginia Vergara Castillo Copyright (c) 2015 Celia Virginia Vergara Castillo diff --git a/include/visitors/dfs_visitor.hpp b/include/visitors/dfs_visitor.hpp index 9b1de951f6b..3ddd341b757 100644 --- a/include/visitors/dfs_visitor.hpp +++ b/include/visitors/dfs_visitor.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: Dfs_visitor.hpp +File: dfs_visitor.hpp Copyright (c) 2020 pgRouting developers Mail: project@pgrouting.org diff --git a/include/visitors/dfs_visitor_with_root.hpp b/include/visitors/dfs_visitor_with_root.hpp index 26d10a4f9f5..19aec846dff 100644 --- a/include/visitors/dfs_visitor_with_root.hpp +++ b/include/visitors/dfs_visitor_with_root.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: Dfs_visitor_with_root.hpp +File: dfs_visitor_with_root.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/include/visitors/dijkstra_visitors.hpp b/include/visitors/dijkstra_visitors.hpp index 58db9b9d7c1..0acc99ac8e1 100644 --- a/include/visitors/dijkstra_visitors.hpp +++ b/include/visitors/dijkstra_visitors.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -file: dijkstra_visitors.hpp +File: dijkstra_visitors.hpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org @@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include "visitors/found_goals.hpp" +#include "cpp_common/assert.hpp" namespace pgrouting { namespace visitors { @@ -92,12 +93,9 @@ class dijkstra_distance_visitor : public boost::default_dijkstra_visitor { public: explicit dijkstra_distance_visitor( double distance_goal, - std::deque &nodesInDistance, std::vector &distances) : m_distance_goal(distance_goal), - m_nodes(nodesInDistance), m_dist(distances) { - pgassert(m_nodes.empty()); pgassert(m_distance_goal > 0); } template @@ -105,12 +103,10 @@ class dijkstra_distance_visitor : public boost::default_dijkstra_visitor { if (m_dist[u] > m_distance_goal) { throw found_goals(); } - m_nodes.push_back(u); } private: double m_distance_goal; - std::deque &m_nodes; std::vector &m_dist; }; @@ -118,69 +114,55 @@ template class dijkstra_distance_visitor_no_init : public boost::default_dijkstra_visitor { public: explicit dijkstra_distance_visitor_no_init( - std::ostringstream &p_log, - V source, + V root, double distance_goal, std::vector &predecessors, std::vector &distances, std::vector &color_map) : - log(p_log), - first(source), + m_root(root), m_distance_goal(distance_goal), m_num_examined(0), m_predecessors(predecessors), m_dist(distances), m_color(color_map) { - pgassert(m_num_examined == 0); pgassert(m_distance_goal > 0); } template void examine_vertex(V u, B_G &) { - if ( 0 == m_num_examined++) first = u; + if ( 0 == m_num_examined++) m_root = u; if (m_dist[u] > m_distance_goal) { throw found_goals(); } - if (u != first && m_predecessors[u] == u) { + if (u != m_root && m_predecessors[u] == u) { m_color[u] = boost::black_color; } } template void examine_edge(E e, B_G &g) { - if (source(e, g) != first - && m_predecessors[source(e, g)] == source(e, g)) { + if (source(e, g) != m_root && m_predecessors[source(e, g)] == source(e, g)) { m_color[target(e, g)] = boost::black_color; } } - template - void edge_relaxed(E, B_G &) { - } - template void edge_not_relaxed(E e, B_G &g) { - if (source(e, g) != first - && m_predecessors[source(e, g)] == source(e, g)) { + if (source(e, g) != m_root && m_predecessors[source(e, g)] == source(e, g)) { m_color[target(e, g)] = boost::black_color; } } - template - void finish_vertex(V, B_G &) { - } - template void discover_vertex(V u, B_G &) { - if (u != first && m_predecessors[u] == u) { + if (u != m_root && m_predecessors[u] == u) { m_color[u] = boost::black_color; } } private: - std::ostringstream &log; - V first; + V m_root; double m_distance_goal; size_t m_num_examined; std::vector &m_predecessors; diff --git a/include/visitors/edges_order_bfs_visitor.hpp b/include/visitors/edges_order_bfs_visitor.hpp index d779e8761e5..2475019b023 100644 --- a/include/visitors/edges_order_bfs_visitor.hpp +++ b/include/visitors/edges_order_bfs_visitor.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File:.edges_order_bfs_visitor.hpp +File: edges_order_bfs_visitor.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/include/visitors/found_goals.hpp b/include/visitors/found_goals.hpp index 3fadedae4e3..e36567a2213 100644 --- a/include/visitors/found_goals.hpp +++ b/include/visitors/found_goals.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -file: found_goals.hpp +File: found_goals.hpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org diff --git a/include/vrp/book_keeping.h b/include/vrp/book_keeping.h deleted file mode 100644 index f91c6a43c63..00000000000 --- a/include/vrp/book_keeping.h +++ /dev/null @@ -1,115 +0,0 @@ -/*PGR-GNU***************************************************************** - * - * FILE: book_keeping.h - * - * Copyright (c) 2017 pgRouting developers - * Mail: project@pgrouting.org - * - * ------ - -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*/ - -/*! @file */ - -#ifndef INCLUDE_VRP_BOOK_KEEPING_H_ -#define INCLUDE_VRP_BOOK_KEEPING_H_ -#pragma once - -#include -#include -#include -#include "vrp/vehicle_pickDeliver.h" -/** - * Book keeping class for swapping orders between vehicles - */ - -namespace pgrouting { -namespace vrp { - -class Swap_bk; -class Swap_info { - friend class Swap_bk; - - public: - Swap_info() = delete; - Swap_info(const Swap_info &) = default; - Swap_info(const Vehicle_pickDeliver &from, - const Vehicle_pickDeliver &to, - size_t from_o, - size_t to_o, - double delta); - friend std::ostream& operator << (std::ostream& log, const Swap_info &d); -#if 0 - { - log - << "\n" << d.from_truck.tau() << " --> " - << d.from_order - << "(" - << d.from_truck.orders()[d.from_order].pickup().original_id() - << ")" - << "\n" << d.to_truck.tau() << " --> " - << d.to_order - << "(" - << d.to_truck.orders()[d.to_order].pickup().original_id() - << ")" - << "\n" << "delta = " << d.estimated_delta; - return log; - } -#endif - - public: - Vehicle_pickDeliver from_truck; - Vehicle_pickDeliver to_truck; - size_t from_order; - size_t to_order; - double estimated_delta; -}; - - -class Swap_bk { - private: - class Compare { - public: - bool operator() (const Swap_info &lhs, const Swap_info rhs) { - return lhs.estimated_delta > rhs.estimated_delta; - } - }; - - public: - typedef std::priority_queue< - Swap_info, - std::vector, - Compare > Swaps_queue; - - - Swaps_queue m_swaps; - friend std::ostream& operator<< (std::ostream &log, const Swap_bk &data); - - public: - Swap_bk() = default; - Swap_bk(const Swap_bk &bk) = default; - Swaps_queue& possible_swaps() {return m_swaps;} - void push(const Swap_info& data) {m_swaps.push(data);} - Swap_info top() {return m_swaps.top();} - void pop() {return m_swaps.pop();} - bool empty() {return m_swaps.empty();} -}; - -} // namespace vrp -} // namespace pgrouting - -#endif // INCLUDE_VRP_BOOK_KEEPING_H_ diff --git a/include/vrp/dnode.h b/include/vrp/dnode.hpp similarity index 89% rename from include/vrp/dnode.h rename to include/vrp/dnode.hpp index 1387fa1037f..9954b6a8578 100644 --- a/include/vrp/dnode.h +++ b/include/vrp/dnode.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: dnode.h +File: dnode.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -23,16 +22,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -/*! @file dnode.h */ +/*! @file dnode.hpp */ -#ifndef INCLUDE_VRP_DNODE_H_ -#define INCLUDE_VRP_DNODE_H_ +#ifndef INCLUDE_VRP_DNODE_HPP_ +#define INCLUDE_VRP_DNODE_HPP_ #pragma once #include #include -#include "cpp_common/identifier.h" -#include "cpp_common/pgr_messages.h" +#include "cpp_common/identifier.hpp" +#include "cpp_common/messages.hpp" namespace pgrouting { namespace vrp { @@ -73,4 +72,4 @@ class Dnode : public Identifier { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_DNODE_H_ +#endif // INCLUDE_VRP_DNODE_HPP_ diff --git a/include/vrp/fleet.h b/include/vrp/fleet.hpp similarity index 93% rename from include/vrp/fleet.h rename to include/vrp/fleet.hpp index c4760004af4..71c946f0947 100644 --- a/include/vrp/fleet.h +++ b/include/vrp/fleet.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: fleet.h +File: fleet.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_FLEET_H_ -#define INCLUDE_VRP_FLEET_H_ +#ifndef INCLUDE_VRP_FLEET_HPP_ +#define INCLUDE_VRP_FLEET_HPP_ #pragma once #include @@ -35,8 +34,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "cpp_common/identifiers.hpp" -#include "vrp/pd_problem.h" -#include "vrp/vehicle_pickDeliver.h" +#include "vrp/pd_problem.hpp" +#include "vrp/vehicle_pickDeliver.hpp" namespace pgrouting { namespace vrp { @@ -109,4 +108,4 @@ class Fleet { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_FLEET_H_ +#endif // INCLUDE_VRP_FLEET_HPP_ diff --git a/include/vrp/initial_solution.h b/include/vrp/initial_solution.hpp similarity index 86% rename from include/vrp/initial_solution.h rename to include/vrp/initial_solution.hpp index 9dbfc3fd1c5..e0099902fa4 100644 --- a/include/vrp/initial_solution.h +++ b/include/vrp/initial_solution.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: initial_solution.h +File: initial_solution.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,15 +24,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_INITIAL_SOLUTION_H_ -#define INCLUDE_VRP_INITIAL_SOLUTION_H_ +#ifndef INCLUDE_VRP_INITIAL_SOLUTION_HPP_ +#define INCLUDE_VRP_INITIAL_SOLUTION_HPP_ #pragma once #include #include -#include "vrp/pd_orders.h" -#include "vrp/solution.h" -#include "vrp/initials_code.h" +#include "vrp/pd_orders.hpp" +#include "vrp/solution.hpp" +#include "vrp/initials_code.hpp" #include "cpp_common/identifiers.hpp" namespace pgrouting { @@ -68,4 +67,4 @@ class Initial_solution : public Solution { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_INITIAL_SOLUTION_H_ +#endif // INCLUDE_VRP_INITIAL_SOLUTION_HPP_ diff --git a/include/vrp/initials_code.h b/include/vrp/initials_code.hpp similarity index 91% rename from include/vrp/initials_code.h rename to include/vrp/initials_code.hpp index 7b56033a638..466359d39d3 100644 --- a/include/vrp/initials_code.h +++ b/include/vrp/initials_code.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: initials_code.h +File: initials_code.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_INITIALS_CODE_H_ -#define INCLUDE_VRP_INITIALS_CODE_H_ +#ifndef INCLUDE_VRP_INITIALS_CODE_HPP_ +#define INCLUDE_VRP_INITIALS_CODE_HPP_ #pragma once namespace pgrouting { @@ -47,4 +46,4 @@ enum Initials_code { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_INITIALS_CODE_H_ +#endif // INCLUDE_VRP_INITIALS_CODE_HPP_ diff --git a/include/vrp/optimize.h b/include/vrp/optimize.hpp similarity index 90% rename from include/vrp/optimize.h rename to include/vrp/optimize.hpp index 5fb67ee5baa..88bf57844ec 100644 --- a/include/vrp/optimize.h +++ b/include/vrp/optimize.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: optimize.cpp +File: optimize.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,18 +24,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_OPTIMIZE_H_ -#define INCLUDE_VRP_OPTIMIZE_H_ +#ifndef INCLUDE_VRP_OPTIMIZE_HPP_ +#define INCLUDE_VRP_OPTIMIZE_HPP_ #pragma once -#include "vrp/optimize.h" +#include "vrp/solution.hpp" +#include "vrp/pickDeliver.hpp" namespace pgrouting { namespace vrp { -class Solution; -class Pgr_pickDeliver; - class Optimize : public Solution { public: @@ -71,4 +68,4 @@ class Optimize : public Solution { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_OPTIMIZE_H_ +#endif // INCLUDE_VRP_OPTIMIZE_HPP_ diff --git a/include/vrp/order.h b/include/vrp/order.hpp similarity index 95% rename from include/vrp/order.h rename to include/vrp/order.hpp index 789bd651599..3d77aaaeb67 100644 --- a/include/vrp/order.h +++ b/include/vrp/order.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: order.h +File: order.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,15 +24,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_ORDER_H_ -#define INCLUDE_VRP_ORDER_H_ +#ifndef INCLUDE_VRP_ORDER_HPP_ +#define INCLUDE_VRP_ORDER_HPP_ #pragma once #include -#include "cpp_common/identifier.h" +#include "cpp_common/identifier.hpp" #include "cpp_common/identifiers.hpp" -#include "vrp/vehicle_node.h" +#include "vrp/vehicle_node.hpp" namespace pgrouting { namespace vrp { @@ -183,4 +182,4 @@ class Order : public Identifier { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_ORDER_H_ +#endif // INCLUDE_VRP_ORDER_HPP_ diff --git a/include/vrp/pd_orders.h b/include/vrp/pd_orders.hpp similarity index 91% rename from include/vrp/pd_orders.h rename to include/vrp/pd_orders.hpp index 42978daafa6..d8d1b0641fd 100644 --- a/include/vrp/pd_orders.h +++ b/include/vrp/pd_orders.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: pd_orders.h +File: pd_orders.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,26 +24,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_PD_ORDERS_H_ -#define INCLUDE_VRP_PD_ORDERS_H_ +#ifndef INCLUDE_VRP_PD_ORDERS_HPP_ +#define INCLUDE_VRP_PD_ORDERS_HPP_ #pragma once #include #include #include -#include "c_types/pickDeliver/orders_t.h" +#include "cpp_common/orders_t.hpp" #include "cpp_common/identifiers.hpp" -#include "vrp/pd_problem.h" +#include "vrp/pd_problem.hpp" +#include "vrp/order.hpp" +#include "vrp/vehicle_node.hpp" namespace pgrouting { namespace vrp { -class Order; -class Vehicle_node; - class PD_Orders { /** PD_rpblem needs access to set up the problem pointer */ friend class PD_problem; @@ -105,4 +103,4 @@ class PD_Orders { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_PD_ORDERS_H_ +#endif // INCLUDE_VRP_PD_ORDERS_HPP_ diff --git a/include/vrp/pd_problem.h b/include/vrp/pd_problem.hpp similarity index 87% rename from include/vrp/pd_problem.h rename to include/vrp/pd_problem.hpp index 5858a537d67..717347daa81 100644 --- a/include/vrp/pd_problem.h +++ b/include/vrp/pd_problem.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: pd_problem.h +File: pd_problem.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -25,12 +24,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_PD_PROBLEM_H_ -#define INCLUDE_VRP_PD_PROBLEM_H_ +#ifndef INCLUDE_VRP_PD_PROBLEM_HPP_ +#define INCLUDE_VRP_PD_PROBLEM_HPP_ #pragma once -#include "cpp_common/pgr_messages.h" -#include "vrp/initials_code.h" +#include "cpp_common/messages.hpp" +#include "vrp/initials_code.hpp" @@ -54,4 +53,4 @@ class PD_problem { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_PD_PROBLEM_H_ +#endif // INCLUDE_VRP_PD_PROBLEM_HPP_ diff --git a/include/vrp/pgr_pickDeliver.h b/include/vrp/pickDeliver.hpp similarity index 87% rename from include/vrp/pgr_pickDeliver.h rename to include/vrp/pickDeliver.hpp index 385eac4dae2..fb316636adb 100644 --- a/include/vrp/pgr_pickDeliver.h +++ b/include/vrp/pickDeliver.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: pgr_pickDeliver.h +File: pickDeliver.hpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_PGR_PICKDELIVER_H_ -#define INCLUDE_VRP_PGR_PICKDELIVER_H_ +#ifndef INCLUDE_VRP_PICKDELIVER_HPP_ +#define INCLUDE_VRP_PICKDELIVER_HPP_ #pragma once @@ -35,13 +34,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "c_types/pickDeliver/vehicle_t.h" -#include "c_types/pickDeliver/orders_t.h" -#include "vrp/pd_problem.h" -#include "cpp_common/Dmatrix.h" -#include "vrp/fleet.h" -#include "vrp/pd_orders.h" -#include "vrp/solution.h" +#include "cpp_common/vehicle_t.hpp" +#include "cpp_common/orders_t.hpp" +#include "vrp/pd_problem.hpp" +#include "cpp_common/Dmatrix.hpp" +#include "vrp/fleet.hpp" +#include "vrp/pd_orders.hpp" +#include "vrp/solution.hpp" using Schedule_rt = struct Schedule_rt; @@ -117,4 +116,4 @@ class Pgr_pickDeliver : public PD_problem { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_PGR_PICKDELIVER_H_ +#endif // INCLUDE_VRP_PICKDELIVER_HPP_ diff --git a/include/vrp/solution.h b/include/vrp/solution.hpp similarity index 93% rename from include/vrp/solution.h rename to include/vrp/solution.hpp index 629f8ba57c0..d90ea0af490 100644 --- a/include/vrp/solution.h +++ b/include/vrp/solution.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: solution.h +File: solution.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_SOLUTION_H_ -#define INCLUDE_VRP_SOLUTION_H_ +#ifndef INCLUDE_VRP_SOLUTION_HPP_ +#define INCLUDE_VRP_SOLUTION_HPP_ #pragma once #include @@ -34,8 +33,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "vrp/vehicle_pickDeliver.h" -#include "vrp/fleet.h" +#include "vrp/vehicle_pickDeliver.hpp" +#include "vrp/fleet.hpp" using Schedule_rt = struct Schedule_rt; @@ -120,4 +119,4 @@ class Solution { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_SOLUTION_H_ +#endif // INCLUDE_VRP_SOLUTION_HPP_ diff --git a/include/vrp/tw_node.h b/include/vrp/tw_node.hpp similarity index 94% rename from include/vrp/tw_node.h rename to include/vrp/tw_node.hpp index e2f1f28217e..812edfff8a3 100644 --- a/include/vrp/tw_node.h +++ b/include/vrp/tw_node.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: tw_node.h +File: tw_node.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,19 +24,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_TW_NODE_H_ -#define INCLUDE_VRP_TW_NODE_H_ +#ifndef INCLUDE_VRP_TW_NODE_HPP_ +#define INCLUDE_VRP_TW_NODE_HPP_ #pragma once #include -#include "c_types/pickDeliver/orders_t.h" -#include "c_types/pickDeliver/vehicle_t.h" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/identifier.h" +#include "cpp_common/orders_t.hpp" +#include "cpp_common/vehicle_t.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/identifier.hpp" -#include "vrp/pd_problem.h" -#include "vrp/dnode.h" +#include "vrp/pd_problem.hpp" +#include "vrp/dnode.hpp" namespace pgrouting { namespace vrp { @@ -232,4 +231,4 @@ class Tw_node : public Dnode { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_TW_NODE_H_ +#endif // INCLUDE_VRP_TW_NODE_HPP_ diff --git a/include/vrp/vehicle.h b/include/vrp/vehicle.hpp similarity index 97% rename from include/vrp/vehicle.h rename to include/vrp/vehicle.hpp index 7e761a5c0f7..f35c6af705e 100644 --- a/include/vrp/vehicle.h +++ b/include/vrp/vehicle.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: vehicle.h +File: vehicle.hpp Copyright (c) 2016 pgRouting developers Mail: project@pgrouting.org @@ -25,8 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_VEHICLE_H_ -#define INCLUDE_VRP_VEHICLE_H_ +#ifndef INCLUDE_VRP_VEHICLE_HPP_ +#define INCLUDE_VRP_VEHICLE_HPP_ #pragma once #include @@ -38,8 +37,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include -#include "cpp_common/identifier.h" -#include "vrp/vehicle_node.h" +#include "cpp_common/identifier.hpp" +#include "vrp/vehicle_node.hpp" using Schedule_rt = struct Schedule_rt; namespace pgrouting { @@ -325,4 +324,4 @@ class Vehicle : public Identifier { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_VEHICLE_H_ +#endif // INCLUDE_VRP_VEHICLE_HPP_ diff --git a/include/vrp/vehicle_node.h b/include/vrp/vehicle_node.hpp similarity index 96% rename from include/vrp/vehicle_node.h rename to include/vrp/vehicle_node.hpp index bb7a4c03eda..0845d95d8d1 100644 --- a/include/vrp/vehicle_node.h +++ b/include/vrp/vehicle_node.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: vehicle_node.h +File: vehicle_node.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,14 +24,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_VEHICLE_NODE_H_ -#define INCLUDE_VRP_VEHICLE_NODE_H_ +#ifndef INCLUDE_VRP_VEHICLE_NODE_HPP_ +#define INCLUDE_VRP_VEHICLE_NODE_HPP_ #pragma once #include -#include "vrp/tw_node.h" +#include "vrp/tw_node.hpp" namespace pgrouting { namespace vrp { @@ -175,4 +174,4 @@ class Vehicle_node: public Tw_node { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_VEHICLE_NODE_H_ +#endif // INCLUDE_VRP_VEHICLE_NODE_HPP_ diff --git a/include/vrp/vehicle_pickDeliver.h b/include/vrp/vehicle_pickDeliver.hpp similarity index 93% rename from include/vrp/vehicle_pickDeliver.h rename to include/vrp/vehicle_pickDeliver.hpp index f9e918e91c9..bb6a816e7fb 100644 --- a/include/vrp/vehicle_pickDeliver.h +++ b/include/vrp/vehicle_pickDeliver.hpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: vehicle_pickDeliver.h +File: vehicle_pickDeliver.hpp Copyright (c) 2016 pgRouting developers Mail: project@pgrouting.org @@ -25,16 +24,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_VRP_VEHICLE_PICKDELIVER_H_ -#define INCLUDE_VRP_VEHICLE_PICKDELIVER_H_ +#ifndef INCLUDE_VRP_VEHICLE_PICKDELIVER_HPP_ +#define INCLUDE_VRP_VEHICLE_PICKDELIVER_HPP_ #pragma once #include -#include "vrp/order.h" -#include "vrp/pd_orders.h" -#include "vrp/tw_node.h" -#include "vrp/vehicle.h" -#include "vrp/initials_code.h" +#include "vrp/order.hpp" +#include "vrp/pd_orders.hpp" +#include "vrp/tw_node.hpp" +#include "vrp/vehicle.hpp" +#include "vrp/initials_code.hpp" #include "cpp_common/identifiers.hpp" namespace pgrouting { @@ -181,4 +180,4 @@ class Vehicle_pickDeliver : public Vehicle { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_VRP_VEHICLE_PICKDELIVER_H_ +#endif // INCLUDE_VRP_VEHICLE_PICKDELIVER_HPP_ diff --git a/include/withPoints/pgr_withPoints.hpp b/include/withPoints/withPoints.hpp similarity index 92% rename from include/withPoints/pgr_withPoints.hpp rename to include/withPoints/withPoints.hpp index 7a26c343d53..6fa13398b2a 100644 --- a/include/withPoints/pgr_withPoints.hpp +++ b/include/withPoints/withPoints.hpp @@ -26,13 +26,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_WITHPOINTS_PGR_WITHPOINTS_HPP_ -#define INCLUDE_WITHPOINTS_PGR_WITHPOINTS_HPP_ +#ifndef INCLUDE_WITHPOINTS_WITHPOINTS_HPP_ +#define INCLUDE_WITHPOINTS_WITHPOINTS_HPP_ #pragma once #include -#include "c_types/point_on_edge_t.h" -#include "cpp_common/pgr_messages.h" +#include "cpp_common/point_on_edge_t.hpp" +#include "cpp_common/messages.hpp" #include "cpp_common/basePath_SSEC.hpp" namespace pgrouting { @@ -98,4 +98,4 @@ class Pg_points_graph : public Pgr_messages { } // namespace pgrouting -#endif // INCLUDE_WITHPOINTS_PGR_WITHPOINTS_HPP_ +#endif // INCLUDE_WITHPOINTS_WITHPOINTS_HPP_ diff --git a/include/yen/pgr_ksp.hpp b/include/yen/ksp.hpp similarity index 96% rename from include/yen/pgr_ksp.hpp rename to include/yen/ksp.hpp index d4bae23698e..11b10e36d76 100644 --- a/include/yen/pgr_ksp.hpp +++ b/include/yen/ksp.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_ksp.hpp +File: ksp.hpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -30,8 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_YEN_PGR_KSP_HPP_ -#define INCLUDE_YEN_PGR_KSP_HPP_ +#ifndef INCLUDE_YEN_KSP_HPP_ +#define INCLUDE_YEN_KSP_HPP_ #pragma once #include @@ -43,9 +43,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "dijkstra/dijkstra.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/compPaths.h" -#include "cpp_common/pgr_messages.h" +#include "cpp_common/assert.hpp" +#include "cpp_common/compPaths.hpp" +#include "cpp_common/messages.hpp" #include "cpp_common/basePath_SSEC.hpp" namespace pgrouting { @@ -277,4 +277,4 @@ namespace algorithms { } // namespace pgrouting -#endif // INCLUDE_YEN_PGR_KSP_HPP_ +#endif // INCLUDE_YEN_KSP_HPP_ diff --git a/include/yen/pgr_turnRestrictedPath.hpp b/include/yen/turnRestrictedPath.hpp similarity index 95% rename from include/yen/pgr_turnRestrictedPath.hpp rename to include/yen/turnRestrictedPath.hpp index 3be8ab492e6..a314b3a4625 100644 --- a/include/yen/pgr_turnRestrictedPath.hpp +++ b/include/yen/turnRestrictedPath.hpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_dijkstraTR.hpp +File: turnRestrictedPath.hpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -26,22 +26,21 @@ 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_YEN_PGR_TURNRESTRICTEDPATH_HPP_ -#define INCLUDE_YEN_PGR_TURNRESTRICTEDPATH_HPP_ +#ifndef INCLUDE_YEN_TURNRESTRICTEDPATH_HPP_ +#define INCLUDE_YEN_TURNRESTRICTEDPATH_HPP_ #pragma once -#include "yen/pgr_ksp.hpp" - #include #include #include #include #include -#include "cpp_common/pgr_assert.h" +#include "yen/ksp.hpp" +#include "cpp_common/assert.hpp" #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/compPaths.h" -#include "cpp_common/pgr_messages.h" +#include "cpp_common/compPaths.hpp" +#include "cpp_common/messages.hpp" #include "cpp_common/rule.hpp" namespace pgrouting { @@ -265,4 +264,4 @@ class Pgr_turnRestrictedPath : public Pgr_ksp< G > { -#endif // INCLUDE_YEN_PGR_TURNRESTRICTEDPATH_HPP_ +#endif // INCLUDE_YEN_TURNRESTRICTEDPATH_HPP_ diff --git a/locale/de/LC_MESSAGES/index.po b/locale/de/LC_MESSAGES/index.po index 1ad07fa7b8a..b0a7ef6c4e1 100644 --- a/locale/de/LC_MESSAGES/index.po +++ b/locale/de/LC_MESSAGES/index.po @@ -1,11 +1,11 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # FIRST AUTHOR , YEAR. # msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-06-25 12:55-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" diff --git a/locale/de/LC_MESSAGES/pgrouting_doc_strings.po b/locale/de/LC_MESSAGES/pgrouting_doc_strings.po index a35ab0143c9..3e0cd6aad26 100644 --- a/locale/de/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/de/LC_MESSAGES/pgrouting_doc_strings.po @@ -1,12 +1,12 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # Regina Obe , 2023. msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-10 03:40+0000\n" +"POT-Creation-Date: 2024-10-17 00:50+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -15566,6 +15566,9 @@ msgstr "" msgid "postgis 3.0.0" msgstr "" +msgid "g++ 13+ is supported" +msgstr "" + msgid "Code fixes" msgstr "" diff --git a/locale/en/LC_MESSAGES/index.po b/locale/en/LC_MESSAGES/index.po index f271d04f43a..48ce38b67d2 100644 --- a/locale/en/LC_MESSAGES/index.po +++ b/locale/en/LC_MESSAGES/index.po @@ -1,12 +1,12 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # FIRST AUTHOR , 2022. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-06-25 12:55-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" diff --git a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po index c869f7a3856..7c41681d7ba 100644 --- a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po @@ -1,14 +1,14 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # FIRST AUTHOR , 2022. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-10 03:40+0000\n" +"POT-Creation-Date: 2024-10-17 00:50+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -15619,6 +15619,9 @@ msgstr "" msgid "postgis 3.0.0" msgstr "" +msgid "g++ 13+ is supported" +msgstr "" + msgid "Code fixes" msgstr "" diff --git a/locale/es/LC_MESSAGES/index.po b/locale/es/LC_MESSAGES/index.po index 94f36a7898e..aebad72d2b0 100644 --- a/locale/es/LC_MESSAGES/index.po +++ b/locale/es/LC_MESSAGES/index.po @@ -1,11 +1,11 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # FIRST AUTHOR , 2022. # msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-06-25 12:55-0500\n" "PO-Revision-Date: 2022-09-29 16:37+0000\n" diff --git a/locale/es/LC_MESSAGES/pgrouting_doc_strings.po b/locale/es/LC_MESSAGES/pgrouting_doc_strings.po index 733f8e5ca6e..036b0d27241 100644 --- a/locale/es/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/es/LC_MESSAGES/pgrouting_doc_strings.po @@ -1,5 +1,5 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # FIRST AUTHOR , 2022. # Pedro Jose Rios Vergara , 2022. @@ -8,9 +8,9 @@ # DeepL , 2024. msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-10 03:40+0000\n" +"POT-Creation-Date: 2024-10-17 00:50+0000\n" "PO-Revision-Date: 2024-10-10 19:43+0000\n" "Last-Translator: DeepL \n" "Language-Team: Spanish `__" -#~ msgstr "" -#~ "`Wikipedia: Coloración de grafos `__" - -#~ msgid "There is no flow when a **source** is the same as a **target**." -#~ msgstr "" -#~ "No hay ningún flujo cuando el **orígen** es el mismo que el **destino**." - -#~ msgid "Any duplicated value in the source(s) or target(s) are ignored." -#~ msgstr "" -#~ "Cualquier valor duplicado en el/los orígen(es) o en el/los destino(s) " -#~ "será ignorado." - -#~ msgid "" -#~ "Creates a **super source** and edges to all the source(s), and a **super " -#~ "target** and the edges from all the targets(s)." -#~ msgstr "" -#~ "Crea una **súper origen**, con aristas para todos las fuentes(es), y un " -#~ "**súper destino** con aristas para todos los destino(s)." - -#~ msgid "" -#~ "There are several kinds of valid inner queries and also the columns " -#~ "returned are depending of the function. Which kind of inner query will " -#~ "depend on the function(s) requirements. To simplify variety of types, " -#~ "**ANY-INTEGER** and **ANY-NUMERICAL** is used." -#~ msgstr "" -#~ "Hay varios tipos de consultas internas válidas y también las columnas " -#~ "devueltas dependen de la función. El tipo de consulta interna dependerá " -#~ "de los requisitos de las funcion(es). Para simplificar la variedad de " -#~ "tipos, se utiliza **ENTEROS** y **FLOTANTES**." - -#~ msgid "wget" -#~ msgstr "wget" - -#~ msgid "" -#~ "``pgr_aStarCost`` - Total cost of the shortest path(s) using the A* " -#~ "algorithm." -#~ msgstr "" -#~ "``pgr_aStarCost`` —Costo total de la ruta más corta usando el algoritmo :" -#~ "A*." - -#~ msgid "" -#~ "The ``pgr_aStarCost`` function sumarizes of the cost of the shortest " -#~ "path(s) using the A* algorithm." -#~ msgstr "" -#~ "La función ``pgr_aStarCost`` sumarisa el costo de la ruta más corta " -#~ "usando el algoritmo A*." - -#~ msgid "" -#~ "``pgr_bdAstarCost`` - Total cost of the shortest path(s) using the " -#~ "bidirectional A* algorithm." -#~ msgstr "" -#~ "``pgr_bdAstarCost`` - Devuelve el costo agregado de la ruta más corta " -#~ "usando el algoritmo bidireccional A*." - -#~ msgid "" -#~ "The ``pgr_bdAstarCost`` function sumarizes of the cost of the shortest " -#~ "path(s) using the bidirectional A* algorithm." -#~ msgstr "" -#~ "La función ``pgr_bdAstarCost`` Sumariza el costo del camino más corto " -#~ "utilizando el algoritmo bidireccional A*." - -#~ msgid "" -#~ "``pgr_bdDijkstra`` — Returns the shortest path(s) using Bidirectional " -#~ "Dijkstra algorithm." -#~ msgstr "" -#~ "``pgr_bdDijkstra`` — Devuelve la(s) rutas más cortas mediante el " -#~ "algoritmo Bidirectional Dijkstra." - -#~ msgid "pgr_bdDijkstra(`Edges SQL`_, `Combinations SQL`_ , [``directed``])" -#~ msgstr "" -#~ "pgr_bdDijkstra(`SQL de aristas`_, `SQL de combinaciones`_, [``directed``])" - -#~ msgid "" -#~ "``pgr_bdDijkstraCost`` — Returns the shortest path(s)'s cost using " -#~ "Bidirectional Dijkstra algorithm." -#~ msgstr "" -#~ "``pgr_bdDijkstraCost`` — Devuelve la ruta(s) más corta utilizando el " -#~ "algoritmo de Dijkstra Bidireccional." - -#~ msgid "``pgr_bellmanFord`` — Shortest path(s) using Bellman-Ford algorithm." -#~ msgstr "" -#~ "``pgr_bellmanFord`` —Camino m+as corto usando el algoritmo de Bellman-" -#~ "Ford." - -#~ msgid "Identifier of the vertex" -#~ msgstr "Identificador del vértice" - -#~ msgid "" -#~ "``pgr_binaryBreadthFirstSearch`` — Returns the shortest path(s) in a " -#~ "binary graph." -#~ msgstr "" -#~ "``pgr_binaryBreadthFirstSearch`` — Regresa los caminos más cortos en un " -#~ "grafo binario." - -#~ msgid "" -#~ "``pgr_dagShortestPath`` — Returns the shortest path(s) for weighted " -#~ "directed acyclic graphs(DAG). In particular, the DAG shortest paths " -#~ "algorithm implemented by Boost.Graph." -#~ msgstr "" -#~ "``pgr_dagShortestPath`` — Devuelve la(s) rutas más cortas para los grafos " -#~ "acíclicos dirigidos ponderados (DAG). En particular, el algoritmo de " -#~ "rutas más cortas de DAG implementado por Boost.Graph." - -#~ msgid "``pgr_dijkstra`` — Shortest path(s) using Dijkstra algorithm." -#~ msgstr "" -#~ "``pgr_dijkstra`` — Ruta(s) más corta(s) usando el algoritmo Dijkstra." - -#~ msgid "" -#~ "``pgr_dijkstraCost`` - Total cost of the shortest path(s) using Dijkstra " -#~ "algorithm." -#~ msgstr "" -#~ "``pgr_dijkstraCost`` - Costo total de los caminos más cortos usando el " -#~ "algoritmo de Dijkstra." - -#~ msgid "" -#~ "The ``pgr_dijkstraCost`` function sumarizes of the cost of the shortest " -#~ "path(s) using Dijkstra Algorithm." -#~ msgstr "" -#~ "La función ``pgr_dijkstraCost`` function sumarizes el costo de los " -#~ "caminos más cortos usando el algoritmo de Dijkstra." - -#~ msgid "" -#~ "Find the route that visits the vertices :math:`\\{5, 1, 8\\}` in that " -#~ "order on an **directed** graph." -#~ msgstr "" -#~ "Encontrar la ruta que visita los vértices :math:`\\{ 5, 1, 8\\}` en ese " -#~ "orden, en un grafo dirigido." - -#~ msgid "Calculates the maximum flow from the `source(s)` to the `target(s)`." -#~ msgstr "Calcula el flujo máximo desde `source(s)` a `target(s)`." - -#~ msgid "" -#~ "Find the route that visits the vertices :math:`\\{ 5, 1, 8\\}` in that " -#~ "order on an directed graph." -#~ msgstr "" -#~ "Encontrar la ruta que visita los vértices :math:`\\{ 5, 1, 8\\}` en ese " -#~ "orden, en un grafo dirigido." - -#~ msgid "" -#~ "Modify the graph to include points defined by points_sql. Using Dijkstra " -#~ "algorithm, find the shortest path(s)" -#~ msgstr "" -#~ "Modificar el grafo para incluir puntos definidos por points_sql. Usando " -#~ "el algoritmo Dijkstra, busar la o las rutas más cortas" - -#~ msgid "" -#~ "``pgr_withPointsCost`` - Calculates the shortest path and returns only " -#~ "the aggregate cost of the shortest path(s) found, for the combination of " -#~ "points given." -#~ msgstr "" -#~ "``pgr_withPointsCost`` - Calcula la ruta más corta y devuelve solo el " -#~ "costo agregado de la(s) rutas más cortas encontradas, para la combinación " -#~ "de puntos dados." - -#~ msgid "" -#~ "Modify the graph to include points defined by points_sql. Using Dijkstra " -#~ "algorithm, return only the aggregate cost of the shortest path(s) found." -#~ msgstr "" -#~ "Modifica el grafo para incluir puntos definidos por points_sql. Con el " -#~ "algoritmo Dijkstra, devuelva solo el costo agregado de la(s) rutas más " -#~ "cortas encontradas." diff --git a/locale/ja/LC_MESSAGES/index.po b/locale/ja/LC_MESSAGES/index.po index 23de982c4f4..da2ba936963 100644 --- a/locale/ja/LC_MESSAGES/index.po +++ b/locale/ja/LC_MESSAGES/index.po @@ -1,11 +1,11 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # FIRST AUTHOR , 2022. # msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-06-25 12:55-0500\n" "PO-Revision-Date: 2024-05-01 03:45+0000\n" diff --git a/locale/ja/LC_MESSAGES/pgrouting_doc_strings.po b/locale/ja/LC_MESSAGES/pgrouting_doc_strings.po index 2483eefa9c7..6c7170aa075 100644 --- a/locale/ja/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/ja/LC_MESSAGES/pgrouting_doc_strings.po @@ -1,6 +1,5 @@ -# #-#-#-#-# allpairs-family.po (pgRouting v3.4.0-dev) #-#-#-#-# # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # FIRST AUTHOR , 2022. # Translators: @@ -19,9 +18,9 @@ # Celia Virginia Vergara Castillo , 2024. msgid "" msgstr "" -"Project-Id-Version: PROJECT VERSION 3.6.3\n" +"Project-Id-Version: PROJECT VERSION 3.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-10 03:40+0000\n" +"POT-Creation-Date: 2024-10-17 00:50+0000\n" "PO-Revision-Date: 2024-09-23 01:16+0000\n" "Last-Translator: Celia Virginia Vergara Castillo \n" "Language-Team: Japanese , YEAR. # msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-06-25 12:55-0500\n" "PO-Revision-Date: 2022-11-15 15:30+0000\n" diff --git a/locale/ko/LC_MESSAGES/pgrouting_doc_strings.po b/locale/ko/LC_MESSAGES/pgrouting_doc_strings.po index e782d1d807a..a09cc7227d2 100644 --- a/locale/ko/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/ko/LC_MESSAGES/pgrouting_doc_strings.po @@ -1,13 +1,13 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # Regina Obe , 2022. # Hyung-Gyu Ryoo , 2022. msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-10 03:40+0000\n" +"POT-Creation-Date: 2024-10-17 00:50+0000\n" "PO-Revision-Date: 2022-12-13 12:30+0000\n" "Last-Translator: Hyung-Gyu Ryoo \n" "Language-Team: Korean , YEAR. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-06-25 12:55-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" diff --git a/locale/pot/pgrouting_doc_strings.pot b/locale/pot/pgrouting_doc_strings.pot index 5dfcc5f82c2..c62a4180f2a 100644 --- a/locale/pot/pgrouting_doc_strings.pot +++ b/locale/pot/pgrouting_doc_strings.pot @@ -1,14 +1,14 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-10 03:40+0000\n" +"POT-Creation-Date: 2024-10-17 00:50+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -13267,6 +13267,9 @@ msgstr "" msgid "postgis 3.0.0" msgstr "" +msgid "g++ 13+ is supported" +msgstr "" + msgid "Code fixes" msgstr "" diff --git a/locale/zh_Hans/LC_MESSAGES/index.po b/locale/zh_Hans/LC_MESSAGES/index.po index d6ff27efd5c..d9ec1efa857 100644 --- a/locale/zh_Hans/LC_MESSAGES/index.po +++ b/locale/zh_Hans/LC_MESSAGES/index.po @@ -1,11 +1,11 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # FIRST AUTHOR , YEAR. # msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-06-25 12:55-0500\n" "PO-Revision-Date: 2024-09-23 14:18+0000\n" diff --git a/locale/zh_Hans/LC_MESSAGES/pgrouting_doc_strings.po b/locale/zh_Hans/LC_MESSAGES/pgrouting_doc_strings.po index 523c4bee570..dc7ee5c9236 100644 --- a/locale/zh_Hans/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/zh_Hans/LC_MESSAGES/pgrouting_doc_strings.po @@ -1,5 +1,5 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) pgRouting Contributors - Version v3.6.3 +# Copyright (C) pgRouting Contributors - Version v3.7.0 # This file is distributed under the same license as the pgRouting package. # Regina Obe , 2023. # Wangdapeng , 2023. @@ -9,9 +9,9 @@ # DeepL , 2024. msgid "" msgstr "" -"Project-Id-Version: pgRouting v3.6.3\n" +"Project-Id-Version: pgRouting v3.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-10 03:40+0000\n" +"POT-Creation-Date: 2024-10-17 00:50+0000\n" "PO-Revision-Date: 2024-10-10 19:47+0000\n" "Last-Translator: DeepL \n" "Language-Team: Chinese (Simplified) false ) ORDER BY vid; + +PREPARE idless5ud_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.8333333333333333), + (7 , 0), + (10 , 0.5), + (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless5ud_q'); + +RETURN QUERY +SELECT results_eq('idless5ud_q', 'idless5ud_r'); + +PREPARE idless4ud_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 4', directed => false ) ORDER BY vid; + +PREPARE idless4ud_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.6666666666666666), + (10 , 0.6666666666666666), (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless4ud_q'); + +RETURN QUERY +SELECT results_eq('idless4ud_q', 'idless4ud_r'); + + +PREPARE idless3ud_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 3', directed => false ) ORDER BY vid; + +PREPARE idless3ud_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 1), + (10 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless3ud_q'); + +RETURN QUERY +SELECT results_eq('idless3ud_q', 'idless3ud_r'); + +PREPARE idless2ud_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 2', directed => false + ) ORDER BY vid; + +PREPARE idless2ud_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless2ud_q'); + +RETURN QUERY +SELECT results_eq('idless2ud_q', 'idless2ud_r'); + +/* Explicit Directed Cases */ + + +PREPARE idless5d_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 5', directed => true ) ORDER BY vid; + +PREPARE idless5d_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.5), + (7 , 0), + (10 , 0.25), + (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless5d_q'); + +RETURN QUERY +SELECT results_eq('idless5d_q', 'idless5d_r'); + + +PREPARE idless4d_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 4', directed => true ) ORDER BY vid; + +PREPARE idless4d_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.3333333333333333), + (10 , 0.3333333333333333), + (15 , 0)) + AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless4d_q'); + +RETURN QUERY +SELECT results_eq('idless4d_q', 'idless4d_r'); + + +PREPARE idless3d_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 3', directed => true ) ORDER BY vid; + +PREPARE idless3d_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0.5), + (10 , 0) + ) AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless3d_q'); + +RETURN QUERY +SELECT results_eq('idless3d_q', 'idless3d_r'); + +PREPARE idless2d_q AS + SELECT * FROM pgr_betweennessCentrality( + 'SELECT id, source, target, cost, reverse_cost + FROM edges WHERE id < 2', directed => true + ) ORDER BY vid; + +PREPARE idless2d_r AS + SELECT * FROM (VALUES + (5::BIGINT , 0::FLOAT), + (6 , 0) + ) AS t(vid, centrality); + +RETURN QUERY +SELECT lives_ok('idless2d_q'); + +RETURN QUERY +SELECT results_eq('idless2d_q', 'idless2d_r'); + +END; +$BODY$ +LANGUAGE plpgsql; + +SELECT edge_cases(); + +SELECT finish(); +ROLLBACK; diff --git a/include/c_types/graph_enum.h b/pgtap/metrics/betweennessCentrality/inner_query.pg similarity index 62% rename from include/c_types/graph_enum.h rename to pgtap/metrics/betweennessCentrality/inner_query.pg index 9aeac09a139..9873cbb703a 100644 --- a/include/c_types/graph_enum.h +++ b/pgtap/metrics/betweennessCentrality/inner_query.pg @@ -1,36 +1,46 @@ + /*PGR-GNU***************************************************************** -File: pgr_types.h -Copyright (c) 2015 pgRouting developers +Copyright (c) 2024 pgRouting developers Mail: project@pgrouting.org -Copyright (c) 2015 Celia Virginia Vergara Castillo -Mail: vicky_vergara@hotmail.com - ------ - 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*/ -/*! @file */ +BEGIN; + +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN NOT min_version('3.7.0') THEN plan(1) ELSE plan(54) END; + +CREATE OR REPLACE FUNCTION inner_query() +RETURNS SETOF TEXT AS +$BODY$ +BEGIN + +IF NOT min_version('3.7.0') THEN + RETURN QUERY + SELECT skip(1, 'Function is new on 3.7.0'); + RETURN; +END IF; -#ifndef INCLUDE_C_TYPES_GRAPH_ENUM_H_ -#define INCLUDE_C_TYPES_GRAPH_ENUM_H_ -#pragma once +RETURN QUERY +SELECT style_dijkstra('pgr_betweennessCentrality(', ')'); -enum graphType {UNDIRECTED = 0, DIRECTED}; +END; +$BODY$ +LANGUAGE plpgsql; +SELECT inner_query(); -#endif // INCLUDE_C_TYPES_GRAPH_ENUM_H_ +SELECT finish(); +ROLLBACK; diff --git a/pgtap/metrics/betweennessCentrality/no_crash_test.pg b/pgtap/metrics/betweennessCentrality/no_crash_test.pg new file mode 100644 index 00000000000..c7b37ce9e70 --- /dev/null +++ b/pgtap/metrics/betweennessCentrality/no_crash_test.pg @@ -0,0 +1,72 @@ + +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN NOT min_version('3.7.0') THEN plan(1) ELSE plan(7) END; + +PREPARE edges_q AS +SELECT id, source, target, cost, reverse_cost FROM edges; + +PREPARE null_ret AS +SELECT id FROM vertices WHERE id IN (-1); + +PREPARE null_ret_arr AS +SELECT array_agg(id) FROM vertices WHERE id IN (-1); + + +CREATE OR REPLACE FUNCTION no_crash() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE +params TEXT[]; +subs TEXT[]; +BEGIN + IF NOT min_version('3.7.0') THEN + RETURN QUERY + SELECT skip(1, 'Function is new on 3.7.0'); + RETURN; + END IF; + + RETURN QUERY + SELECT isnt_empty('edges_q', 'Should be not empty to tests be meaningful'); + RETURN QUERY + SELECT is_empty('null_ret', 'Should be empty to tests be meaningful'); + RETURN QUERY + SELECT set_eq('null_ret_arr', 'SELECT NULL::BIGINT[]', 'Should be empty to tests be meaningful'); + + params = ARRAY[ + '$$SELECT id, source, target, cost, reverse_cost FROM edges$$' + ]::TEXT[]; + subs = ARRAY[ + 'NULL' + ]::TEXT[]; + + RETURN query SELECT * FROM no_crash_test('pgr_betweennessCentrality', params, subs); + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + + +SELECT * FROM no_crash(); + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/metrics/betweennessCentrality/types_check.pg b/pgtap/metrics/betweennessCentrality/types_check.pg new file mode 100644 index 00000000000..032556df946 --- /dev/null +++ b/pgtap/metrics/betweennessCentrality/types_check.pg @@ -0,0 +1,62 @@ + +/*PGR-GNU***************************************************************** + +Copyright (c) 2024 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +SELECT CASE WHEN NOT min_version('3.7.0') THEN plan(1) ELSE plan(5) END; + +CREATE OR REPLACE FUNCTION types_check() +RETURNS SETOF TEXT AS +$BODY$ +BEGIN + + IF NOT min_version('3.7.0') THEN + RETURN QUERY + SELECT skip(1, 'Function is new on 3.7.0'); + RETURN; + END IF; + +RETURN QUERY +SELECT has_function('pgr_betweennesscentrality'); +RETURN QUERY +SELECT has_function('pgr_betweennesscentrality', ARRAY['text','boolean']); +RETURN QUERY +SELECT function_returns('pgr_betweennesscentrality', ARRAY['text','boolean'],'setof record'); + +RETURN QUERY +SELECT set_eq( + $$SELECT proargnames from pg_proc where proname = 'pgr_betweennesscentrality'$$, + $$VALUES + ('{"","directed","vid","centrality"}'::TEXT[]) + $$); + +RETURN QUERY +SELECT set_eq( + $$SELECT proallargtypes from pg_proc where proname = 'pgr_betweennesscentrality'$$, + $$VALUES + ('{25,16,20,701}'::OID[]) + $$); + +END; +$BODY$ +LANGUAGE plpgsql; +SELECT types_check(); + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/planar/isPlanar/no_crash_test.pg b/pgtap/planar/isPlanar/no_crash_test.pg index d60050befdb..e5c144c3a9d 100644 --- a/pgtap/planar/isPlanar/no_crash_test.pg +++ b/pgtap/planar/isPlanar/no_crash_test.pg @@ -46,12 +46,9 @@ BEGIN 'NULL' ]::TEXT[]; - PERFORM todo_start('Fix these checks, for 3.2 onwards'); - RETURN QUERY SELECT * FROM no_crash_test('pgr_isplanar', params, subs); - PERFORM todo_end(); END $BODY$ LANGUAGE plpgsql VOLATILE; diff --git a/pgtap/spanningTree/kruskal/kruskalBFS/edge_cases.pg b/pgtap/spanningTree/kruskal/kruskalBFS/edge_cases.pg index f05993ddf58..e3e842aa238 100644 --- a/pgtap/spanningTree/kruskal/kruskalBFS/edge_cases.pg +++ b/pgtap/spanningTree/kruskal/kruskalBFS/edge_cases.pg @@ -25,7 +25,7 @@ UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(revers -- PREPARE kruskal1 AS -SELECT * FROM pgr_kruskalBFS( +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalBFS( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id > 18 ORDER BY id', 21, 3 @@ -37,7 +37,7 @@ SELECT set_eq('kruskal1', PREPARE kruskal2 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalBFS( 'SELECT id, source, target, cost FROM edges WHERE id > 18 ORDER BY id', @@ -55,7 +55,7 @@ SELECT set_eq('kruskal2', -- PREPARE kruskal3 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalBFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', @@ -123,12 +123,10 @@ FROM pgr_kruskalBFS( SELECT throws_ok('kruskal6', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''max_depth''', '6: Negative max_depth throws'); - - PREPARE kruskal7 AS SELECT * FROM pgr_kruskalBFS( @@ -138,13 +136,13 @@ FROM pgr_kruskalBFS( ); SELECT throws_ok('kruskal7', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''max_depth''', '7: Negative max_depth throws'); -- PREPARE kruskal8 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalBFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', diff --git a/pgtap/spanningTree/kruskal/kruskalDD/edge_cases.pg b/pgtap/spanningTree/kruskal/kruskalDD/edge_cases.pg index 4eab3962deb..ea3813fd5d2 100644 --- a/pgtap/spanningTree/kruskal/kruskalDD/edge_cases.pg +++ b/pgtap/spanningTree/kruskal/kruskalDD/edge_cases.pg @@ -25,7 +25,7 @@ UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(revers -- PREPARE kruskal1 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalDD( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id > 18 ORDER BY id', @@ -38,7 +38,7 @@ SELECT set_eq('kruskal1', PREPARE kruskal2 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalDD( 'SELECT id, source, target, cost FROM edges WHERE id > 18 ORDER BY id', @@ -56,7 +56,7 @@ SELECT set_eq('kruskal2', -- PREPARE kruskal3 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalDD( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', @@ -126,7 +126,7 @@ FROM pgr_kruskalDD( ); SELECT throws_ok('kruskal6', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''distance''', '6: Negative distance throws'); @@ -141,13 +141,13 @@ FROM pgr_kruskalDD( ); SELECT throws_ok('kruskal7', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''distance''', '7:Negative distance throws'); -- PREPARE kruskal8 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalDD( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', diff --git a/pgtap/spanningTree/kruskal/kruskalDFS/edge_cases.pg b/pgtap/spanningTree/kruskal/kruskalDFS/edge_cases.pg index 869d040d27e..bc9ea5b3670 100644 --- a/pgtap/spanningTree/kruskal/kruskalDFS/edge_cases.pg +++ b/pgtap/spanningTree/kruskal/kruskalDFS/edge_cases.pg @@ -25,7 +25,8 @@ UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(revers -- PREPARE kruskal1 AS -SELECT * FROM pgr_kruskalDFS( +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_kruskalDFS( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id > 18 ORDER BY id', 21, 3 @@ -37,7 +38,7 @@ SELECT set_eq('kruskal1', PREPARE kruskal2 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalDFS( 'SELECT id, source, target, cost FROM edges WHERE id > 18 ORDER BY id', @@ -55,7 +56,7 @@ SELECT set_eq('kruskal2', -- PREPARE kruskal3 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalDFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', @@ -126,12 +127,10 @@ FROM pgr_kruskalDFS( SELECT throws_ok('kruskal6', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''max_depth''', '6: Negative max_depth throws'); - - PREPARE kruskal7 AS SELECT * FROM pgr_kruskalDFS( @@ -141,13 +140,13 @@ FROM pgr_kruskalDFS( ); SELECT throws_ok('kruskal7', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''max_depth''', '7: Negative max_depth throws'); -- PREPARE kruskal8 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_kruskalDFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', diff --git a/pgtap/spanningTree/prim/primBFS/edge_cases.pg b/pgtap/spanningTree/prim/primBFS/edge_cases.pg index 31db46ffb69..5d2a8956edb 100644 --- a/pgtap/spanningTree/prim/primBFS/edge_cases.pg +++ b/pgtap/spanningTree/prim/primBFS/edge_cases.pg @@ -25,7 +25,8 @@ UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(revers -- PREPARE prim1 AS -SELECT * FROM pgr_primBFS( +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_primBFS( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id > 18 ORDER BY id', 21, 3 @@ -37,7 +38,7 @@ SELECT set_eq('prim1', PREPARE prim2 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primBFS( 'SELECT id, source, target, cost FROM edges WHERE id > 18 ORDER BY id', @@ -55,7 +56,7 @@ SELECT set_eq('prim2', -- PREPARE prim3 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primBFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', @@ -123,7 +124,7 @@ FROM pgr_primBFS( SELECT throws_ok('prim6', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''max_depth''', '6: Negative max_depth throws'); @@ -138,13 +139,13 @@ FROM pgr_primBFS( ); SELECT throws_ok('prim7', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''max_depth''', '7: Negative max_depth throws'); -- PREPARE prim8 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primBFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', @@ -215,7 +216,8 @@ SELECT set_eq('prim10', -- PREPARE prim11 AS -SELECT * FROM pgr_primBFS( +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_primBFS( 'SELECT id, source, target, cost, reverse_cost FROM edges', 18 ); @@ -234,7 +236,7 @@ SELECT is_empty('prim12', 'No cost can be negative'); -- PREPARE prim13 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primBFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ', 13 diff --git a/pgtap/spanningTree/prim/primDD/edge_cases.pg b/pgtap/spanningTree/prim/primDD/edge_cases.pg index 332a493c71f..e87e2b07cde 100644 --- a/pgtap/spanningTree/prim/primDD/edge_cases.pg +++ b/pgtap/spanningTree/prim/primDD/edge_cases.pg @@ -25,7 +25,7 @@ UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(revers -- PREPARE prim1 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primDD( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id > 18 ORDER BY id', @@ -38,7 +38,7 @@ SELECT set_eq('prim1', PREPARE prim2 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primDD( 'SELECT id, source, target, cost FROM edges WHERE id > 18 ORDER BY id', @@ -56,7 +56,7 @@ SELECT set_eq('prim2', -- PREPARE prim3 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primDD( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', @@ -126,7 +126,7 @@ FROM pgr_primDD( ); SELECT throws_ok('prim6', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''distance''', '6: Negative distance throws'); @@ -141,13 +141,13 @@ FROM pgr_primDD( ); SELECT throws_ok('prim7', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''distance''', '7:Negative distance throws'); -- PREPARE prim8 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primDD( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', diff --git a/pgtap/spanningTree/prim/primDFS/edge_cases.pg b/pgtap/spanningTree/prim/primDFS/edge_cases.pg index 2ef97f24e62..029d932f4ff 100644 --- a/pgtap/spanningTree/prim/primDFS/edge_cases.pg +++ b/pgtap/spanningTree/prim/primDFS/edge_cases.pg @@ -25,7 +25,8 @@ UPDATE edges SET cost = sign(cost) + 0.001 * id * id, reverse_cost = sign(revers -- PREPARE prim1 AS -SELECT * FROM pgr_primDFS( +SELECT seq, depth, start_vid, node, edge, cost, agg_cost +FROM pgr_primDFS( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id > 18 ORDER BY id', 21, 3 @@ -37,7 +38,7 @@ SELECT set_eq('prim1', PREPARE prim2 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primDFS( 'SELECT id, source, target, cost FROM edges WHERE id > 18 ORDER BY id', @@ -55,7 +56,7 @@ SELECT set_eq('prim2', -- PREPARE prim3 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primDFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', @@ -126,12 +127,10 @@ FROM pgr_primDFS( SELECT throws_ok('prim6', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''max_depth''', '6: Negative max_depth throws'); - - PREPARE prim7 AS SELECT * FROM pgr_primDFS( @@ -141,13 +140,13 @@ FROM pgr_primDFS( ); SELECT throws_ok('prim7', - 'P0001', + CASE WHEN min_version('3.7.0') THEN 'XX000' ELSE 'P0001' END, 'Negative value found on ''max_depth''', '7: Negative max_depth throws'); -- PREPARE prim8 AS -SELECT * +SELECT seq, depth, start_vid, node, edge, cost, agg_cost FROM pgr_primDFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', diff --git a/pgtap/traversal/breadthFirstSearch/edge_cases.pg b/pgtap/traversal/breadthFirstSearch/edge_cases.pg index d34fc7da853..6add18c2528 100644 --- a/pgtap/traversal/breadthFirstSearch/edge_cases.pg +++ b/pgtap/traversal/breadthFirstSearch/edge_cases.pg @@ -55,7 +55,7 @@ SELECT is_empty(' SELECT * from pgr_breadthFirstSearch(''SELECT id, source, target, cost, reverse_cost from edges where id>18 '',array[2,5], 2, directed := false)', '13'); --- vertex not present in graph tests +-- vertex not present in graph tests -- directed graph SELECT is_empty(' @@ -85,7 +85,7 @@ SELECT * from pgr_breadthFirstSearch(''SELECT id, source, target, cost, reverse_ SELECT is_empty(' SELECT * from pgr_breadthFirstSearch(''SELECT id, source, target, cost, reverse_cost from edges'',array[20,-10], 2, directed := false)', '25'); --- negative depth tests +-- negative depth tests PREPARE breadthFirstSearch26 AS SELECT * @@ -141,8 +141,8 @@ FROM pgr_breadthFirstSearch( SELECT throws_ok('breadthFirstSearch29', 'P0001', 'Negative value found on ''max_depth''', - '29: Negative max_depth throws'); + '29: Negative max_depth throws'); SELECT * FROM finish(); -ROLLBACK; +ROLLBACK; diff --git a/sql/chinese/CMakeLists.txt b/sql/chinese/CMakeLists.txt index bbe1e78d19b..242a069dfd3 100644 --- a/sql/chinese/CMakeLists.txt +++ b/sql/chinese/CMakeLists.txt @@ -1,8 +1,8 @@ SET(LOCAL_FILES _pgr_chinesePostman.sql - pgr_chinesePostman.sql - pgr_chinesePostmanCost.sql) + chinesePostman.sql + chinesePostmanCost.sql) foreach (f ${LOCAL_FILES}) configure_file(${f} ${f}) diff --git a/sql/chinese/pgr_chinesePostman.sql b/sql/chinese/chinesePostman.sql similarity index 100% rename from sql/chinese/pgr_chinesePostman.sql rename to sql/chinese/chinesePostman.sql diff --git a/sql/chinese/pgr_chinesePostmanCost.sql b/sql/chinese/chinesePostmanCost.sql similarity index 100% rename from sql/chinese/pgr_chinesePostmanCost.sql rename to sql/chinese/chinesePostmanCost.sql diff --git a/sql/common/CMakeLists.txt b/sql/common/CMakeLists.txt index 5678072f130..ede4090c6d6 100644 --- a/sql/common/CMakeLists.txt +++ b/sql/common/CMakeLists.txt @@ -5,7 +5,7 @@ SET(LOCAL_FILES _startPoint.sql _endPoint.sql pgrouting_utilities.sql - pgr_parameter_check.sql + parameter_check.sql utilities_pgr.sql createIndex.sql _checkquery.sql diff --git a/sql/common/pgr_parameter_check.sql b/sql/common/parameter_check.sql similarity index 100% rename from sql/common/pgr_parameter_check.sql rename to sql/common/parameter_check.sql diff --git a/sql/legacy/tsp/_makeDistanceMatrix.sql b/sql/legacy/tsp/_makeDistanceMatrix.sql index e810b182943..07da120eb9b 100644 --- a/sql/legacy/tsp/_makeDistanceMatrix.sql +++ b/sql/legacy/tsp/_makeDistanceMatrix.sql @@ -39,7 +39,7 @@ THE SOFTWARE. create or replace function _pgr_makeDistanceMatrix - (sqlin text, + (sqlin text, OUT dmatrix double precision[], OUT ids integer[]) diff --git a/sql/legacy/tsp/tsp_v2.0_coordinates.sql b/sql/legacy/tsp/tsp_v2.0_coordinates.sql index 35ff0a8cf9e..7e2837746fa 100644 --- a/sql/legacy/tsp/tsp_v2.0_coordinates.sql +++ b/sql/legacy/tsp/tsp_v2.0_coordinates.sql @@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. CREATE OR REPLACE FUNCTION pgr_tsp( - sql text, + sql text, start_id INTEGER, end_id INTEGER default (-1), diff --git a/sql/legacy/tsp/tsp_v2.0_matrix.sql b/sql/legacy/tsp/tsp_v2.0_matrix.sql index c11ded449df..b24d988a4c5 100644 --- a/sql/legacy/tsp/tsp_v2.0_matrix.sql +++ b/sql/legacy/tsp/tsp_v2.0_matrix.sql @@ -83,7 +83,7 @@ debuglevel TEXT; BEGIN RAISE NOTICE 'Deprecated Signature pgr_tsp(float8[][], integer, integer)'; - CREATE TEMP TABLE ___tmp2 ON COMMIT DROP AS + CREATE TEMP TABLE ___tmp2 ON COMMIT DROP AS SELECT start_vid, end_vid, agg_cost FROM _pgr_unnest_matrix( matrix ); diff --git a/sql/metrics/CMakeLists.txt b/sql/metrics/CMakeLists.txt new file mode 100644 index 00000000000..c047b395e5a --- /dev/null +++ b/sql/metrics/CMakeLists.txt @@ -0,0 +1,12 @@ + +SET(LOCAL_FILES + _betweennessCentrality.sql + betweennessCentrality.sql +) + +foreach (f ${LOCAL_FILES}) + configure_file(${f} ${f}) + list(APPEND PACKAGE_SQL_FILES ${CMAKE_CURRENT_BINARY_DIR}/${f}) +endforeach() + +set(PROJECT_SQL_FILES ${PROJECT_SQL_FILES} ${PACKAGE_SQL_FILES} PARENT_SCOPE) diff --git a/sql/metrics/_betweennessCentrality.sql b/sql/metrics/_betweennessCentrality.sql new file mode 100644 index 00000000000..4a8b7479c2b --- /dev/null +++ b/sql/metrics/_betweennessCentrality.sql @@ -0,0 +1,49 @@ +/*PGR-GNU***************************************************************** + +File: _betweennessCentrality.sql + +Template: +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Function developer: +Copyright (c) 2024 Arun Thakur +Mail: bedupako12mas at gmail.com + +------ + +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*/ + +-------------------------------- +-- pgr_betweennessCentrality +-------------------------------- + +--v3.7 +CREATE FUNCTION _pgr_betweennessCentrality( + edges_sql TEXT, + directed BOOLEAN, + + OUT vid BIGINT, + OUT centrality FLOAT) +RETURNS SETOF RECORD AS +'MODULE_PATHNAME' +LANGUAGE C VOLATILE STRICT; + +-- COMMENTS + +COMMENT ON FUNCTION _pgr_betweennessCentrality(TEXT, BOOLEAN) +IS 'pgRouting internal function'; diff --git a/sql/metrics/betweennessCentrality.sql b/sql/metrics/betweennessCentrality.sql new file mode 100644 index 00000000000..8da8d6916a4 --- /dev/null +++ b/sql/metrics/betweennessCentrality.sql @@ -0,0 +1,57 @@ +/*PGR-GNU***************************************************************** + +File: betweennessCentrality.sql + +Template: +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Function developer: +Copyright (c) 2024 Arun Thakur +Mail: bedupako12mas at gmail.com + +------ + +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.7 +CREATE FUNCTION pgr_betweennessCentrality( + TEXT, -- edges_sql (required) + directed BOOLEAN DEFAULT true, + + OUT vid BIGINT, + OUT centrality FLOAT) +RETURNS SETOF RECORD AS +$BODY$ + + SELECT vid, centrality + FROM _pgr_betweennesscentrality(_pgr_get_statement($1), $2); + +$BODY$ +LANGUAGE SQL VOLATILE STRICT; + +-- COMMENTS + +COMMENT ON FUNCTION pgr_betweennessCentrality(TEXT, BOOLEAN) +IS 'pgr_betweennessCentrality +- Parameters: + - edges SQL with columns: source, target, cost [,reverse_cost]) +- Optional Parameters: + - directed := true +- Documentation: + - ${PROJECT_DOC_LINK}/pgr_centrality.html +'; diff --git a/sql/scripts/build-extension-update-files.pl b/sql/scripts/build-extension-update-files.pl index 80071fa0707..8fa53588527 100755 --- a/sql/scripts/build-extension-update-files.pl +++ b/sql/scripts/build-extension-update-files.pl @@ -63,6 +63,7 @@ my $version_3_4 = qr/(3.4.[\d+])/; my $version_3_5 = qr/(3.5.[\d+])/; my $version_3_6 = qr/(3.6.[\d+])/; +my $version_3_7 = qr/(3.7.[\d+])/; # add minor here my $version_2 = qr/(2.[\d+].[\d+])/; @@ -72,7 +73,7 @@ my $mayor_format = qr/([\d+]).[\d+].[\d+]/; -my $current = $version_3_6; +my $current = $version_3_7; sub Usage { @@ -220,19 +221,19 @@ sub generate_upgrade_script { } # updating to 3.4+ - if ($old_mayor == 2 or $old_minor < 4) { + if ($old_mayor == 2 or ($old_mayor == 3 and $old_minor < 4)) { push @commands, drop_special_case_function("pgr_maxcardinalitymatch(text,boolean)"); } # updating to 3.5+ - if ($old_mayor == 2 or $old_minor < 5) { + if ($old_mayor == 2 or ($old_mayor == 3 && $old_minor < 5)) { push @commands, drop_special_case_function("pgr_dijkstra(text,anyarray,bigint,boolean)"); push @commands, drop_special_case_function("pgr_dijkstra(text,bigint,anyarray,boolean)"); push @commands, drop_special_case_function("pgr_dijkstra(text,bigint,bigint,boolean)"); } # updating to 3.6+ - if ($old_mayor == 2 or $old_minor < 6) { + if ($old_mayor == 2 or ($old_mayor == 3 && $old_minor < 6)) { push @commands, drop_special_case_function("pgr_withpointsksp(text, text, bigint, bigint, integer, boolean, boolean, char, boolean)"); push @commands, drop_special_case_function("pgr_astar(text,anyarray,bigint,boolean,integer,double precision,double precision)"); push @commands, drop_special_case_function("pgr_astar(text,bigint,anyarray,boolean,integer,double precision,double precision)"); @@ -247,6 +248,26 @@ sub generate_upgrade_script { push @commands, drop_special_case_function("pgr_drivingdistance(text,bigint,double precision,boolean)"); } + # updating to 3.7+ + if ($old_mayor == 2 or ($old_mayor == 3 && $old_minor < 7)) { + push @commands, drop_special_case_function("pgr_primbfs(text,anyarray,bigint)"); + push @commands, drop_special_case_function("pgr_primbfs(text,bigint,bigint)"); + push @commands, drop_special_case_function("pgr_primdfs(text,anyarray,bigint)"); + push @commands, drop_special_case_function("pgr_primdfs(text,bigint,bigint)"); + push @commands, drop_special_case_function("pgr_primdd(text,bigint,numeric)"); + push @commands, drop_special_case_function("pgr_primdd(text,bigint,double precision)"); + push @commands, drop_special_case_function("pgr_primdd(text,anyarray,numeric)"); + push @commands, drop_special_case_function("pgr_primdd(text,anyarray,double precision)"); + push @commands, drop_special_case_function("pgr_kruskalbfs(text,anyarray,bigint)"); + push @commands, drop_special_case_function("pgr_kruskalbfs(text,bigint,bigint)"); + push @commands, drop_special_case_function("pgr_kruskaldfs(text,anyarray,bigint)"); + push @commands, drop_special_case_function("pgr_kruskaldfs(text,bigint,bigint)"); + push @commands, drop_special_case_function("pgr_kruskaldd(text,bigint,numeric)"); + push @commands, drop_special_case_function("pgr_kruskaldd(text,bigint,double precision)"); + push @commands, drop_special_case_function("pgr_kruskaldd(text,anyarray,numeric)"); + push @commands, drop_special_case_function("pgr_kruskaldd(text,anyarray,double precision)"); + } + } #------------------------------------ diff --git a/sql/sigs/pgrouting--3.7.sig b/sql/sigs/pgrouting--3.7.sig new file mode 100644 index 00000000000..460e9e69d68 --- /dev/null +++ b/sql/sigs/pgrouting--3.7.sig @@ -0,0 +1,344 @@ +pgr_alphashape(geometry,double precision) +_pgr_alphashape(text,double precision) +pgr_analyzegraph(text,double precision,text,text,text,text,text) +pgr_analyzeoneway(text,text[],text[],text[],text[],boolean,text,text,text) +_pgr_array_reverse(anyarray) +_pgr_articulationpoints(text) +pgr_articulationpoints(text) +pgr_astarcostmatrix(text,anyarray,boolean,integer,double precision,double precision) +pgr_astarcost(text,anyarray,anyarray,boolean,integer,double precision,double precision) +pgr_astarcost(text,anyarray,bigint,boolean,integer,double precision,double precision) +pgr_astarcost(text,bigint,anyarray,boolean,integer,double precision,double precision) +pgr_astarcost(text,bigint,bigint,boolean,integer,double precision,double precision) +pgr_astarcost(text,text,boolean,integer,double precision,double precision) +pgr_astar(text,anyarray,anyarray,boolean,integer,double precision,double precision) +_pgr_astar(text,anyarray,anyarray,boolean,integer,double precision,double precision,boolean,boolean) +pgr_astar(text,anyarray,bigint,boolean,integer,double precision,double precision) +pgr_astar(text,bigint,anyarray,boolean,integer,double precision,double precision) +pgr_astar(text,bigint,bigint,boolean,integer,double precision,double precision) +pgr_astar(text,text,boolean,integer,double precision,double precision) +_pgr_astar(text,text,boolean,integer,double precision,double precision,boolean) +pgr_bdastarcostmatrix(text,anyarray,boolean,integer,numeric,numeric) +pgr_bdastarcost(text,anyarray,anyarray,boolean,integer,numeric,numeric) +pgr_bdastarcost(text,anyarray,bigint,boolean,integer,numeric,numeric) +pgr_bdastarcost(text,bigint,anyarray,boolean,integer,numeric,numeric) +pgr_bdastarcost(text,bigint,bigint,boolean,integer,numeric,numeric) +pgr_bdastarcost(text,text,boolean,integer,numeric,numeric) +_pgr_bdastar(text,anyarray,anyarray,boolean,integer,double precision,double precision,boolean) +pgr_bdastar(text,anyarray,anyarray,boolean,integer,numeric,numeric) +pgr_bdastar(text,anyarray,bigint,boolean,integer,numeric,numeric) +pgr_bdastar(text,bigint,anyarray,boolean,integer,numeric,numeric) +pgr_bdastar(text,bigint,bigint,boolean,integer,numeric,numeric) +_pgr_bdastar(text,text,boolean,integer,double precision,double precision,boolean) +pgr_bdastar(text,text,boolean,integer,numeric,numeric) +pgr_bddijkstracostmatrix(text,anyarray,boolean) +pgr_bddijkstracost(text,anyarray,anyarray,boolean) +pgr_bddijkstracost(text,anyarray,bigint,boolean) +pgr_bddijkstracost(text,bigint,anyarray,boolean) +pgr_bddijkstracost(text,bigint,bigint,boolean) +pgr_bddijkstracost(text,text,boolean) +pgr_bddijkstra(text,anyarray,anyarray,boolean) +_pgr_bddijkstra(text,anyarray,anyarray,boolean,boolean) +pgr_bddijkstra(text,anyarray,bigint,boolean) +pgr_bddijkstra(text,bigint,anyarray,boolean) +pgr_bddijkstra(text,bigint,bigint,boolean) +pgr_bddijkstra(text,text,boolean) +_pgr_bddijkstra(text,text,boolean,boolean) +pgr_bellmanford(text,anyarray,anyarray,boolean) +_pgr_bellmanford(text,anyarray,anyarray,boolean,boolean) +pgr_bellmanford(text,anyarray,bigint,boolean) +pgr_bellmanford(text,bigint,anyarray,boolean) +pgr_bellmanford(text,bigint,bigint,boolean) +pgr_bellmanford(text,text,boolean) +_pgr_bellmanford(text,text,boolean,boolean) +_pgr_betweennesscentrality(text,boolean) +pgr_betweennesscentrality(text,boolean) +_pgr_biconnectedcomponents(text) +pgr_biconnectedcomponents(text) +_pgr_binarybreadthfirstsearch(text,anyarray,anyarray,boolean) +pgr_binarybreadthfirstsearch(text,anyarray,anyarray,boolean) +pgr_binarybreadthfirstsearch(text,anyarray,bigint,boolean) +pgr_binarybreadthfirstsearch(text,bigint,anyarray,boolean) +pgr_binarybreadthfirstsearch(text,bigint,bigint,boolean) +_pgr_binarybreadthfirstsearch(text,text,boolean) +pgr_binarybreadthfirstsearch(text,text,boolean) +_pgr_bipartite(text) +pgr_bipartite(text) +_pgr_boost_version() +pgr_boykovkolmogorov(text,anyarray,anyarray) +pgr_boykovkolmogorov(text,anyarray,bigint) +pgr_boykovkolmogorov(text,bigint,anyarray) +pgr_boykovkolmogorov(text,bigint,bigint) +pgr_boykovkolmogorov(text,text) +_pgr_breadthfirstsearch(text,anyarray,bigint,boolean) +pgr_breadthfirstsearch(text,anyarray,bigint,boolean) +pgr_breadthfirstsearch(text,bigint,bigint,boolean) +_pgr_bridges(text) +pgr_bridges(text) +_pgr_build_type() +_pgr_checkcolumn(text,text,text,boolean,boolean) +_pgr_checkquery(text) +_pgr_checkverttab(text,text[],integer,text) +pgr_chinesepostmancost(text) +pgr_chinesepostman(text) +_pgr_chinesepostman(text,boolean) +_pgr_compilation_date() +_pgr_compiler_version() +_pgr_connectedcomponents(text) +pgr_connectedcomponents(text) +_pgr_contraction(text,bigint[],integer,bigint[],boolean) +pgr_contraction(text,bigint[],integer,bigint[],boolean) +_pgr_createindex(text,text,text,integer,text) +_pgr_createindex(text,text,text,text,integer,text) +pgr_createtopology(text,double precision,text,text,text,text,text,boolean) +pgr_createverticestable(text,text,text,text,text) +_pgr_cuthillmckeeordering(text) +pgr_cuthillmckeeordering(text) +pgr_dagshortestpath(text,anyarray,anyarray) +_pgr_dagshortestpath(text,anyarray,anyarray,boolean,boolean) +pgr_dagshortestpath(text,anyarray,bigint) +pgr_dagshortestpath(text,bigint,anyarray) +pgr_dagshortestpath(text,bigint,bigint) +pgr_dagshortestpath(text,text) +_pgr_dagshortestpath(text,text,boolean,boolean) +pgr_degree(text,text,boolean) +_pgr_depthfirstsearch(text,anyarray,boolean,bigint) +pgr_depthfirstsearch(text,anyarray,boolean,bigint) +pgr_depthfirstsearch(text,bigint,boolean,bigint) +pgr_dijkstracostmatrix(text,anyarray,boolean) +pgr_dijkstracost(text,anyarray,anyarray,boolean) +pgr_dijkstracost(text,anyarray,bigint,boolean) +pgr_dijkstracost(text,bigint,anyarray,boolean) +pgr_dijkstracost(text,bigint,bigint,boolean) +pgr_dijkstracost(text,text,boolean) +pgr_dijkstranearcost(text,anyarray,anyarray,boolean,bigint,boolean) +pgr_dijkstranearcost(text,anyarray,bigint,boolean,bigint) +pgr_dijkstranearcost(text,bigint,anyarray,boolean,bigint) +pgr_dijkstranearcost(text,text,boolean,bigint,boolean) +_pgr_dijkstranear(text,anyarray,anyarray,bigint,boolean) +pgr_dijkstranear(text,anyarray,anyarray,boolean,bigint,boolean) +_pgr_dijkstranear(text,anyarray,bigint,bigint,boolean) +pgr_dijkstranear(text,anyarray,bigint,boolean,bigint) +_pgr_dijkstranear(text,bigint,anyarray,bigint,boolean) +pgr_dijkstranear(text,bigint,anyarray,boolean,bigint) +pgr_dijkstranear(text,text,boolean,bigint,boolean) +pgr_dijkstra(text,anyarray,anyarray,boolean) +_pgr_dijkstra(text,anyarray,anyarray,boolean,boolean,boolean,bigint) +_pgr_dijkstra(text,anyarray,anyarray,boolean,boolean,boolean,bigint,boolean) +pgr_dijkstra(text,anyarray,bigint,boolean) +pgr_dijkstra(text,bigint,anyarray,boolean) +pgr_dijkstra(text,bigint,bigint,boolean) +pgr_dijkstra(text,text,boolean) +_pgr_dijkstra(text,text,boolean,boolean,bigint,boolean) +_pgr_dijkstra(text,text,boolean,boolean,boolean) +_pgr_dijkstravia(text,anyarray,boolean,boolean,boolean) +pgr_dijkstravia(text,anyarray,boolean,boolean,boolean) +_pgr_drivingdistance(text,anyarray,double precision,boolean,boolean) +pgr_drivingdistance(text,anyarray,double precision,boolean,boolean) +pgr_drivingdistance(text,bigint,double precision,boolean) +_pgr_drivingdistancev4(text,anyarray,double precision,boolean,boolean) +_pgr_edgecoloring(text) +pgr_edgecoloring(text) +_pgr_edgedisjointpaths(text,anyarray,anyarray,boolean) +pgr_edgedisjointpaths(text,anyarray,anyarray,boolean) +pgr_edgedisjointpaths(text,anyarray,bigint,boolean) +pgr_edgedisjointpaths(text,bigint,anyarray,boolean) +pgr_edgedisjointpaths(text,bigint,bigint,boolean) +_pgr_edgedisjointpaths(text,text,boolean) +pgr_edgedisjointpaths(text,text,boolean) +pgr_edmondskarp(text,anyarray,anyarray) +pgr_edmondskarp(text,anyarray,bigint) +pgr_edmondskarp(text,bigint,anyarray) +pgr_edmondskarp(text,bigint,bigint) +pgr_edmondskarp(text,text) +_pgr_edwardmoore(text,anyarray,anyarray,boolean) +pgr_edwardmoore(text,anyarray,anyarray,boolean) +pgr_edwardmoore(text,anyarray,bigint,boolean) +pgr_edwardmoore(text,bigint,anyarray,boolean) +pgr_edwardmoore(text,bigint,bigint,boolean) +_pgr_edwardmoore(text,text,boolean) +pgr_edwardmoore(text,text,boolean) +_pgr_endpoint(geometry) +pgr_extractvertices(text,boolean) +pgr_findcloseedges(text,geometry,double precision,integer,boolean,boolean) +pgr_findcloseedges(text,geometry[],double precision,integer,boolean,boolean) +_pgr_floydwarshall(text,boolean) +pgr_floydwarshall(text,boolean) +pgr_full_version() +_pgr_getcolumnname(text,text,integer,text) +_pgr_getcolumnname(text,text,text,integer,text) +_pgr_getcolumntype(text,text,integer,text) +_pgr_getcolumntype(text,text,text,integer,text) +_pgr_get_statement(text) +_pgr_gettablename(text,integer,text) +_pgr_git_hash() +_pgr_hawickcircuits(text) +pgr_hawickcircuits(text) +_pgr_iscolumnindexed(text,text,integer,text) +_pgr_iscolumnindexed(text,text,text,integer,text) +_pgr_iscolumnintable(text,text) +_pgr_isplanar(text) +pgr_isplanar(text) +_pgr_johnson(text,boolean) +pgr_johnson(text,boolean) +pgr_kruskalbfs(text,anyarray,bigint) +pgr_kruskalbfs(text,bigint,bigint) +pgr_kruskaldd(text,anyarray,double precision) +pgr_kruskaldd(text,anyarray,numeric) +pgr_kruskaldd(text,bigint,double precision) +pgr_kruskaldd(text,bigint,numeric) +pgr_kruskaldfs(text,anyarray,bigint) +pgr_kruskaldfs(text,bigint,bigint) +pgr_kruskal(text) +_pgr_kruskal(text,anyarray,text,bigint,double precision) +_pgr_kruskalv4(text,anyarray,text,bigint,double precision) +pgr_ksp(text,anyarray,anyarray,integer,boolean,boolean) +_pgr_ksp(text,anyarray,anyarray,integer,boolean,boolean,boolean) +pgr_ksp(text,anyarray,bigint,integer,boolean,boolean) +pgr_ksp(text,bigint,anyarray,integer,boolean,boolean) +_pgr_ksp(text,bigint,bigint,integer,boolean,boolean) +pgr_ksp(text,bigint,bigint,integer,boolean,boolean) +_pgr_ksp(text,text,integer,boolean,boolean) +pgr_ksp(text,text,integer,boolean,boolean) +_pgr_lengauertarjandominatortree(text,bigint) +pgr_lengauertarjandominatortree(text,bigint) +_pgr_lib_version() +_pgr_linegraphfull(text) +pgr_linegraphfull(text) +_pgr_linegraph(text,boolean) +pgr_linegraph(text,boolean) +_pgr_makeconnected(text) +pgr_makeconnected(text) +pgr_maxcardinalitymatch(text) +_pgr_maxcardinalitymatch(text,boolean) +pgr_maxcardinalitymatch(text,boolean) +pgr_maxflowmincost_cost(text,anyarray,anyarray) +pgr_maxflowmincost_cost(text,anyarray,bigint) +pgr_maxflowmincost_cost(text,bigint,anyarray) +pgr_maxflowmincost_cost(text,bigint,bigint) +pgr_maxflowmincost_cost(text,text) +pgr_maxflowmincost(text,anyarray,anyarray) +_pgr_maxflowmincost(text,anyarray,anyarray,boolean) +pgr_maxflowmincost(text,anyarray,bigint) +pgr_maxflowmincost(text,bigint,anyarray) +pgr_maxflowmincost(text,bigint,bigint) +pgr_maxflowmincost(text,text) +_pgr_maxflowmincost(text,text,boolean) +pgr_maxflow(text,anyarray,anyarray) +_pgr_maxflow(text,anyarray,anyarray,integer,boolean) +pgr_maxflow(text,anyarray,bigint) +pgr_maxflow(text,bigint,anyarray) +pgr_maxflow(text,bigint,bigint) +pgr_maxflow(text,text) +_pgr_maxflow(text,text,integer,boolean) +_pgr_msg(integer,text,text) +pgr_nodenetwork(text,double precision,text,text,text,text,boolean) +_pgr_onerror(boolean,integer,text,text,text,text) +_pgr_operating_system() +_pgr_parameter_check(text,text,boolean) +_pgr_pgsql_version() +_pgr_pickdelivereuclidean(text,text,double precision,integer,integer) +pgr_pickdelivereuclidean(text,text,double precision,integer,integer) +_pgr_pickdeliver(text,text,text,double precision,integer,integer) +pgr_pickdeliver(text,text,text,double precision,integer,integer) +_pgr_pointtoid(geometry,double precision,text,integer) +pgr_primbfs(text,anyarray,bigint) +pgr_primbfs(text,bigint,bigint) +pgr_primdd(text,anyarray,double precision) +pgr_primdd(text,anyarray,numeric) +pgr_primdd(text,bigint,double precision) +pgr_primdd(text,bigint,numeric) +pgr_primdfs(text,anyarray,bigint) +pgr_primdfs(text,bigint,bigint) +pgr_prim(text) +_pgr_prim(text,anyarray,text,bigint,double precision) +_pgr_primv4(text,anyarray,text,bigint,double precision) +pgr_pushrelabel(text,anyarray,anyarray) +pgr_pushrelabel(text,anyarray,bigint) +pgr_pushrelabel(text,bigint,anyarray) +pgr_pushrelabel(text,bigint,bigint) +pgr_pushrelabel(text,text) +_pgr_quote_ident(text) +_pgr_sequentialvertexcoloring(text) +pgr_sequentialvertexcoloring(text) +_pgr_startpoint(geometry) +_pgr_stoerwagner(text) +pgr_stoerwagner(text) +_pgr_strongcomponents(text) +pgr_strongcomponents(text) +_pgr_topologicalsort(text) +pgr_topologicalsort(text) +_pgr_transitiveclosure(text) +pgr_transitiveclosure(text) +_pgr_trsp(text,integer,double precision,integer,double precision,boolean,boolean,text) +pgr_trsp(text,integer,double precision,integer,double precision,boolean,boolean,text) +pgr_trsp(text,integer,integer,boolean,boolean,text) +_pgr_trsp(text,text,anyarray,anyarray,boolean) +pgr_trsp(text,text,anyarray,anyarray,boolean) +_pgr_trsp(text,text,anyarray,bigint,boolean) +pgr_trsp(text,text,anyarray,bigint,boolean) +_pgr_trsp(text,text,bigint,anyarray,boolean) +pgr_trsp(text,text,bigint,anyarray,boolean) +_pgr_trsp(text,text,bigint,bigint,boolean) +pgr_trsp(text,text,bigint,bigint,boolean) +pgr_trsp(text,text,text,boolean) +_pgr_trspv4(text,text,anyarray,anyarray,boolean) +_pgr_trspv4(text,text,text,boolean) +pgr_trspviaedges(text,integer[],double precision[],boolean,boolean,text) +_pgr_trspvia(text,text,anyarray,boolean,boolean,boolean) +pgr_trspvia(text,text,anyarray,boolean,boolean,boolean) +pgr_trspviavertices(text,anyarray,boolean,boolean,text) +_pgr_trspviavertices(text,integer[],boolean,boolean,text) +_pgr_trspvia_withpoints(text,text,text,anyarray,boolean,boolean,boolean,character,boolean) +pgr_trspvia_withpoints(text,text,text,anyarray,boolean,boolean,boolean,character,boolean) +_pgr_trsp_withpoints(text,text,text,anyarray,anyarray,boolean,character,boolean) +pgr_trsp_withpoints(text,text,text,anyarray,anyarray,boolean,character,boolean) +pgr_trsp_withpoints(text,text,text,anyarray,bigint,boolean,character,boolean) +pgr_trsp_withpoints(text,text,text,bigint,anyarray,boolean,character,boolean) +pgr_trsp_withpoints(text,text,text,bigint,bigint,boolean,character,boolean) +_pgr_trsp_withpoints(text,text,text,text,boolean,character,boolean) +pgr_trsp_withpoints(text,text,text,text,boolean,character,boolean) +_pgr_tspeuclidean(text,bigint,bigint,double precision,integer,integer,integer,double precision,double precision,double precision,boolean) +pgr_tspeuclidean(text,bigint,bigint,double precision,integer,integer,integer,double precision,double precision,double precision,boolean) +_pgr_tsp(text,bigint,bigint,double precision,integer,integer,integer,double precision,double precision,double precision,boolean) +pgr_tsp(text,bigint,bigint,double precision,integer,integer,integer,double precision,double precision,double precision,boolean) +_pgr_turnrestrictedpath(text,text,bigint,bigint,integer,boolean,boolean,boolean,boolean) +pgr_turnrestrictedpath(text,text,bigint,bigint,integer,boolean,boolean,boolean,boolean) +pgr_version() +_pgr_versionless(text,text) +_pgr_vrponedepot(text,text,text,integer) +pgr_vrponedepot(text,text,text,integer) +pgr_withpointscostmatrix(text,text,anyarray,boolean,character) +pgr_withpointscost(text,text,anyarray,anyarray,boolean,character) +pgr_withpointscost(text,text,anyarray,bigint,boolean,character) +pgr_withpointscost(text,text,bigint,anyarray,boolean,character) +pgr_withpointscost(text,text,bigint,bigint,boolean,character) +pgr_withpointscost(text,text,text,boolean,character) +_pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean) +pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean) +pgr_withpointsdd(text,text,anyarray,double precision,character,boolean,boolean,boolean) +pgr_withpointsdd(text,text,bigint,double precision,boolean,character,boolean) +pgr_withpointsdd(text,text,bigint,double precision,character,boolean,boolean) +_pgr_withpointsddv4(text,text,anyarray,double precision,character,boolean,boolean,boolean) +pgr_withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean) +_pgr_withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean,boolean) +pgr_withpointsksp(text,text,anyarray,bigint,integer,character,boolean,boolean,boolean) +pgr_withpointsksp(text,text,bigint,anyarray,integer,character,boolean,boolean,boolean) +_pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean) +pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean) +pgr_withpointsksp(text,text,bigint,bigint,integer,character,boolean,boolean,boolean) +_pgr_withpointsksp(text,text,text,integer,character,boolean,boolean,boolean) +pgr_withpointsksp(text,text,text,integer,character,boolean,boolean,boolean) +pgr_withpoints(text,text,anyarray,anyarray,boolean,character,boolean) +_pgr_withpoints(text,text,anyarray,anyarray,boolean,character,boolean,boolean,boolean) +pgr_withpoints(text,text,anyarray,bigint,boolean,character,boolean) +pgr_withpoints(text,text,bigint,anyarray,boolean,character,boolean) +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) +_v4trsp(text,text,anyarray,anyarray,boolean) +_v4trsp(text,text,text,boolean) diff --git a/sql/spanningTree/CMakeLists.txt b/sql/spanningTree/CMakeLists.txt index b695a503d41..671894c80e4 100644 --- a/sql/spanningTree/CMakeLists.txt +++ b/sql/spanningTree/CMakeLists.txt @@ -3,7 +3,7 @@ SET(LOCAL_FILES _prim.sql _kruskal.sql #_randomSpanTree.sql - + prim.sql primDFS.sql primBFS.sql diff --git a/sql/spanningTree/_kruskal.sql b/sql/spanningTree/_kruskal.sql index 4ae8d7d4716..8842258bfb1 100644 --- a/sql/spanningTree/_kruskal.sql +++ b/sql/spanningTree/_kruskal.sql @@ -31,6 +31,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -- _pgr_kruskal ---------------- +--v3.7 +CREATE FUNCTION _pgr_kruskalv4( + TEXT, -- Edge sql + ANYARRAY, -- tree root for traversal + TEXT, -- gn suffix + BIGINT, -- max depth + FLOAT, -- distance + + OUT seq BIGINT, + OUT depth BIGINT, + OUT start_vid BIGINT, + OUT pred BIGINT, + OUT node BIGINT, + OUT edge BIGINT, + OUT cost FLOAT, + OUT agg_cost FLOAT) +RETURNS SETOF RECORD AS +'MODULE_PATHNAME' +LANGUAGE C VOLATILE STRICT; + +COMMENT ON FUNCTION _pgr_kruskalv4(TEXT, ANYARRAY, TEXT, BIGINT, FLOAT) +IS 'pgRouting internal function'; --v3.0 CREATE FUNCTION _pgr_kruskal( @@ -56,4 +78,4 @@ LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION _pgr_kruskal(TEXT, ANYARRAY, TEXT, BIGINT, FLOAT) -IS 'pgRouting internal function'; +IS 'pgRouting internal function deprecated on v3.7.0'; diff --git a/sql/spanningTree/_prim.sql b/sql/spanningTree/_prim.sql index 4d519320a64..3401e2812d8 100644 --- a/sql/spanningTree/_prim.sql +++ b/sql/spanningTree/_prim.sql @@ -39,6 +39,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ---------------- +--v3.7 +CREATE FUNCTION _pgr_primv4( + TEXT, -- Edge sql + ANYARRAY, -- tree root for traversal + TEXT, -- order by + BIGINT, -- max depth + FLOAT, -- distance + + OUT seq BIGINT, + OUT depth BIGINT, + OUT start_vid BIGINT, + OUT pred BIGINT, + OUT node BIGINT, + OUT edge BIGINT, + OUT cost FLOAT, + OUT agg_cost FLOAT) +RETURNS SETOF RECORD AS +'MODULE_PATHNAME' +LANGUAGE C VOLATILE STRICT; + +COMMENT ON FUNCTION _pgr_primv4(TEXT, ANYARRAY, TEXT, BIGINT, FLOAT) +IS 'pgRouting internal function'; + --v3.0 CREATE FUNCTION _pgr_prim( TEXT, -- Edge sql @@ -63,5 +86,5 @@ LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION _pgr_prim(TEXT, ANYARRAY, TEXT, BIGINT, FLOAT) -IS 'pgRouting internal function'; +IS 'pgRouting internal function deprecated on v3.7.0'; diff --git a/sql/spanningTree/kruskal.sql b/sql/spanningTree/kruskal.sql index 0648390dc02..bd263043778 100644 --- a/sql/spanningTree/kruskal.sql +++ b/sql/spanningTree/kruskal.sql @@ -42,7 +42,7 @@ CREATE FUNCTION pgr_kruskal( RETURNS SETOF RECORD AS $BODY$ SELECT edge, cost - FROM _pgr_kruskal(_pgr_get_statement($1), ARRAY[0]::BIGINT[], '', -1, -1); + FROM _pgr_kruskalv4(_pgr_get_statement($1), ARRAY[0]::BIGINT[], '', -1, -1); $BODY$ LANGUAGE SQL VOLATILE STRICT; diff --git a/sql/spanningTree/kruskalBFS.sql b/sql/spanningTree/kruskalBFS.sql index 7a64b033299..aaa75fe765e 100644 --- a/sql/spanningTree/kruskalBFS.sql +++ b/sql/spanningTree/kruskalBFS.sql @@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ----------------- ---v3.0 +--v3.7 CREATE FUNCTION pgr_kruskalBFS( TEXT, -- Edge sql (required) BIGINT, -- root vertex (required) @@ -43,28 +43,20 @@ CREATE FUNCTION pgr_kruskalBFS( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''max_depth''' - USING HINT = format('Value found: %s', $3); - END IF; - - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_kruskal(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'BFS', $3, -1) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_kruskalv4(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'BFS', $3, -1); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; ---v3.0 +--v3.7 CREATE FUNCTION pgr_kruskalBFS( TEXT, -- Edge sql (required) ANYARRAY, -- root vertices (required) @@ -74,25 +66,17 @@ CREATE FUNCTION pgr_kruskalBFS( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''max_depth''' - USING HINT = format('Value found: %s', $3); - END IF; - - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_kruskal(_pgr_get_statement($1), $2, 'BFS', $3, -1) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_kruskalv4(_pgr_get_statement($1), $2, 'BFS', $3, -1); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; -- COMMENTS diff --git a/sql/spanningTree/kruskalDD.sql b/sql/spanningTree/kruskalDD.sql index 3c0754c4723..4d2db5f98b6 100644 --- a/sql/spanningTree/kruskalDD.sql +++ b/sql/spanningTree/kruskalDD.sql @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -- SINGLE VERTEX ---v3.0 +--v3.7 CREATE FUNCTION pgr_kruskalDD ( TEXT, -- Edge sql BIGINT, -- root vertex @@ -43,26 +43,19 @@ CREATE FUNCTION pgr_kruskalDD ( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''distance''' - USING HINT = format('Value found: %s', $3); - END IF; - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_kruskal(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DD', -1, $3::FLOAT) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_kruskalv4(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DD', -1, $3::FLOAT); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; ---v3.0 +--v3.7 CREATE FUNCTION pgr_kruskalDD ( TEXT, -- Edge sql BIGINT, -- root vertex @@ -71,28 +64,20 @@ CREATE FUNCTION pgr_kruskalDD ( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''distance''' - USING HINT = format('Value found: %s', $3); - END IF; - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_kruskal(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DD', -1, $3::FLOAT) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_kruskalv4(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DD', -1, $3::FLOAT); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; - +LANGUAGE SQL VOLATILE STRICT; -- MULTIPLE VERTICES ---v3.0 +--v3.7 CREATE FUNCTION pgr_kruskalDD ( TEXT, -- Edge sql ANYARRAY, -- root vertex @@ -102,27 +87,20 @@ CREATE FUNCTION pgr_kruskalDD ( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''distance''' - USING HINT = format('Value found: %s', $3); - END IF; - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_kruskal(_pgr_get_statement($1), $2, 'DD', -1, $3) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_kruskalv4(_pgr_get_statement($1), $2, 'DD', -1, $3); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; ---v3.0 +--v3.7 CREATE FUNCTION pgr_kruskalDD ( TEXT, -- Edge sql ANYARRAY, -- root vertex @@ -132,24 +110,17 @@ CREATE FUNCTION pgr_kruskalDD ( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''distance''' - USING HINT = format('Value found: %s', $3); - END IF; - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_kruskal(_pgr_get_statement($1), $2, 'DD', -1, $3::FLOAT) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_kruskalv4(_pgr_get_statement($1), $2, 'DD', -1, $3::FLOAT); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; -- COMMENTS diff --git a/sql/spanningTree/kruskalDFS.sql b/sql/spanningTree/kruskalDFS.sql index 26f5a719f29..9a32ee11135 100644 --- a/sql/spanningTree/kruskalDFS.sql +++ b/sql/spanningTree/kruskalDFS.sql @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -- SINGLE VERTEX ---v3.0 +--v3.7 CREATE FUNCTION pgr_kruskalDFS( TEXT, -- Edge sql BIGINT, -- root vertex @@ -44,28 +44,20 @@ CREATE FUNCTION pgr_kruskalDFS( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''max_depth''' - USING HINT = format('Value found: %s', $3); - END IF; - - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_kruskal(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DFS', $3, -1) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_kruskalv4(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DFS', $3, -1); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; -- MULTIPLE VERTICES ---v3.0 +--v3.7 CREATE FUNCTION pgr_kruskalDFS( TEXT, -- Edge sql ANYARRAY, -- root vertices @@ -75,25 +67,17 @@ CREATE FUNCTION pgr_kruskalDFS( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''max_depth''' - USING HINT = format('Value found: %s', $3); - END IF; - - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_kruskal(_pgr_get_statement($1), $2, 'DFS', $3, -1) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_kruskalv4(_pgr_get_statement($1), $2, 'DFS', $3, -1); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; -- COMMENTS diff --git a/sql/spanningTree/prim.sql b/sql/spanningTree/prim.sql index 96286179f51..91ebe71b01e 100644 --- a/sql/spanningTree/prim.sql +++ b/sql/spanningTree/prim.sql @@ -42,7 +42,7 @@ CREATE FUNCTION pgr_prim( RETURNS SETOF RECORD AS $BODY$ SELECT edge, cost - FROM _pgr_prim(_pgr_get_statement($1), ARRAY[0]::BIGINT[], '', -1, -1); + FROM _pgr_primv4(_pgr_get_statement($1), ARRAY[0]::BIGINT[], '', -1, -1); $BODY$ LANGUAGE sql VOLATILE STRICT; diff --git a/sql/spanningTree/primBFS.sql b/sql/spanningTree/primBFS.sql index 01bcae4bb79..2e23bcad708 100644 --- a/sql/spanningTree/primBFS.sql +++ b/sql/spanningTree/primBFS.sql @@ -2,7 +2,7 @@ File: primBFS.sql Copyright (c) 2018 Vicky Vergara -Mail: vicky at georepublic dot de +Mail: vicky at erosion dot dev ------ @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -- SINGLE VERTEX ---v3.0 +--v3.7 CREATE FUNCTION pgr_primBFS( TEXT, -- Edge sql BIGINT, -- root vertex @@ -39,29 +39,20 @@ CREATE FUNCTION pgr_primBFS( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''max_depth''' - USING HINT = format('Value found: %s', $3); - END IF; - - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_prim(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'BFS', $3, -1) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_primv4(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'BFS', $3, -1); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; --- MULTIPLE VERTICES ---v3.0 +--v3.7 CREATE FUNCTION pgr_primBFS( TEXT, -- Edge sql ANYARRAY, -- root vertices @@ -71,25 +62,17 @@ CREATE FUNCTION pgr_primBFS( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''max_depth''' - USING HINT = format('Value found: %s', $3); - END IF; - - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_prim(_pgr_get_statement($1), $2, 'BFS', $3, -1) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_primv4(_pgr_get_statement($1), $2, 'BFS', $3, -1); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; -- COMMENTS diff --git a/sql/spanningTree/primDD.sql b/sql/spanningTree/primDD.sql index 1223e26f738..aa3d37989ae 100644 --- a/sql/spanningTree/primDD.sql +++ b/sql/spanningTree/primDD.sql @@ -2,7 +2,7 @@ File: primDD.sql Copyright (c) 2018 Vicky Vergara -Mail: vicky at georepublic dot de +Mail: vicky at vicky at erosion dot dev ------ @@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -- SINGLE VERTEX ---v3.0 +--v3.7 CREATE FUNCTION pgr_primDD ( TEXT, -- Edge sql BIGINT, -- root vertex @@ -37,26 +37,19 @@ CREATE FUNCTION pgr_primDD ( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''distance''' - USING HINT = format('Value found: %s', $3); - END IF; - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_prim(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DD', -1, $3::FLOAT) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_primv4(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DD', -1, $3::FLOAT); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; ---v3.0 +--v3.7 CREATE FUNCTION pgr_primDD ( TEXT, -- Edge sql BIGINT, -- root vertex @@ -65,28 +58,20 @@ CREATE FUNCTION pgr_primDD ( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''distance''' - USING HINT = format('Value found: %s', $3); - END IF; - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_prim(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DD', -1, $3::FLOAT) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_primv4(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DD', -1, $3::FLOAT); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; --- MULTIPLE VERTICES ---v3.0 +--v3.7 CREATE FUNCTION pgr_primDD ( TEXT, -- Edge sql ANYARRAY, -- root vertex @@ -96,27 +81,20 @@ CREATE FUNCTION pgr_primDD ( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''distance''' - USING HINT = format('Value found: %s', $3); - END IF; - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_prim(_pgr_get_statement($1), $2, 'DD', -1, $3) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_primv4(_pgr_get_statement($1), $2, 'DD', -1, $3); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; ---v3.0 +--v3.7 CREATE FUNCTION pgr_primDD ( TEXT, -- Edge sql ANYARRAY, -- root vertex @@ -126,24 +104,17 @@ CREATE FUNCTION pgr_primDD ( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''distance''' - USING HINT = format('Value found: %s', $3); - END IF; - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_prim(_pgr_get_statement($1), $2, 'DD', -1, $3::FLOAT) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_primv4(_pgr_get_statement($1), $2, 'DD', -1, $3::FLOAT); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; -- COMMENTS diff --git a/sql/spanningTree/primDFS.sql b/sql/spanningTree/primDFS.sql index 4967b4c7f0c..c8bcf6a7259 100644 --- a/sql/spanningTree/primDFS.sql +++ b/sql/spanningTree/primDFS.sql @@ -2,7 +2,7 @@ File: primDFS.sql Copyright (c) 2018 Vicky Vergara -Mail: vicky at georepublic dot de +Mail: vicky at vicky at erosion dot dev ------ @@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -- SINGLE VERTEX ---v3.0 +--v3.7 CREATE FUNCTION pgr_primDFS( TEXT, -- Edge sql BIGINT, -- root vertex @@ -38,29 +38,20 @@ CREATE FUNCTION pgr_primDFS( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''max_depth''' - USING HINT = format('Value found: %s', $3); - END IF; - - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_prim(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DFS', $3, -1) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_primv4(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], 'DFS', $3, -1); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; --- MULTIPLE VERTICES ---v3.0 +--v3.7 CREATE FUNCTION pgr_primDFS( TEXT, -- Edge sql ANYARRAY, -- root vertices @@ -70,25 +61,17 @@ CREATE FUNCTION pgr_primDFS( OUT seq BIGINT, OUT depth BIGINT, OUT start_vid BIGINT, + OUT pred BIGINT, OUT node BIGINT, OUT edge BIGINT, OUT cost FLOAT, OUT agg_cost FLOAT) RETURNS SETOF RECORD AS $BODY$ -BEGIN - IF $3 < 0 THEN - RAISE EXCEPTION 'Negative value found on ''max_depth''' - USING HINT = format('Value found: %s', $3); - END IF; - - - RETURN QUERY - SELECT a.seq, a.depth, a.start_vid, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_prim(_pgr_get_statement($1), $2, 'DFS', $3, -1) AS a; -END; + SELECT seq, depth, start_vid, pred, node, edge, cost, agg_cost + FROM _pgr_primv4(_pgr_get_statement($1), $2, 'DFS', $3, -1); $BODY$ -LANGUAGE plpgsql VOLATILE STRICT; +LANGUAGE SQL VOLATILE STRICT; -- COMMENTS diff --git a/sql/trsp/CMakeLists.txt b/sql/trsp/CMakeLists.txt index e66117c87a9..c2b60d62eed 100644 --- a/sql/trsp/CMakeLists.txt +++ b/sql/trsp/CMakeLists.txt @@ -2,14 +2,14 @@ SET(LOCAL_FILES _trsp.sql trsp.sql - _pgr_trsp.sql + _trsp_deprecated.sql _array_reverse.sql - pgr_trsp.sql + trsp_deprecated.sql - _pgr_trspViaVertices.sql - pgr_trspViaVertices.sql + _trspViaVertices_deprecated.sql + trspViaVertices_deprecated.sql - pgr_trspViaEdges.sql + trspViaEdges_deprecated.sql _trsp_withPoints.sql trsp_withPoints.sql diff --git a/sql/trsp/_array_reverse.sql b/sql/trsp/_array_reverse.sql index 64802a33a4d..7f322d027b7 100644 --- a/sql/trsp/_array_reverse.sql +++ b/sql/trsp/_array_reverse.sql @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: _array_reverse.sql Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/sql/trsp/_trsp.sql b/sql/trsp/_trsp.sql index ffe008c6152..4bafa32838b 100644 --- a/sql/trsp/_trsp.sql +++ b/sql/trsp/_trsp.sql @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: _trsp.sql Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org diff --git a/sql/trsp/_pgr_trspViaVertices.sql b/sql/trsp/_trspViaVertices_deprecated.sql similarity index 98% rename from sql/trsp/_pgr_trspViaVertices.sql rename to sql/trsp/_trspViaVertices_deprecated.sql index bebd6bc87ff..2ee513c579b 100644 --- a/sql/trsp/_pgr_trspViaVertices.sql +++ b/sql/trsp/_trspViaVertices_deprecated.sql @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: _trspViaVertices_deprecated.sql Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/sql/trsp/_pgr_trsp.sql b/sql/trsp/_trsp_deprecated.sql similarity index 98% rename from sql/trsp/_pgr_trsp.sql rename to sql/trsp/_trsp_deprecated.sql index 2290b894423..fd81e5e3828 100644 --- a/sql/trsp/_pgr_trsp.sql +++ b/sql/trsp/_trsp_deprecated.sql @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: _trsp_deprecated.sql Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/sql/trsp/trsp.sql b/sql/trsp/trsp.sql index 1acc96f6bf5..80ced402021 100644 --- a/sql/trsp/trsp.sql +++ b/sql/trsp/trsp.sql @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: trsp.sql Copyright (c) 2021 pgRouting developers Mail: project@pgrouting.org diff --git a/sql/trsp/pgr_trspViaEdges.sql b/sql/trsp/trspViaEdges_deprecated.sql similarity index 99% rename from sql/trsp/pgr_trspViaEdges.sql rename to sql/trsp/trspViaEdges_deprecated.sql index cb4840478a1..3bb7028dbfb 100644 --- a/sql/trsp/pgr_trspViaEdges.sql +++ b/sql/trsp/trspViaEdges_deprecated.sql @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: trspViaEdges_deprecated.sql Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/sql/trsp/pgr_trspViaVertices.sql b/sql/trsp/trspViaVertices_deprecated.sql similarity index 98% rename from sql/trsp/pgr_trspViaVertices.sql rename to sql/trsp/trspViaVertices_deprecated.sql index cf9761a2c01..e4f712e972d 100644 --- a/sql/trsp/pgr_trspViaVertices.sql +++ b/sql/trsp/trspViaVertices_deprecated.sql @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: trspViaVertices_deprecated.sql Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/sql/trsp/pgr_trsp.sql b/sql/trsp/trsp_deprecated.sql similarity index 99% rename from sql/trsp/pgr_trsp.sql rename to sql/trsp/trsp_deprecated.sql index 0933442a4cf..011b9373345 100644 --- a/sql/trsp/pgr_trsp.sql +++ b/sql/trsp/trsp_deprecated.sql @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: trsp_deprecated.sql Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/sql/vrp_basic/CMakeLists.txt b/sql/vrp_basic/CMakeLists.txt index ff071286984..670a9d3b36a 100644 --- a/sql/vrp_basic/CMakeLists.txt +++ b/sql/vrp_basic/CMakeLists.txt @@ -2,7 +2,7 @@ SET(LOCAL_FILES #routing_vrp.sql _pgr_vrpOneDepot.sql - pgr_vrpOneDepot.sql + vrpOneDepot.sql ) foreach (f ${LOCAL_FILES}) diff --git a/sql/vrp_basic/pgr_vrpOneDepot.sql b/sql/vrp_basic/vrpOneDepot.sql similarity index 100% rename from sql/vrp_basic/pgr_vrpOneDepot.sql rename to sql/vrp_basic/vrpOneDepot.sql diff --git a/src/allpairs/floydWarshall.c b/src/allpairs/floydWarshall.c index e55162cc5da..4d5c98b10a8 100644 --- a/src/allpairs/floydWarshall.c +++ b/src/allpairs/floydWarshall.c @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ #include - #include "c_common/postgres_connection.h" #include "c_types/iid_t_rt.h" @@ -36,8 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" - #include "drivers/allpairs/floydWarshall_driver.h" PGDLLEXPORT Datum _pgr_floydwarshall(PG_FUNCTION_ARGS); @@ -55,26 +52,9 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_tuples = 0; - pgr_get_edges(edges_sql, &edges, &total_tuples, true, true, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_tuples == 0) { - PGR_DBG("No edges found"); - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - PGR_DBG("Total %ld tuples in query:", total_tuples); - clock_t start_t = clock(); - PGR_DBG("Starting processing"); - do_pgr_floydWarshall( - edges, - total_tuples, + pgr_do_floydWarshall( + edges_sql, directed, result_tuples, result_count, @@ -88,14 +68,8 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - - pfree(edges); pgr_SPI_finish(); } @@ -105,12 +79,9 @@ _pgr_floydwarshall(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ - /* */ + IID_t_rt *result_tuples = NULL; size_t result_count = 0; - /* */ - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; @@ -118,28 +89,12 @@ _pgr_floydwarshall(PG_FUNCTION_ARGS) { oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /*********************************************************************/ - /* */ - // QUERY - // CREATE OR REPLACE FUNCTION pgr_floydWarshalll( - // edges_sql TEXT, - // directed BOOLEAN, - // OUT seq INTEGER, - // OUT from_vid bigint, - // OUT to_vid bigint, - // OUT cost float) - - - PGR_DBG("Calling process"); process( text_to_cstring(PG_GETARG_TEXT_P(0)), PG_GETARG_BOOL(1), &result_tuples, &result_count); - /* */ - /*********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) @@ -163,7 +118,6 @@ _pgr_floydwarshall(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - /*********************************************************************/ values = palloc(3 * sizeof(Datum)); nulls = palloc(3 * sizeof(bool)); @@ -174,7 +128,6 @@ _pgr_floydwarshall(PG_FUNCTION_ARGS) { nulls[1] = false; values[2] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); nulls[2] = false; - /*********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/allpairs/floydWarshall_driver.cpp b/src/allpairs/floydWarshall_driver.cpp index 9dbb95aed42..a016e03d09f 100644 --- a/src/allpairs/floydWarshall_driver.cpp +++ b/src/allpairs/floydWarshall_driver.cpp @@ -32,17 +32,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "allpairs/pgr_allpairs.hpp" +#include "allpairs/allpairs.hpp" +#include "cpp_common/pgdata_getters.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" void -do_pgr_floydWarshall( - Edge_t *data_edges, - size_t total_tuples, - bool directedFlag, +pgr_do_floydWarshall( + char *edges_sql, + bool directed, IID_t_rt **return_tuples, size_t *return_count, @@ -53,6 +54,7 @@ do_pgr_floydWarshall( std::ostringstream log; std::ostringstream err; + char *hint = nullptr; try { pgassert(!(*log_msg)); @@ -60,18 +62,23 @@ do_pgr_floydWarshall( pgassert(!(*return_tuples)); pgassert(*return_count == 0); - graphType gType = directedFlag? DIRECTED: UNDIRECTED; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, true); + if (edges.empty()) { + throw std::string("No edges found"); + } + hint = nullptr; - if (directedFlag) { + if (directed) { log << "Processing Directed graph\n"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_tuples); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); pgr_floydWarshall(digraph, *return_count, return_tuples); } else { log << "Processing Undirected graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_tuples); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); pgr_floydWarshall(undigraph, *return_count, return_tuples); } @@ -93,6 +100,9 @@ do_pgr_floydWarshall( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/allpairs/johnson.c b/src/allpairs/johnson.c index 274498271f0..3c4d88990c9 100644 --- a/src/allpairs/johnson.c +++ b/src/allpairs/johnson.c @@ -34,15 +34,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/allpairs/johnson_driver.h" PGDLLEXPORT Datum _pgr_johnson(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_johnson); -/******************************************************************************/ -/* MODIFY AS NEEDED */ static void process( char* edges_sql, @@ -54,26 +51,10 @@ void process( char* notice_msg = NULL; char* err_msg = NULL; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_tuples = 0; - pgr_get_edges(edges_sql, &edges, &total_tuples, true, true, &err_msg); - throw_error(err_msg, edges_sql); - if (total_tuples == 0) { - PGR_DBG("No edges found"); - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - PGR_DBG("Total %ld tuples in query:", total_tuples); - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_johnson( - edges, - total_tuples, + pgr_do_johnson( + edges_sql, directed, result_tuples, result_count, @@ -87,31 +68,18 @@ void process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - - pfree(edges); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ PGDLLEXPORT Datum _pgr_johnson(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ - /* MODIFY AS NEEDED */ - /* */ IID_t_rt *result_tuples = NULL; size_t result_count = 0; - /* */ - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; @@ -119,22 +87,12 @@ _pgr_johnson(PG_FUNCTION_ARGS) { oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /*********************************************************************/ - /* MODIFY AS NEEDED */ - // CREATE OR REPLACE FUNCTION pgr_johnson( - // edges_sql TEXT, - // directed BOOLEAN, - - PGR_DBG("Calling process"); process( text_to_cstring(PG_GETARG_TEXT_P(0)), PG_GETARG_BOOL(1), &result_tuples, &result_count); - /* */ - /*********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) @@ -158,13 +116,6 @@ _pgr_johnson(PG_FUNCTION_ARGS) { Datum *values; bool *nulls; - /*********************************************************************/ - /* MODIFY AS NEEDED */ - // OUT seq BIGINT, - // OUT from_vid BIGINT, - // OUT to_vid BIGINT, - // OUT cost float) - values = palloc(3 * sizeof(Datum)); nulls = palloc(3 * sizeof(bool)); @@ -176,8 +127,6 @@ _pgr_johnson(PG_FUNCTION_ARGS) { values[2] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); nulls[2] = false; - /*********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); diff --git a/src/allpairs/johnson_driver.cpp b/src/allpairs/johnson_driver.cpp index ff0c914f134..dea9c9f8f10 100644 --- a/src/allpairs/johnson_driver.cpp +++ b/src/allpairs/johnson_driver.cpp @@ -32,16 +32,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "allpairs/pgr_allpairs.hpp" +#include "allpairs/allpairs.hpp" +#include "cpp_common/pgdata_getters.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" void -do_pgr_johnson( - Edge_t *data_edges, - size_t total_tuples, +pgr_do_johnson( + char *edges_sql, bool directed, IID_t_rt **return_tuples, size_t *return_count, @@ -52,6 +53,7 @@ do_pgr_johnson( std::ostringstream log; std::ostringstream err; + char *hint = nullptr; try { pgassert(!(*log_msg)); @@ -59,30 +61,35 @@ do_pgr_johnson( pgassert(!(*return_tuples)); pgassert(*return_count == 0); - graphType gType = directed? DIRECTED: UNDIRECTED; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, true); + + if (edges.empty()) { + throw std::string("No edges found"); + } + hint = nullptr; if (directed) { log << "Processing Directed graph\n"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_tuples); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); pgr_johnson(digraph, *return_count, return_tuples); } else { log << "Processing Undirected graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_tuples); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); pgr_johnson(undigraph, *return_count, return_tuples); } if (*return_count == 0) { - log << "No result generated, report this error\n"; - *log_msg = pgr_msg(err.str().c_str()); + err << "No result generated, report this error\n"; + *err_msg = pgr_msg(err.str().c_str()); *return_tuples = NULL; *return_count = 0; return; } - *log_msg = log.str().empty()? *log_msg : pgr_msg(log.str().c_str()); @@ -92,6 +99,9 @@ do_pgr_johnson( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/alpha_shape/CMakeLists.txt b/src/alpha_shape/CMakeLists.txt index 22148dd4ebc..f7e04dfea9d 100644 --- a/src/alpha_shape/CMakeLists.txt +++ b/src/alpha_shape/CMakeLists.txt @@ -1,5 +1,5 @@ ADD_LIBRARY(alpha_shape OBJECT - pgr_alphaShape.cpp + alphaShape.cpp alphaShape.c alphaShape_driver.cpp ) diff --git a/src/alpha_shape/alphaShape.c b/src/alpha_shape/alphaShape.c index ba56b55d54a..cf4971ce55f 100644 --- a/src/alpha_shape/alphaShape.c +++ b/src/alpha_shape/alphaShape.c @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -FILE: alphaShape.c +File: alphaShape.c Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org @@ -35,7 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/geom_text_rt.h" #include "drivers/alpha_shape/alphaShape_driver.h" @@ -53,34 +52,8 @@ static void process( char* notice_msg = NULL; char* err_msg = NULL; - Edge_xy_t *edgesArr = NULL; - size_t edgesSize = 0; - - pgr_get_edges_xy(edges_sql, &edgesArr, &edgesSize, true, &err_msg); - throw_error(err_msg, edges_sql); - - PGR_DBG("total edges %ld", edgesSize); - PGR_DBG("alpha %f", alpha); -#if 0 - for (size_t i = 0; i < edgesSize; ++i) { - PGR_DBG("x1=%f y1=%f", edgesArr[i].x1, edgesArr[i].y1); - PGR_DBG("x2=%f y2=%f", edgesArr[i].x2, edgesArr[i].y2); - } -#endif - - if (edgesSize < 3) { - if (edgesArr) pfree(edgesArr); - elog(ERROR, "Less than 3 vertices." - " pgr_alphaShape needs at least 3 vertices."); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Calling alpha-shape driver\n"); - - - do_alphaShape( - edgesArr, edgesSize, + pgr_do_alphaShape( + edges_sql, alpha, res, @@ -95,12 +68,8 @@ static void process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edgesArr) pfree(edgesArr); pgr_SPI_finish(); } @@ -111,26 +80,20 @@ Datum _pgr_alphashape(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ GeomText_t *result_tuples = NULL; 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)), PG_GETARG_FLOAT8(1), &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) diff --git a/src/alpha_shape/pgr_alphaShape.cpp b/src/alpha_shape/alphaShape.cpp similarity index 99% rename from src/alpha_shape/pgr_alphaShape.cpp rename to src/alpha_shape/alphaShape.cpp index 961a0823d39..e85c8b90a24 100644 --- a/src/alpha_shape/pgr_alphaShape.cpp +++ b/src/alpha_shape/alphaShape.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -file: pgr_alphaShape.cpp +File: alphaShape.cpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "alphaShape/pgr_alphaShape.h" +#include "alphaShape/alphaShape.hpp" #include #include @@ -51,7 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include -#include "cpp_common/interruption.h" +#include "cpp_common/interruption.hpp" namespace bg = boost::geometry; @@ -166,8 +166,7 @@ struct CompareRadius { /* * Constructor */ -Pgr_alphaShape::Pgr_alphaShape(const std::vector &edges) : -graph(UNDIRECTED) { +Pgr_alphaShape::Pgr_alphaShape(const std::vector &edges) { graph.insert_edges(edges); make_triangles(); } diff --git a/src/alpha_shape/alphaShape_driver.cpp b/src/alpha_shape/alphaShape_driver.cpp index 8a85601c6e0..e3441771d80 100644 --- a/src/alpha_shape/alphaShape_driver.cpp +++ b/src/alpha_shape/alphaShape_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -FILE: alphaShape_driver.cpp +File: alphaShape_driver.cpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org @@ -39,12 +39,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_types/geom_text_rt.h" -#include "cpp_common/pgr_assert.h" -#include "alphaShape/pgr_alphaShape.h" +#include "cpp_common/assert.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "alphaShape/alphaShape.hpp" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/alloc.hpp" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/base_graph.hpp" #include "cpp_common/bpoint.hpp" #include "cpp_common/bline.hpp" @@ -61,10 +62,8 @@ data_eq(const Edge_xy_t &lhs, const Edge_xy_t &rhs, int64_t round) { } void -do_alphaShape( - Edge_xy_t *edgesArr, - size_t edgesSize, - +pgr_do_alphaShape( + char* edges_sql, double alpha, GeomText_t **return_tuples, @@ -80,13 +79,20 @@ do_alphaShape( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char* hint = nullptr; + try { - pgassert(edgesArr); - pgassert(edgesSize > 2); pgassert(*return_count == 0); const int64_t round = 100000000000000; - std::vector edges(edgesArr, edgesArr + edgesSize); + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges_xy(std::string(edges_sql), true); + + if (edges.size() < 3) { + throw std::string("Less than 3 vertices. pgr_alphaShape needs at least 3 vertices."); + } + hint = nullptr; + /* id | source | target | cost | x1 | y1 | x2 | y2 -------+--------+--------+------+------------+------------+----+---- @@ -107,8 +113,6 @@ do_alphaShape( return std::floor(lhs.x1 * static_cast(round)) < std::floor(rhs.x1 * static_cast(round)); }); - log << "ending sort"; - int64_t source_id(0); @@ -201,15 +205,21 @@ do_alphaShape( (*return_count) = 0; err << except.what(); *err_msg = pgr_msg(err.str().c_str()); + *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : 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()); } } diff --git a/src/astar/astar.c b/src/astar/astar.c index d4fc8039da4..1bf9284269d 100644 --- a/src/astar/astar.c +++ b/src/astar/astar.c @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: astarOneToOne.c +File: astar.c Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -7,7 +7,7 @@ Mail: project@pgrouting.org Function's developer: Copyright (c) 2015 Celia Virginia Vergara Castillo -Mail: +Mail: vicky at erosion.dev ------ @@ -29,15 +29,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_common/check_parameters.h" - #include "drivers/astar/astar_driver.h" PGDLLEXPORT Datum _pgr_astar(PG_FUNCTION_ARGS); @@ -64,55 +61,13 @@ process(char* edges_sql, char* notice_msg = NULL; char* err_msg = NULL; - int64_t* start_vidsArr = NULL; - size_t size_start_vidsArr = 0; - - int64_t* end_vidsArr = NULL; - size_t size_end_vidsArr = 0; - - Edge_xy_t *edges = NULL; - size_t total_edges = 0; - - II_t_rt *combinations = NULL; - size_t total_combinations = 0; - - if (normal) { - pgr_get_edges_xy(edges_sql, &edges, &total_edges, true, &err_msg); - throw_error(err_msg, edges_sql); - if (starts && ends) { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - } - } else { - pgr_get_edges_xy(edges_sql, &edges, &total_edges, false, &err_msg); - throw_error(err_msg, edges_sql); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } - - if (total_edges == 0) { - PGR_DBG("No edges found"); - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); pgr_do_astar( - edges, total_edges, - - combinations, total_combinations, + edges_sql, + combinations_sql, + starts, + ends, - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, directed, heuristic, factor, @@ -130,21 +85,13 @@ process(char* edges_sql, time_msg("processing pgr_astar", 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 (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (start_vidsArr) pfree(start_vidsArr); - if (end_vidsArr) pfree(end_vidsArr); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } @@ -222,6 +169,8 @@ _pgr_astar(PG_FUNCTION_ARGS) { Datum result; Datum *values; bool* nulls; + size_t call_cntr = funcctx->call_cntr; + size_t numb = 8; values = palloc(numb * sizeof(Datum)); @@ -232,16 +181,18 @@ _pgr_astar(PG_FUNCTION_ARGS) { nulls[i] = false; } + int64_t seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; - values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq); - values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id); - values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id); - values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); - values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); - values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); - values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); + values[0] = Int32GetDatum((int32_t)call_cntr + 1); + values[1] = Int32GetDatum((int32_t)seq); + values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); + values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); + values[4] = Int64GetDatum(result_tuples[call_cntr].node); + values[5] = Int64GetDatum(result_tuples[call_cntr].edge); + values[6] = Float8GetDatum(result_tuples[call_cntr].cost); + values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); + result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/astar/astar_driver.cpp b/src/astar/astar_driver.cpp index e38523bf980..6a14a78f90b 100644 --- a/src/astar/astar_driver.cpp +++ b/src/astar/astar_driver.cpp @@ -33,23 +33,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include #include "astar/astar.hpp" -#include "cpp_common/combinations.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -#include "c_types/edge_xy_t.h" +#include "cpp_common/edge_xy_t.hpp" #include "c_types/ii_t_rt.h" void pgr_do_astar( - Edge_xy_t *edges, size_t total_edges, + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, - II_t_rt *combinationsArr, size_t total_combinations, - - int64_t *start_vidsArr, size_t size_start_vidsArr, - int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, int heuristic, double factor, @@ -62,37 +63,58 @@ void pgr_do_astar( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; std::ostringstream log; std::ostringstream notice; std::ostringstream err; + + char* hint = nullptr; try { pgassert(!(*log_msg)); + pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - auto combinations = total_combinations? - pgrouting::utilities::get_combinations(combinationsArr, total_combinations) - : pgrouting::utilities::get_combinations(start_vidsArr, size_start_vidsArr, end_vidsArr, size_end_vidsArr); + (*return_tuples) = nullptr; + (*return_count) = 0; + + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, normal); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges_xy(std::string(edges_sql), normal); + hint = nullptr; + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = pgr_msg(edges_sql); + return; + } + + - graphType gType = directed? DIRECTED: UNDIRECTED; std::deque paths; if (directed) { - pgrouting::xyDirectedGraph graph( - pgrouting::extract_vertices(edges, total_edges), - gType); - graph.insert_edges(edges, total_edges); + pgrouting::xyDirectedGraph graph; + graph.insert_edges(edges); paths = pgrouting::algorithms::astar(graph, combinations, heuristic, factor, epsilon, only_cost); } else { - pgrouting::xyUndirectedGraph graph( - pgrouting::extract_vertices(edges, total_edges), - gType); - graph.insert_edges(edges, total_edges); + pgrouting::xyUndirectedGraph graph; + graph.insert_edges(edges); paths = pgrouting::algorithms::astar(graph, combinations, heuristic, factor, epsilon, only_cost); } + if (!normal) { for (auto &path : paths) { path.reverse(); @@ -103,7 +125,7 @@ void pgr_do_astar( count = count_tuples(paths); if (count == 0) { - (*return_tuples) = NULL; + (*return_tuples) = nullptr; (*return_count) = 0; notice << "No paths found\n"; *log_msg = pgr_msg(notice.str().c_str()); @@ -125,6 +147,9 @@ void pgr_do_astar( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/bdAstar/bdAstar.c b/src/bdAstar/bdAstar.c index 845ccc3ad28..64359b91ddb 100644 --- a/src/bdAstar/bdAstar.c +++ b/src/bdAstar/bdAstar.c @@ -7,7 +7,7 @@ Mail: project@pgrouting.org Function's developer: Copyright (c) 2015 Celia Virginia Vergara Castillo -Mail:vicky at erosion.dev +Mail: vicky at erosion.dev ------ @@ -34,9 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_common/check_parameters.h" - #include "drivers/bdAstar/bdAstar_driver.h" PGDLLEXPORT Datum _pgr_bdastar(PG_FUNCTION_ARGS); @@ -63,47 +61,12 @@ process(char* edges_sql, char* notice_msg = NULL; char* err_msg = NULL; - int64_t* start_vidsArr = NULL; - size_t size_start_vidsArr = 0; - - int64_t* end_vidsArr = NULL; - size_t size_end_vidsArr = 0; - - Edge_xy_t *edges = NULL; - size_t total_edges = 0; - - II_t_rt *combinations = NULL; - size_t total_combinations = 0; - - if (starts && ends) { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - } - - pgr_get_edges_xy(edges_sql, &edges, &total_edges, true, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - PGR_DBG("No edges found"); - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); pgr_do_bdAstar( - edges, total_edges, + edges_sql, + combinations_sql, + starts, ends, - combinations, total_combinations, - - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, directed, heuristic, factor, @@ -126,14 +89,7 @@ process(char* edges_sql, (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (start_vidsArr) pfree(start_vidsArr); - if (end_vidsArr) pfree(end_vidsArr); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } @@ -161,7 +117,6 @@ _pgr_bdastar(PG_FUNCTION_ARGS) { NULL, PG_GETARG_ARRAYTYPE_P(1), PG_GETARG_ARRAYTYPE_P(2), - PG_GETARG_BOOL(3), PG_GETARG_INT32(4), PG_GETARG_FLOAT8(5), @@ -222,8 +177,10 @@ _pgr_bdastar(PG_FUNCTION_ARGS) { nulls[i] = false; } + int64_t seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; + values[0] = Int32GetDatum((int32_t)call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[call_cntr].seq); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); values[4] = Int64GetDatum(result_tuples[call_cntr].node); @@ -231,6 +188,7 @@ _pgr_bdastar(PG_FUNCTION_ARGS) { values[6] = Float8GetDatum(result_tuples[call_cntr].cost); values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); + result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/bdAstar/bdAstar_driver.cpp b/src/bdAstar/bdAstar_driver.cpp index cc9a671ad4d..8f685608e4a 100644 --- a/src/bdAstar/bdAstar_driver.cpp +++ b/src/bdAstar/bdAstar_driver.cpp @@ -32,26 +32,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include #include +#include +#include #include "bdAstar/bdAstar.hpp" -#include "cpp_common/combinations.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/edge_xy_t.hpp" #include "c_types/ii_t_rt.h" +void pgr_do_bdAstar( + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, -void -pgr_do_bdAstar( - Edge_xy_t *edges, size_t total_edges, - - II_t_rt *combinationsArr, size_t total_combinations, - - int64_t *start_vidsArr, size_t size_start_vidsArr, - int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, int heuristic, double factor, @@ -64,35 +64,51 @@ pgr_do_bdAstar( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; std::ostringstream log; std::ostringstream notice; std::ostringstream err; + + char* hint = nullptr; try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - auto combinations = total_combinations? - pgrouting::utilities::get_combinations(combinationsArr, total_combinations) - : pgrouting::utilities::get_combinations(start_vidsArr, size_start_vidsArr, end_vidsArr, size_end_vidsArr); + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges_xy(std::string(edges_sql), true); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + - graphType gType = directed? DIRECTED: UNDIRECTED; std::deque paths; if (directed) { - pgrouting::xyDirectedGraph digraph(pgrouting::extract_vertices(edges, total_edges), gType); - digraph.insert_edges(edges, total_edges); - - paths = pgrouting::algorithms::bdastar(digraph, combinations, heuristic, factor, epsilon, only_cost); + pgrouting::xyDirectedGraph graph; + graph.insert_edges(edges); + paths = pgrouting::algorithms::bdastar(graph, combinations, heuristic, factor, epsilon, only_cost); } else { - pgrouting::xyUndirectedGraph undigraph(pgrouting::extract_vertices(edges, total_edges), gType); - undigraph.insert_edges(edges, total_edges); - - paths = pgrouting::algorithms::bdastar(undigraph, combinations, heuristic, factor, epsilon, only_cost); + pgrouting::xyUndirectedGraph graph; + graph.insert_edges(edges); + paths = pgrouting::algorithms::bdastar(graph, combinations, heuristic, factor, epsilon, only_cost); } size_t count(0); @@ -109,8 +125,6 @@ pgr_do_bdAstar( (*return_tuples) = pgr_alloc(count, (*return_tuples)); (*return_count) = (collapse_paths(return_tuples, paths)); - - pgassert(*err_msg == nullptr); *log_msg = log.str().empty()? *log_msg : pgr_msg(log.str().c_str()); @@ -123,6 +137,9 @@ pgr_do_bdAstar( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/bdDijkstra/bdDijkstra.c b/src/bdDijkstra/bdDijkstra.c index d367dcf2214..843efdf289f 100644 --- a/src/bdDijkstra/bdDijkstra.c +++ b/src/bdDijkstra/bdDijkstra.c @@ -7,7 +7,7 @@ Mail: project@pgrouting.org Function's developer: Copyright (c) 2016 Celia Virginia Vergara Castillo -Mail: vicky_vergara@hotmail.com +Mail: vicky at erosion.dev ------ @@ -31,29 +31,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" - #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - #include "drivers/bdDijkstra/bdDijkstra_driver.h" PGDLLEXPORT Datum _pgr_bddijkstra(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_bddijkstra); - -/******************************************************************************/ -/* MODIFY AS NEEDED */ -static -void +static void process( - char* edges_sql, - char* combinations_sql, + char *edges_sql, + char *combinations_sql, ArrayType *starts, ArrayType *ends, + bool directed, bool only_cost, Path_rt **result_tuples, @@ -63,45 +56,11 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - int64_t* start_vidsArr = NULL; - size_t size_start_vidsArr = 0; - - int64_t* end_vidsArr = NULL; - size_t size_end_vidsArr = 0; - - Edge_t *edges = NULL; - size_t total_edges = 0; - - II_t_rt *combinations = NULL; - size_t total_combinations = 0; - - if (starts && ends) { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - } - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - PGR_DBG("No edges found"); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_bdDijkstra( - edges, total_edges, - combinations, total_combinations, - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, + pgr_do_bdDijkstra( + edges_sql, + combinations_sql, + starts, ends, directed, only_cost, @@ -111,7 +70,6 @@ process( &log_msg, ¬ice_msg, &err_msg); - time_msg(" processing pgr_bdDijkstra", start_t, clock()); @@ -121,36 +79,23 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ + PGDLLEXPORT Datum _pgr_bddijkstra(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; - TupleDesc tuple_desc; + TupleDesc tuple_desc; - /**************************************************************************/ - /* MODIFY AS NEEDED */ - /* */ Path_rt *result_tuples = NULL; size_t result_count = 0; - /* */ - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - if (PG_NARGS() == 5) { /* * many to many @@ -180,11 +125,7 @@ PGDLLEXPORT Datum _pgr_bddijkstra(PG_FUNCTION_ARGS) { &result_count); } - /* */ - /**********************************************************************/ - funcctx->max_calls = result_count; - funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) { @@ -200,7 +141,6 @@ PGDLLEXPORT Datum _pgr_bddijkstra(PG_FUNCTION_ARGS) { funcctx = SRF_PERCALL_SETUP(); tuple_desc = funcctx->tuple_desc; - result_tuples = (Path_rt*) funcctx->user_fctx; if (funcctx->call_cntr < funcctx->max_calls) { @@ -210,30 +150,19 @@ PGDLLEXPORT Datum _pgr_bddijkstra(PG_FUNCTION_ARGS) { bool* nulls; size_t call_cntr = funcctx->call_cntr; - - /**********************************************************************/ - /* MODIFY AS NEEDED */ - /* - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT - ***********************************************************************/ - size_t numb = 8; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); - size_t i; for (i = 0; i < numb; ++i) { nulls[i] = false; } + int64_t seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; + values[0] = Int32GetDatum((int32_t)call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[call_cntr].seq); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); values[4] = Int64GetDatum(result_tuples[call_cntr].node); @@ -241,7 +170,7 @@ PGDLLEXPORT Datum _pgr_bddijkstra(PG_FUNCTION_ARGS) { values[6] = Float8GetDatum(result_tuples[call_cntr].cost); values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); - /**********************************************************************/ + result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/bdDijkstra/bdDijkstra_driver.cpp b/src/bdDijkstra/bdDijkstra_driver.cpp index 48bb0062a05..1411dd50fd9 100644 --- a/src/bdDijkstra/bdDijkstra_driver.cpp +++ b/src/bdDijkstra/bdDijkstra_driver.cpp @@ -7,7 +7,7 @@ Mail: project@pgrouting.org Function's developer: Copyright (c) 2016 Celia Virginia Vergara Castillo -Mail: vicky_vergara@hotmail.com +Mail: vicky at erosion.dev ------ @@ -33,13 +33,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include +#include +#include -#include "bdDijkstra/pgr_bdDijkstra.hpp" - -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/base_graph.hpp" +#include "bdDijkstra/bdDijkstra.hpp" #include "c_types/ii_t_rt.h" @@ -51,92 +55,35 @@ template < class G > std::deque pgr_bdDijkstra( G &graph, - std::vector < II_t_rt > &combinations, - std::vector < int64_t > sources, - std::vector < int64_t > targets, - - std::ostream &log, + const std::map> &combinations, bool only_cost) { using pgrouting::Path; pgrouting::bidirectional::Pgr_bdDijkstra fn_bdDijkstra(graph); std::deque paths; - if (combinations.empty()) { - std::sort(sources.begin(), sources.end()); - sources.erase( - std::unique(sources.begin(), sources.end()), - sources.end()); - - std::sort(targets.begin(), targets.end()); - targets.erase( - std::unique(targets.begin(), targets.end()), - targets.end()); - - for (const auto source : sources) { - for (const auto target : targets) { - fn_bdDijkstra.clear(); - - if (!graph.has_vertex(source) - || !graph.has_vertex(target)) { - paths.push_back(Path(source, target)); - continue; - } - - paths.push_back(fn_bdDijkstra.pgr_bdDijkstra( - graph.get_V(source), graph.get_V(target), only_cost)); - } - } - - } else { - std::sort(combinations.begin(), combinations.end(), - [](const II_t_rt &lhs, const II_t_rt &rhs)->bool { - return lhs.d2.target < rhs.d2.target; - }); - std::stable_sort(combinations.begin(), combinations.end(), - [](const II_t_rt &lhs, const II_t_rt &rhs)->bool { - return lhs.d1.source < rhs.d1.source; - }); - - II_t_rt previousCombination {{0}, {0}}; + for (const auto &comb : combinations) { + auto source = comb.first; + if (!graph.has_vertex(source)) continue; - for (const II_t_rt &comb : combinations) { + for (const auto &target : comb.second) { + if (!graph.has_vertex(target)) continue; fn_bdDijkstra.clear(); - if (comb.d1.source == previousCombination.d1.source && - comb.d2.target == previousCombination.d2.target) { - continue; - } - if (!graph.has_vertex(comb.d1.source) - || !graph.has_vertex(comb.d2.target)) { - paths.push_back(Path(comb.d1.source, comb.d2.target)); - continue; - } - - paths.push_back(fn_bdDijkstra.pgr_bdDijkstra( - graph.get_V(comb.d1.source), graph.get_V(comb.d2.target), only_cost)); - - previousCombination = comb; + paths.push_back(fn_bdDijkstra.pgr_bdDijkstra(graph.get_V(source), graph.get_V(target), only_cost)); } } - - log << fn_bdDijkstra.log(); - return paths; } } // namespace void -do_pgr_bdDijkstra( - Edge_t *data_edges, - size_t total_edges, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, +pgr_do_bdDijkstra( + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, bool directed, bool only_cost, @@ -147,74 +94,70 @@ do_pgr_bdDijkstra( char **notice_msg, char **err_msg) { using pgrouting::Path; + using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; - using pgrouting::pgr_alloc; + using pgrouting::utilities::get_combinations; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - log << "Inserting vertices into a c++ vector structure"; - std::vector - start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr); - std::vector< int64_t > - end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr); - std::vector< II_t_rt > - combinations_vector(combinations, combinations + total_combinations); + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); - graphType gType = directed? DIRECTED: UNDIRECTED; + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; std::deque paths; - log << "starting process\n"; if (directed) { - log << "Working with directed Graph\n"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); - paths = pgr_bdDijkstra(digraph, - combinations_vector, - start_vertices, - end_vertices, - log, - only_cost); + pgrouting::DirectedGraph graph; + graph.insert_edges(edges); + paths = pgr_bdDijkstra(graph, combinations, only_cost); } else { - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); - paths = pgr_bdDijkstra( - undigraph, - combinations_vector, - start_vertices, - end_vertices, - log, - only_cost); + pgrouting::UndirectedGraph graph; + graph.insert_edges(edges); + paths = pgr_bdDijkstra(graph, combinations, only_cost); } - size_t count(0); - count = count_tuples(paths); + auto count = count_tuples(paths); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No paths found"; + notice << "No paths found"; *log_msg = pgr_msg(notice.str().c_str()); return; } (*return_tuples) = pgr_alloc(count, (*return_tuples)); - log << "\nConverting a set of paths into the tuples"; (*return_count) = (collapse_paths(return_tuples, paths)); - pgassert(*err_msg == NULL); *log_msg = log.str().empty()? *log_msg : pgr_msg(log.str().c_str()); @@ -227,6 +170,9 @@ do_pgr_bdDijkstra( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/bellman_ford/bellman_ford.c b/src/bellman_ford/bellman_ford.c index efa5113e44d..60962c06def 100644 --- a/src/bellman_ford/bellman_ford.c +++ b/src/bellman_ford/bellman_ford.c @@ -35,9 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - #include "drivers/bellman_ford/bellman_ford_driver.h" PGDLLEXPORT Datum _pgr_bellmanford(PG_FUNCTION_ARGS); @@ -59,61 +56,15 @@ process( char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - - PGR_DBG("Initializing arrays"); - - size_t size_start_vidsArr = 0; - int64_t* start_vidsArr = NULL; - - size_t size_end_vidsArr = 0; - int64_t* end_vidsArr = NULL; - - size_t total_combinations = 0; - II_t_rt *combinations = NULL; - - if (starts && ends) { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - if (total_combinations == 0) { - if (combinations) - pfree(combinations); - pgr_SPI_finish(); - return; - } - } - (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - if (end_vidsArr) pfree(end_vidsArr); - if (start_vidsArr) pfree(start_vidsArr); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_bellman_ford( - edges, - total_edges, - combinations, - total_combinations, - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, + pgr_do_bellman_ford( + edges_sql, + combinations_sql, + starts, ends, + directed, only_cost, @@ -125,41 +76,31 @@ process( &err_msg); time_msg(" processing pgr_bellman_ford", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); - if (err_msg) { - if (*result_tuples) pfree(*result_tuples); + if (err_msg && (*result_tuples)) { + pfree(*result_tuples); + (*result_tuples) = NULL; + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - - if (end_vidsArr) pfree(end_vidsArr); - if (start_vidsArr) pfree(start_vidsArr); pgr_SPI_finish(); } - -PGDLLEXPORT Datum _pgr_bellmanford(PG_FUNCTION_ARGS) { +PGDLLEXPORT Datum +_pgr_bellmanford(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; - TupleDesc tuple_desc; + TupleDesc tuple_desc; - /**************************************************************************/ Path_rt *result_tuples = NULL; size_t result_count = 0; - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - PGR_DBG("Calling process"); if (PG_NARGS() == 5) { /* * many to many @@ -189,9 +130,6 @@ PGDLLEXPORT Datum _pgr_bellmanford(PG_FUNCTION_ARGS) { &result_count); } - - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) @@ -216,30 +154,19 @@ PGDLLEXPORT Datum _pgr_bellmanford(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - /**********************************************************************/ - /* - OUT seq 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 - */ - /**********************************************************************/ size_t numb = 8; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); - size_t i; for (i = 0; i < numb; ++i) { nulls[i] = false; } + int64_t seq = funcctx->call_cntr == 0? 1 : result_tuples[funcctx->call_cntr - 1].start_id; + values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id); values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id); values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); @@ -247,18 +174,12 @@ PGDLLEXPORT Datum _pgr_bellmanford(PG_FUNCTION_ARGS) { values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ + result_tuples[funcctx->call_cntr].start_id = result_tuples[funcctx->call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/bellman_ford/bellman_ford_driver.cpp b/src/bellman_ford/bellman_ford_driver.cpp index eef5eee0429..2203aad4a62 100644 --- a/src/bellman_ford/bellman_ford_driver.cpp +++ b/src/bellman_ford/bellman_ford_driver.cpp @@ -34,66 +34,41 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include +#include -#include "bellman_ford/pgr_bellman_ford.hpp" +#include "bellman_ford/bellman_ford.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "c_types/ii_t_rt.h" -/* Bellman Ford Shortest Path */ -/************************************************************ - EDGE_SQL, - ANYARRAY, - ANYARRAY, - directed BOOLEAN DEFAULT true, - ***********************************************************/ - namespace { + template std::deque -pgr_bellman_ford( +bellman_ford( G &graph, - std::vector &combinations, - std::vector < int64_t > sources, - std::vector < int64_t > targets, - std::string &log, + const std::map> &combinations, bool only_cost = false) { - std::sort(sources.begin(), sources.end()); - sources.erase( - std::unique(sources.begin(), sources.end()), - sources.end()); - - std::sort(targets.begin(), targets.end()); - targets.erase( - std::unique(targets.begin(), targets.end()), - targets.end()); - - pgrouting::Pgr_bellman_ford< G > fn_bellman_ford; - auto paths = combinations.empty() ? - fn_bellman_ford.bellman_ford(graph, sources, targets, only_cost) - : fn_bellman_ford.bellman_ford(graph, combinations, only_cost); - log += fn_bellman_ford.get_log(); - for (auto &p : paths) { - p.recalculate_agg_cost(); - } + pgrouting::Pgr_bellman_ford fn_bellman_ford; + auto paths = fn_bellman_ford.bellman_ford(graph, combinations, only_cost); + for (auto &p : paths) p.recalculate_agg_cost(); return paths; } } // namespace void -do_pgr_bellman_ford( - Edge_t *data_edges, - size_t total_edges, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, +pgr_do_bellman_ford( + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, bool directed, bool only_cost, @@ -106,70 +81,66 @@ do_pgr_bellman_ford( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - pgassert(data_edges); - pgassert((start_vidsArr && end_vidsArr) || combinations); - pgassert((size_start_vidsArr && size_end_vidsArr) || total_combinations); - - graphType gType = directed? DIRECTED: UNDIRECTED; - - log << "Inserting vertices into a c++ vector structure"; - std::vector - start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr); - std::vector< int64_t > - end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr); - std::vector< II_t_rt > - combinations_vector(combinations, combinations + total_combinations); - - std::deque< Path >paths; - std::string logstr; + + + + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + std::deque paths; if (directed) { - log << "Working with directed Graph\n"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); - paths = pgr_bellman_ford(digraph, - combinations_vector, - start_vertices, - end_vertices, - logstr, - only_cost); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); + paths = bellman_ford(digraph, combinations, only_cost); } else { - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); - paths = pgr_bellman_ford( - undigraph, - combinations_vector, - start_vertices, - end_vertices, - logstr, - only_cost); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); + paths = bellman_ford(undigraph, combinations, only_cost); } - log<< logstr; + size_t count(0); count = count_tuples(paths); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No paths found"; + notice << "No paths found"; *log_msg = pgr_msg(notice.str().c_str()); return; } (*return_tuples) = pgr_alloc(count, (*return_tuples)); - log << "\nConverting a set of paths into the tuples"; (*return_count) = (collapse_paths(return_tuples, paths)); *log_msg = log.str().empty()? @@ -184,6 +155,9 @@ do_pgr_bellman_ford( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/bellman_ford/bellman_ford_neg.c b/src/bellman_ford/bellman_ford_neg.c index 8bae728b8f1..d5c9f1fe4b5 100644 --- a/src/bellman_ford/bellman_ford_neg.c +++ b/src/bellman_ford/bellman_ford_neg.c @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: bellman_ford.c +File: bellman_ford_neg.c Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -31,13 +31,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" +#include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - -#include "drivers/bellman_ford/bellman_ford_neg_driver.h" // the link to the C++ code of the function +#include "drivers/bellman_ford/bellman_ford_neg_driver.h" PGDLLEXPORT Datum _pgr_bellmanfordneg(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_bellmanfordneg); @@ -59,78 +57,16 @@ process( char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - - PGR_DBG("Initializing arrays"); - - size_t size_start_vidsArr = 0; - int64_t* start_vidsArr = NULL; - - size_t size_end_vidsArr = 0; - int64_t* end_vidsArr = NULL; - - size_t total_combinations = 0; - II_t_rt *combinations = NULL; - - if (starts && ends) { - start_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_start_vidsArr, starts, false); - end_vidsArr = (int64_t*) - pgr_get_bigIntArray(&size_end_vidsArr, ends, false); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - if (total_combinations == 0) { - if (combinations) - pfree(combinations); - pgr_SPI_finish(); - return; - } - } - (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *positive_edges = NULL; - size_t total_positive_edges = 0; - - pgr_get_edges(edges_sql, &positive_edges, &total_positive_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG( - "Total positive weighted edges in query: %ld", - total_positive_edges); - - Edge_t *negative_edges = NULL; - size_t total_negative_edges = 0; - - pgr_get_edges(neg_edges_sql, &negative_edges, &total_negative_edges, true, false, &err_msg); - throw_error(err_msg, neg_edges_sql); - PGR_DBG( - "Total negative weighted edges in query: %ld", - total_negative_edges); - - size_t total_edges = total_positive_edges + total_negative_edges; - - if (total_edges == 0) { - if (end_vidsArr) pfree(end_vidsArr); - if (start_vidsArr) pfree(start_vidsArr); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_bellman_ford_neg( - positive_edges, - total_positive_edges, - negative_edges, - total_negative_edges, - combinations, - total_combinations, - start_vidsArr, - size_start_vidsArr, - end_vidsArr, - size_end_vidsArr, + pgr_do_bellman_ford_neg( + edges_sql, + neg_edges_sql, + combinations_sql, + starts, ends, + directed, only_cost, @@ -142,42 +78,31 @@ process( &err_msg); time_msg(" processing pgr_bellman_ford", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); - if (err_msg) { - if (*result_tuples) pfree(*result_tuples); + if (err_msg && (*result_tuples)) { + pfree(*result_tuples); + (*result_tuples) = NULL; + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (positive_edges) pfree(positive_edges); - if (negative_edges) pfree(negative_edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (end_vidsArr) pfree(end_vidsArr); - if (start_vidsArr) pfree(start_vidsArr); pgr_SPI_finish(); } - -PGDLLEXPORT Datum _pgr_bellmanfordneg(PG_FUNCTION_ARGS) { +PGDLLEXPORT Datum +_pgr_bellmanfordneg(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; - TupleDesc tuple_desc; + TupleDesc tuple_desc; - /**************************************************************************/ Path_rt *result_tuples = NULL; size_t result_count = 0; - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - PGR_DBG("Calling process"); if (PG_NARGS() == 6) { /* * many to many @@ -208,9 +133,6 @@ PGDLLEXPORT Datum _pgr_bellmanfordneg(PG_FUNCTION_ARGS) { &result_count); } - - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) @@ -235,30 +157,19 @@ PGDLLEXPORT Datum _pgr_bellmanfordneg(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - /**********************************************************************/ - /* - OUT seq 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 - */ - /**********************************************************************/ size_t numb = 8; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); - size_t i; for (i = 0; i < numb; ++i) { nulls[i] = false; } - values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq); + int64_t seq = funcctx->call_cntr == 0? 1 : result_tuples[funcctx->call_cntr - 1].start_id; + + values[0] = Int32GetDatum(funcctx->call_cntr + 1); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id); values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id); values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); @@ -266,18 +177,12 @@ PGDLLEXPORT Datum _pgr_bellmanfordneg(PG_FUNCTION_ARGS) { values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ + result_tuples[funcctx->call_cntr].start_id = result_tuples[funcctx->call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/bellman_ford/bellman_ford_neg_driver.cpp b/src/bellman_ford/bellman_ford_neg_driver.cpp index 95ee2963fbf..200946d1054 100644 --- a/src/bellman_ford/bellman_ford_neg_driver.cpp +++ b/src/bellman_ford/bellman_ford_neg_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: bellman_ford_driver.cpp +File: bellman_ford_neg_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -34,62 +34,43 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include +#include -#include "bellman_ford/pgr_bellman_ford.hpp" +#include "bellman_ford/bellman_ford.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "c_types/ii_t_rt.h" -/* Bellman Ford Shortest Path */ -/************************************************************ - EDGE_SQL, - ANYARRAY, - ANYARRAY, - directed BOOLEAN DEFAULT true, - ***********************************************************/ namespace { -template < class G > + + +template std::deque -pgr_bellman_ford( +bellman_ford( G &graph, - std::vector &combinations, - std::vector < int64_t > sources, - std::vector < int64_t > targets, - std::string &log, + const std::map> &combinations, bool only_cost = false) { - std::sort(sources.begin(), sources.end()); - sources.erase( - std::unique(sources.begin(), sources.end()), - sources.end()); - - std::sort(targets.begin(), targets.end()); - targets.erase( - std::unique(targets.begin(), targets.end()), - targets.end()); - - pgrouting::Pgr_bellman_ford< G > fn_bellman_ford; - auto paths = combinations.empty() ? - fn_bellman_ford.bellman_ford(graph, sources, targets, only_cost) - : fn_bellman_ford.bellman_ford(graph, combinations, only_cost); - log += fn_bellman_ford.get_log(); + pgrouting::Pgr_bellman_ford fn_bellman_ford; + auto paths = fn_bellman_ford.bellman_ford(graph, combinations, only_cost); + for (auto &p : paths) p.recalculate_agg_cost(); return paths; } } // namespace void -do_pgr_bellman_ford_neg( - Edge_t *positive_edges, - size_t total_positive_edges, - Edge_t *negative_edges, - size_t total_negative_edges, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, +pgr_do_bellman_ford_neg( + char *edges_sql, + char *neg_edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, + bool directed, bool only_cost, @@ -102,78 +83,71 @@ do_pgr_bellman_ford_neg( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { - size_t total_edges = total_positive_edges + total_negative_edges; pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - pgassert(total_positive_edges || total_negative_edges); - pgassert((start_vidsArr && end_vidsArr) || combinations); - pgassert((size_start_vidsArr && size_end_vidsArr) || total_combinations); - graphType gType = directed? DIRECTED: UNDIRECTED; - log << "Inserting vertices into a c++ vector structure"; - std::vector - start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr); - std::vector< int64_t > - end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr); - std::vector< II_t_rt > - combinations_vector(combinations, combinations + total_combinations); + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } - std::deque< Path >paths; - std::string logstr; + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + + hint = neg_edges_sql; + auto neg_edges = get_edges(std::string(neg_edges_sql), true, false); + + if (edges.size() + neg_edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + std::deque paths; if (directed) { - log << "Working with directed Graph\n"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(positive_edges, total_positive_edges); - digraph.insert_negative_edges(negative_edges, total_negative_edges); - log << digraph; - paths = pgr_bellman_ford(digraph, - combinations_vector, - start_vertices, - end_vertices, - logstr, - only_cost); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); + digraph.insert_negative_edges(neg_edges); + paths = bellman_ford(digraph, combinations, only_cost); } else { - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(positive_edges, total_positive_edges); - undigraph.insert_negative_edges( - negative_edges, - total_negative_edges); - log << undigraph; - paths = pgr_bellman_ford( - undigraph, - combinations_vector, - start_vertices, - end_vertices, - logstr, - only_cost); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); + undigraph.insert_negative_edges(neg_edges); + paths = bellman_ford(undigraph, combinations, only_cost); } - log<< logstr; + size_t count(0); count = count_tuples(paths); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No paths found"; + notice << "No paths found"; *log_msg = pgr_msg(notice.str().c_str()); return; } (*return_tuples) = pgr_alloc(count, (*return_tuples)); - log << "\nConverting a set of paths into the tuples"; (*return_count) = (collapse_paths(return_tuples, paths)); *log_msg = log.str().empty()? @@ -188,6 +162,9 @@ do_pgr_bellman_ford_neg( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/bellman_ford/edwardMoore.c b/src/bellman_ford/edwardMoore.c index ca7cd5c8f44..929dacf36d6 100644 --- a/src/bellman_ford/edwardMoore.c +++ b/src/bellman_ford/edwardMoore.c @@ -35,9 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - #include "drivers/bellman_ford/edwardMoore_driver.h" PGDLLEXPORT Datum _pgr_edwardmoore(PG_FUNCTION_ARGS); @@ -57,63 +54,14 @@ process( char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - - PGR_DBG("Initializing arrays"); - - size_t size_start_vidsArr = 0; - int64_t *start_vidsArr = NULL; - - size_t size_end_vidsArr = 0; - int64_t *end_vidsArr = NULL; - - size_t total_combinations = 0; - II_t_rt *combinations = NULL; - - if (starts && ends) { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - if (total_combinations == 0) { - if (combinations) - pfree(combinations); - pgr_SPI_finish(); - return; - } - } - (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - if (start_vidsArr) - pfree(start_vidsArr); - if (end_vidsArr) - pfree(end_vidsArr); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_edwardMoore( - edges, - total_edges, - combinations, - total_combinations, - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, + pgr_do_edwardMoore( + edges_sql, + combinations_sql, + starts, ends, directed, @@ -125,28 +73,15 @@ process( &err_msg); time_msg(" processing pgr_edwardMoore", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); - if (err_msg) { - if (*result_tuples) - pfree(*result_tuples); + if (err_msg && (*result_tuples)) { + pfree(*result_tuples); + (*result_tuples) = NULL; + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) - pfree(edges); - if (log_msg) - pfree(log_msg); - if (notice_msg) - pfree(notice_msg); - if (err_msg) - pfree(err_msg); - - if (start_vidsArr) - pfree(start_vidsArr); - if (end_vidsArr) - pfree(end_vidsArr); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); + pgr_SPI_finish(); } @@ -154,17 +89,14 @@ PGDLLEXPORT Datum _pgr_edwardmoore(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ Path_rt *result_tuples = NULL; size_t result_count = 0; - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - PGR_DBG("Calling process"); if (PG_NARGS() == 4) { /* * many to many @@ -192,9 +124,6 @@ PGDLLEXPORT Datum _pgr_edwardmoore(PG_FUNCTION_ARGS) { &result_count); } - - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) { @@ -218,18 +147,6 @@ PGDLLEXPORT Datum _pgr_edwardmoore(PG_FUNCTION_ARGS) { Datum *values; bool *nulls; - /**********************************************************************/ - /* - OUT seq BIGINT, - OUT path_seq BIGINT, - OUT start_vid BIGINT, - OUT end_vid BIGINT, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT - */ - /**********************************************************************/ size_t numb = 8; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -239,8 +156,10 @@ PGDLLEXPORT Datum _pgr_edwardmoore(PG_FUNCTION_ARGS) { nulls[i] = false; } - values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq); + int64_t seq = funcctx->call_cntr == 0? 1 : result_tuples[funcctx->call_cntr - 1].start_id; + + values[0] = Int32GetDatum((int32_t) funcctx->call_cntr + 1); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id); values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id); values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); @@ -248,18 +167,12 @@ PGDLLEXPORT Datum _pgr_edwardmoore(PG_FUNCTION_ARGS) { values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ + result_tuples[funcctx->call_cntr].start_id = result_tuples[funcctx->call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/bellman_ford/edwardMoore_driver.cpp b/src/bellman_ford/edwardMoore_driver.cpp index 8dc08daa605..19052122056 100644 --- a/src/bellman_ford/edwardMoore_driver.cpp +++ b/src/bellman_ford/edwardMoore_driver.cpp @@ -34,60 +34,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include - +#include +#include #include -#include -#include -#include -#include "bellman_ford/pgr_edwardMoore.hpp" +#include "bellman_ford/edwardMoore.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/base_graph.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "c_types/ii_t_rt.h" namespace { -template < class G > -std::deque< pgrouting::Path > -pgr_edwardMoore( + +template +std::deque +edwardMoore( G &graph, - std::vector &combinations, - std::vector < int64_t > sources, - std::vector < int64_t > targets) { - std::sort(sources.begin(), sources.end()); - sources.erase( - std::unique(sources.begin(), sources.end()), - sources.end()); - - std::sort(targets.begin(), targets.end()); - targets.erase( - std::unique(targets.begin(), targets.end()), - targets.end()); - - pgrouting::functions::Pgr_edwardMoore< G > fn_edwardMoore; - auto paths = combinations.empty() ? - fn_edwardMoore.edwardMoore(graph, sources, targets) - : fn_edwardMoore.edwardMoore(graph, combinations); - - return paths; + const std::map> &combinations) { + pgrouting::functions::Pgr_edwardMoore fn_edwardMoore; + return fn_edwardMoore.edwardMoore(graph, combinations); } } // namespace void -do_pgr_edwardMoore( - Edge_t *data_edges, - size_t total_edges, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, +pgr_do_edwardMoore( + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, + bool directed, Path_rt **return_tuples, @@ -99,53 +81,52 @@ do_pgr_edwardMoore( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(data_edges); - pgassert((start_vidsArr && end_vidsArr) || combinations); - pgassert((size_start_vidsArr && size_end_vidsArr) || total_combinations); - graphType gType = directed? DIRECTED: UNDIRECTED; - log << "Inserting vertices into a c++ vector structure"; - std::vector - start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr); - std::vector< int64_t > - end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr); - std::vector< II_t_rt > - combinations_vector(combinations, combinations + total_combinations); + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - std::deque< Path >paths; + std::deque paths; if (directed) { - log << "\nWorking with directed Graph"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); - paths = pgr_edwardMoore( - digraph, - combinations_vector, - start_vertices, - end_vertices); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); + paths = edwardMoore(digraph, combinations); } else { - log << "\nWorking with Undirected Graph"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); - - paths = pgr_edwardMoore( - undigraph, - combinations_vector, - start_vertices, - end_vertices); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); + paths = edwardMoore(undigraph, combinations); } size_t count(0); @@ -154,14 +135,12 @@ do_pgr_edwardMoore( if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No paths found"; + notice << "No paths found"; *log_msg = pgr_msg(notice.str().c_str()); return; } (*return_tuples) = pgr_alloc(count, (*return_tuples)); - log << "\nConverting a set of paths into the tuples"; (*return_count) = (collapse_paths(return_tuples, paths)); *log_msg = log.str().empty()? @@ -176,6 +155,9 @@ do_pgr_edwardMoore( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/breadthFirstSearch/CMakeLists.txt b/src/breadthFirstSearch/CMakeLists.txt index 0a86985f740..f7c64f82349 100644 --- a/src/breadthFirstSearch/CMakeLists.txt +++ b/src/breadthFirstSearch/CMakeLists.txt @@ -2,5 +2,5 @@ ADD_LIBRARY(breadthFirstSearch OBJECT breadthFirstSearch.c breadthFirstSearch_driver.cpp binaryBreadthFirstSearch.c - binaryBreadthFirstSearch_driver.cpp + binaryBreadthFirstSearch_driver.cpp ) diff --git a/src/breadthFirstSearch/binaryBreadthFirstSearch.c b/src/breadthFirstSearch/binaryBreadthFirstSearch.c index fa4ec4da49a..e8a5734a290 100644 --- a/src/breadthFirstSearch/binaryBreadthFirstSearch.c +++ b/src/breadthFirstSearch/binaryBreadthFirstSearch.c @@ -35,9 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - #include "drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h" PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS); @@ -57,63 +54,14 @@ process( char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - - PGR_DBG("Initializing arrays"); - - size_t size_start_vidsArr = 0; - int64_t *start_vidsArr = NULL; - - size_t size_end_vidsArr = 0; - int64_t *end_vidsArr = NULL; - - size_t total_combinations = 0; - II_t_rt *combinations = NULL; - - if (starts && ends) { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - if (total_combinations == 0) { - if (combinations) - pfree(combinations); - pgr_SPI_finish(); - return; - } - } - (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - if (start_vidsArr) - pfree(start_vidsArr); - if (end_vidsArr) - pfree(end_vidsArr); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_binaryBreadthFirstSearch( - edges, - total_edges, - combinations, - total_combinations, - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, + pgr_do_binaryBreadthFirstSearch( + edges_sql, + combinations_sql, + starts, ends, directed, @@ -125,54 +73,29 @@ process( &err_msg); time_msg(" processing pgr_binaryBreadthFirstSearch", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); - if (err_msg) { - if (*result_tuples) - pfree(*result_tuples); + if (err_msg && (*result_tuples)) { + pfree(*result_tuples); + (*result_tuples) = NULL; + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) - pfree(edges); - if (log_msg) - pfree(log_msg); - if (notice_msg) - pfree(notice_msg); - if (err_msg) - pfree(err_msg); - - if (start_vidsArr) - pfree(start_vidsArr); - if (end_vidsArr) - pfree(end_vidsArr); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); + pgr_SPI_finish(); } PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - - /**************************************************************************/ Path_rt *result_tuples = NULL; size_t result_count = 0; - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - // pgr_binaryBreadthFirstSearch( - // sql TEXT, - // start_vids ANYARRAY, - // end_vids ANYARRAY, - // directed BOOLEAN default true, - - PGR_DBG("Calling process"); - if (PG_NARGS() == 4) { /* * many to many @@ -200,9 +123,6 @@ PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) { &result_count); } - - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -227,18 +147,6 @@ PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) { Datum *values; bool *nulls; - /**********************************************************************/ - /* - OUT seq BIGINT, - OUT path_seq BIGINT, - OUT start_vid BIGINT, - OUT end_vid BIGINT, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT - */ - /**********************************************************************/ size_t numb = 8; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -248,8 +156,10 @@ PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) { nulls[i] = false; } + int64_t seq = funcctx->call_cntr == 0? 1 : result_tuples[funcctx->call_cntr - 1].start_id; + values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id); values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id); values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); @@ -257,18 +167,12 @@ PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) { values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ + result_tuples[funcctx->call_cntr].start_id = result_tuples[funcctx->call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp b/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp index 5fed2418f3f..d2a0d9fa77d 100644 --- a/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp +++ b/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp @@ -36,14 +36,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp" +#include "breadthFirstSearch/binaryBreadthFirstSearch.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" namespace { +#if 0 template < class G > std::deque pgr_binaryBreadthFirstSearch( @@ -72,12 +76,15 @@ pgr_binaryBreadthFirstSearch( const size_t MAX_UNIQUE_EDGE_COSTS = 2; const char COST_ERR_MSG[] = "Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs! " "If there are exactly two distinct edge costs, one of them must equal zero!"; +#endif + template < class G > bool costCheck(G &graph) { typedef typename G::E E; typedef typename G::E_i E_i; + const size_t max_unique_edge_costs = 2; auto edges = boost::edges(graph.graph); E e; E_i out_i; @@ -88,7 +95,7 @@ costCheck(G &graph) { e = *out_i; cost_set.insert(graph[e].cost); - if (cost_set.size() > MAX_UNIQUE_EDGE_COSTS) { + if (cost_set.size() > max_unique_edge_costs) { return false; } } @@ -102,19 +109,24 @@ costCheck(G &graph) { return true; } +template std::deque binaryBreadthFirstSearch( + G &graph, + std::map> &combinations) { + pgrouting::functions::Pgr_binaryBreadthFirstSearch< G > fn_binaryBreadthFirstSearch; + auto paths = fn_binaryBreadthFirstSearch.binaryBreadthFirstSearch(graph, combinations); + + return paths; +} + } // namespace void -do_pgr_binaryBreadthFirstSearch( - Edge_t *data_edges, - size_t total_edges, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, +pgr_do_binaryBreadthFirstSearch( + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, bool directed, Path_rt **return_tuples, @@ -126,65 +138,68 @@ do_pgr_binaryBreadthFirstSearch( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + const char c_err_msg[] = "Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs! " + "If there are exactly two distinct edge costs, one of them must equal zero!"; try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(data_edges); - pgassert((start_vidsArr && end_vidsArr) || combinations); - pgassert((size_start_vidsArr && size_end_vidsArr) || total_combinations); - graphType gType = directed? DIRECTED: UNDIRECTED; - // log << "Inserting vertices into a c++ vector structure"; - std::vector - start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr); - std::vector< int64_t > - end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr); - std::vector< II_t_rt > - combinations_vector(combinations, combinations + total_combinations); + + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } std::deque< Path >paths; if (directed) { - // log << "\nWorking with directed Graph"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); if (!(costCheck(digraph))) { - err << COST_ERR_MSG; + err << c_err_msg; *err_msg = pgr_msg(err.str().c_str()); return; } - paths = pgr_binaryBreadthFirstSearch( - digraph, - combinations_vector, - start_vertices, - end_vertices); + paths = binaryBreadthFirstSearch(digraph, combinations); } else { - // log << "\nWorking with Undirected Graph"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); if (!(costCheck(undigraph))) { - err << COST_ERR_MSG; + err << c_err_msg; *err_msg = pgr_msg(err.str().c_str()); return; } - paths = pgr_binaryBreadthFirstSearch( - undigraph, - combinations_vector, - start_vertices, - end_vertices); + paths = binaryBreadthFirstSearch(undigraph, combinations); } size_t count(0); @@ -215,6 +230,9 @@ do_pgr_binaryBreadthFirstSearch( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/breadthFirstSearch/breadthFirstSearch.c b/src/breadthFirstSearch/breadthFirstSearch.c index f47f26a152b..7ed6be67318 100644 --- a/src/breadthFirstSearch/breadthFirstSearch.c +++ b/src/breadthFirstSearch/breadthFirstSearch.c @@ -26,7 +26,7 @@ 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*/ + ********************************************************************PGR-GNU*/ #include #include "c_common/postgres_connection.h" @@ -34,11 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - #include "c_types/mst_rt.h" - #include "drivers/breadthFirstSearch/breadthFirstSearch_driver.h" PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS); @@ -57,39 +53,14 @@ process( char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - - PGR_DBG("Initializing arrays"); - - size_t size_start_vidsArr = 0; - int64_t *start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - PGR_DBG("start_vidsArr size %ld ", size_start_vidsArr); - - (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - if (total_edges == 0) { - if (start_vidsArr) - pfree(start_vidsArr); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_breadthFirstSearch( - edges, - total_edges, - start_vidsArr, size_start_vidsArr, + pgr_do_breadthFirstSearch( + edges_sql, + starts, max_depth, directed, @@ -101,26 +72,15 @@ process( &err_msg); time_msg(" processing pgr_breadthFirstSearch", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); - if (err_msg) { - if (*result_tuples) - pfree(*result_tuples); + if (err_msg && (*result_tuples)) { + pfree(*result_tuples); + (*result_tuples) = NULL; + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (edges) - pfree(edges); - if (log_msg) - pfree(log_msg); - if (notice_msg) - pfree(notice_msg); - if (err_msg) - pfree(err_msg); - - if (start_vidsArr) - pfree(start_vidsArr); pgr_SPI_finish(); } @@ -128,27 +88,14 @@ PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ MST_rt *result_tuples = NULL; size_t result_count = 0; - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - /* - pgr_breadthFirstSearch( - edge_sql TEXT, - start_vids ANYARRAY, - max_depth BIGINT DEFAULT 9223372036854775807, - directed BOOLEAN DEFAULT true) - */ - /**********************************************************************/ - - PGR_DBG("Calling process"); process( text_to_cstring(PG_GETARG_TEXT_P(0)), PG_GETARG_ARRAYTYPE_P(1), @@ -157,10 +104,7 @@ PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) { &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, @@ -183,17 +127,6 @@ PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) { Datum *values; bool *nulls; - /**********************************************************************/ - /* - OUT seq BIGINT, - OUT depth BIGINT, - OUT start_vid BIGINT, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT - */ - /**********************************************************************/ size_t numb = 7; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -211,18 +144,11 @@ PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) { values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/breadthFirstSearch/breadthFirstSearch_driver.cpp b/src/breadthFirstSearch/breadthFirstSearch_driver.cpp index fb75a561a5c..06eb026f2a6 100644 --- a/src/breadthFirstSearch/breadthFirstSearch_driver.cpp +++ b/src/breadthFirstSearch/breadthFirstSearch_driver.cpp @@ -32,40 +32,32 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -#include "breadthFirstSearch/pgr_breadthFirstSearch.hpp" +#include "breadthFirstSearch/breadthFirstSearch.hpp" namespace { -template < class G > -std::vector -pgr_breadthFirstSearch( + +template std::vector breadthFirstSearch( G &graph, - std::vector < int64_t > sources, + std::set sources, int64_t max_depth) { - std::sort(sources.begin(), sources.end()); - sources.erase( - std::unique(sources.begin(), sources.end()), - sources.end()); - - - pgrouting::functions::Pgr_breadthFirstSearch< G > fn_breadthFirstSearch; - auto results = fn_breadthFirstSearch.breadthFirstSearch( - graph, sources, max_depth); + pgrouting::functions::Pgr_breadthFirstSearch fn_breadthFirstSearch; + auto results = fn_breadthFirstSearch.breadthFirstSearch(graph, sources, max_depth); return results; } } // namespace void -do_pgr_breadthFirstSearch( - Edge_t *data_edges, - size_t total_edges, - int64_t *start_vidsArr, - size_t size_start_vidsArr, +pgr_do_breadthFirstSearch( + char *edges_sql, + ArrayType* starts, int64_t max_depth, bool directed, @@ -77,43 +69,46 @@ do_pgr_breadthFirstSearch( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intSet; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { + // NOLINTBEGIN(clang-analyzer-cplusplus.NewDelete) pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); + // NOLINTEND(clang-analyzer-cplusplus.NewDelete) + - graphType gType = directed? DIRECTED: UNDIRECTED; - log << "Inserting vertices into a c++ vector structure"; - std::vector - start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr); + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + auto roots = get_intSet(starts); std::vector results; if (directed) { - log << "Working with directed Graph\n"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); - results = pgr_breadthFirstSearch( - digraph, - start_vertices, - max_depth); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); + results = breadthFirstSearch(digraph, roots, max_depth); } else { - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); - - results = pgr_breadthFirstSearch( - undigraph, - start_vertices, - max_depth); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); + results = breadthFirstSearch(undigraph, roots, max_depth); } auto count = results.size(); @@ -121,20 +116,17 @@ do_pgr_breadthFirstSearch( if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No traversal found"; + notice << "No traversal found"; *log_msg = pgr_msg(notice.str().c_str()); return; } (*return_tuples) = pgr_alloc(count, (*return_tuples)); - log << "\nConverting a set of traversals into the tuples"; + (*return_count) = count; for (size_t i = 0; i < count; i++) { *((*return_tuples) + i) = results[i]; } - (*return_count) = count; - pgassert(*err_msg == NULL); *log_msg = log.str().empty()? *log_msg : pgr_msg(log.str().c_str()); @@ -147,6 +139,9 @@ do_pgr_breadthFirstSearch( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/chinese/chinesePostman.c b/src/chinese/chinesePostman.c index 5e600336be4..4f14167ed56 100644 --- a/src/chinese/chinesePostman.c +++ b/src/chinese/chinesePostman.c @@ -37,7 +37,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/chinese/chinesePostman_driver.h" @@ -45,7 +44,6 @@ PGDLLEXPORT Datum _pgr_chinesepostman(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_chinesepostman); -/******************************************************************************/ static void process( @@ -58,21 +56,9 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); - - do_pgr_directedChPP( - edges, total_edges, + pgr_do_directedChPP( + edges_sql, only_cost, result_tuples, result_count, @@ -87,19 +73,13 @@ process( time_msg(" processing pgr_chinesePostman", start_t, clock()); } - if (edges) pfree(edges); - if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_tuples) = NULL; (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } @@ -109,30 +89,21 @@ PGDLLEXPORT Datum _pgr_chinesepostman(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ Path_rt *result_tuples = NULL; 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)), PG_GETARG_BOOL(1), &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) { @@ -157,11 +128,6 @@ PGDLLEXPORT Datum _pgr_chinesepostman(PG_FUNCTION_ARGS) { bool* nulls; size_t call_cntr = funcctx->call_cntr; - /**********************************************************************/ - /* MODIFY AS NEEDED */ - /* - ***********************************************************************/ - size_t numb = 5; values =(Datum *)palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -176,7 +142,6 @@ PGDLLEXPORT Datum _pgr_chinesepostman(PG_FUNCTION_ARGS) { values[2] = Int64GetDatum(result_tuples[call_cntr].edge); values[3] = Float8GetDatum(result_tuples[call_cntr].cost); values[4] = Float8GetDatum(result_tuples[call_cntr].agg_cost); - /**********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/chinese/chinesePostman_driver.cpp b/src/chinese/chinesePostman_driver.cpp index de4a7afbee1..6685c916277 100644 --- a/src/chinese/chinesePostman_driver.cpp +++ b/src/chinese/chinesePostman_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: directedChPP_driver.cpp +File: chinesePostman_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -33,16 +33,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include // work for only directed -#include "chinese/pgr_chinesePostman.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "chinese/chinesePostman.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" void -do_pgr_directedChPP( - Edge_t *data_edges, size_t total_edges, +pgr_do_directedChPP( + char *edges_sql, bool only_cost, Path_rt **return_tuples, size_t *return_count, @@ -56,16 +58,26 @@ do_pgr_directedChPP( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - pgrouting::graph::PgrDirectedChPPGraph digraph( - data_edges, total_edges); + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + pgrouting::graph::PgrDirectedChPPGraph digraph(edges); double minCost; minCost = digraph.DirectedChPP(); @@ -73,8 +85,7 @@ do_pgr_directedChPP( std::vector pathEdges; if (only_cost) { if (minCost >= 0.0) { - Path_rt edge; - edge.seq = -1; + Path_rt edge = {}; edge.node = edge.edge = -1; edge.cost = edge.agg_cost = minCost; pathEdges.push_back(edge); @@ -83,7 +94,6 @@ do_pgr_directedChPP( pathEdges = digraph.GetPathEdges(); } - size_t count = pathEdges.size(); if (count == 0) { @@ -114,6 +124,9 @@ do_pgr_directedChPP( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/circuits/hawickCircuits.c b/src/circuits/hawickCircuits.c index e6cff0eab37..fd639bba899 100644 --- a/src/circuits/hawickCircuits.c +++ b/src/circuits/hawickCircuits.c @@ -26,10 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -/** @file hawickCircuits.c - * @brief Connecting code with postgres. - * - */ #include #include "c_common/postgres_connection.h" #include "c_types/circuits_rt.h" @@ -37,25 +33,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" -#include "drivers/circuits/hawickcircuits_driver.h" +#include "drivers/circuits/hawickCircuits_driver.h" PGDLLEXPORT Datum _pgr_hawickcircuits(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_hawickcircuits); -/** @brief Static function, loads the data from postgres to C types for further processing. - * - * It first connects the C function to the SPI manager. Then converts - * the postgres array to C array and loads the edges belonging to the graph - * in C types. Then it calls the function `do_cuthillMckeeOrdering` defined - * in the `cuthillMckeeOrdering_driver.h` file for further processing. - * Finally, it frees the memory and disconnects the C function to the SPI manager. - * - * @param edges_sql the edges of the SQL query - * @param result_tuples the rows in the result - * @param result_count the count of rows in the result - */ - static void process( char* edges_sql, @@ -70,27 +52,15 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - do_hawickCircuits( - edges, total_edges, + pgr_do_hawickCircuits( + edges_sql, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg("processing hawickCircuits", start_t, clock()); if (err_msg && (*result_tuples)) { @@ -99,42 +69,23 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ - -/** @brief Helps in converting postgres variables to C variables, and returns the result. - * - */ PGDLLEXPORT Datum _pgr_hawickcircuits(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ circuits_rt *result_tuples = NULL; size_t result_count = 0; - /**********************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /*********************************************************************** - * - * pgr_hawickCircuits(edges_sql TEXT); - * - **********************************************************************/ - process( text_to_cstring(PG_GETARG_TEXT_P(0)), &result_tuples, @@ -185,20 +136,6 @@ PGDLLEXPORT Datum _pgr_hawickcircuits(PG_FUNCTION_ARGS) { values[7] = Float8GetDatum(result_tuples[call_cntr].cost); values[8] = Float8GetDatum(result_tuples[call_cntr].agg_cost); - /*********************************************************************** - * - * OUT seq INTEGER, - * OUT path_id INTEGER, - * OUT path_seq INTEGER, - * OUT start_vid BIGINT, - * OUT end_vid BIGINT, - * OUT node BIGINT, - * OUT edge FLOAT, - * OUT cost FLOAT, - * OUT agg_cost FLOAT - * - **********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); diff --git a/src/circuits/hawickCircuits_driver.cpp b/src/circuits/hawickCircuits_driver.cpp index b53265d6b40..b506deee1bb 100644 --- a/src/circuits/hawickCircuits_driver.cpp +++ b/src/circuits/hawickCircuits_driver.cpp @@ -28,20 +28,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ +#include "drivers/circuits/hawickCircuits_driver.h" #include #include #include #include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" - -#include "drivers/circuits/hawickcircuits_driver.h" #include "circuits/hawickcircuits.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -/** @file hawickCircuits_driver.cpp */ - +namespace { /** @brief Calls the main function defined in the C++ Header file. * @@ -57,33 +56,11 @@ pgr_hawickCircuits(G &graph) { auto results = fn_hawickCircuits.hawickCircuits(graph); return results; } - -/** @brief Performs exception handling and converts the results to postgres. - * - * @pre log_msg is empty - * @pre notice_msg is empty - * @pre err_msg is empty - * @pre return_tuples is empty - * @pre return_count is 0 - * - * It builds the undirected graph using the `data_edges` variable. - * Then, it passes the required variables to the template function - * `cuthillMckeeOrdering` which calls the main function - * defined in the C++ Header file. It also does exception handling. - * - * @param data_edges the set of edges from the SQL query - * @param total_edges the total number of edges in the SQL query - * @param return_tuples the rows in the result - * @param return_count the count of rows in the result - * @param log_msg stores the log message - * @param notice_msg stores the notice message - * @param err_msg stores the error message - */ +} // namespace void -do_hawickCircuits( - Edge_t *data_edges, - size_t total_edges, +pgr_do_hawickCircuits( + char *edges_sql, circuits_rt **return_tuples, size_t *return_count, @@ -99,20 +76,28 @@ do_hawickCircuits( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); - pgassert(total_edges != 0); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - std::deque < circuits_rt > results; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - graphType gType = DIRECTED; - pgrouting::DirectedGraph digraph(gType); + std::deque results; - digraph.insert_edges(data_edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); results = pgr_hawickCircuits(digraph); @@ -145,6 +130,9 @@ do_hawickCircuits( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/coloring/CMakeLists.txt b/src/coloring/CMakeLists.txt index 50ca5613c77..e46b889efc3 100644 --- a/src/coloring/CMakeLists.txt +++ b/src/coloring/CMakeLists.txt @@ -5,5 +5,5 @@ ADD_LIBRARY(coloring OBJECT bipartite_driver.cpp edgeColoring.c edgeColoring_driver.cpp - pgr_edgeColoring.cpp + edgeColoring.cpp ) diff --git a/src/coloring/bipartite.c b/src/coloring/bipartite.c index 4f575e5dfee..610ed45c1a7 100644 --- a/src/coloring/bipartite.c +++ b/src/coloring/bipartite.c @@ -28,8 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -/******************************************************************************/ - #include #include "c_common/postgres_connection.h" @@ -38,7 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/coloring/bipartite_driver.h" @@ -56,24 +53,14 @@ process(char* edges_sql, char* notice_msg = NULL; char* err_msg = NULL; - size_t total_edges = 0; - Edge_t* edges = NULL; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - PGR_DBG("Starting timer"); clock_t start_t = clock(); - do_pgr_bipartite( - edges, total_edges, + pgr_do_bipartite( + edges_sql, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg("processing pgr_bipartite()", start_t, clock()); @@ -83,12 +70,8 @@ process(char* edges_sql, (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); pgr_SPI_finish(); } diff --git a/src/coloring/bipartite_driver.cpp b/src/coloring/bipartite_driver.cpp index 61f8e846b54..66f1f779eb1 100644 --- a/src/coloring/bipartite_driver.cpp +++ b/src/coloring/bipartite_driver.cpp @@ -28,31 +28,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -/************************************************************ - edges_sql TEXT - ***********************************************************/ - #include #include #include #include #include +#include "cpp_common/pgdata_getters.hpp" #include "c_types/ii_t_rt.h" #include "cpp_common/identifiers.hpp" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/alloc.hpp" #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/base_graph.hpp" #include "drivers/coloring/bipartite_driver.h" -#include "coloring/pgr_bipartite_driver.hpp" +#include "coloring/bipartite_driver.hpp" -/************************************************************ - edges_sql TEXT - ***********************************************************/ void -do_pgr_bipartite( - Edge_t *data_edges, - size_t total_edges, +pgr_do_bipartite( + char *edges_sql, + II_t_rt **return_tuples, size_t *return_count, char **log_msg, @@ -65,20 +59,30 @@ do_pgr_bipartite( std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; try { - pgassert(total_edges != 0); + // NOLINTBEGIN(clang-analyzer-cplusplus.NewDelete) pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); + // NOLINTEND(clang-analyzer-cplusplus.NewDelete) + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; std::string logstr; - graphType gType = UNDIRECTED; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); std::vector results; pgrouting::functions::Pgr_Bipartite fn_Bipartite; results = fn_Bipartite.pgr_bipartite(undigraph); @@ -115,6 +119,9 @@ do_pgr_bipartite( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/coloring/edgeColoring.c b/src/coloring/edgeColoring.c index 618220cf24f..4020600e86b 100644 --- a/src/coloring/edgeColoring.c +++ b/src/coloring/edgeColoring.c @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/ii_t_rt.h" #include "drivers/coloring/edgeColoring_driver.h" @@ -46,18 +45,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. PGDLLEXPORT Datum _pgr_edgecoloring(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_edgecoloring); -/** @brief Static function, loads the data from postgres to C types for further processing. - * - * It first connects the C function to the SPI manager. Then converts - * the postgres array to C array and loads the edges belonging to the graph - * in C types. Then it calls the function `do_pgr_edgeColoring` defined - * in the `edgeColoring_driver.h` file for further processing. - * Finally, it frees the memory and disconnects the C function to the SPI manager. - * - * @param edges_sql the edges of the SQL query - * @param result_tuples the rows in the result - * @param result_count the count of rows in the result - */ static void @@ -74,33 +61,15 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - ereport(WARNING, - (errmsg("Insufficient data found on inner query."), - errhint("%s", edges_sql))); - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); - - do_pgr_edgeColoring( - edges, total_edges, + pgr_do_edgeColoring( + edges_sql, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg("processing pgr_edgeColoring", start_t, clock()); if (err_msg && (*result_tuples)) { @@ -109,50 +78,28 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ - -/** @brief Helps in converting postgres variables to C variables, and returns the result. - * - */ - PGDLLEXPORT Datum _pgr_edgecoloring(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ II_t_rt *result_tuples = NULL; size_t result_count = 0; - /**********************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /*********************************************************************** - * - * pgr_edgeColoring(edges_sql TEXT); - * - **********************************************************************/ - process( text_to_cstring(PG_GETARG_TEXT_P(0)), &result_tuples, &result_count); - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -178,13 +125,6 @@ PGDLLEXPORT Datum _pgr_edgecoloring(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - /*********************************************************************** - * - * OUT edge BIGINT - * OUT color BIGINT - * - **********************************************************************/ - size_t num = 3; values = palloc(num * sizeof(Datum)); nulls = palloc(num * sizeof(bool)); @@ -198,8 +138,6 @@ PGDLLEXPORT Datum _pgr_edgecoloring(PG_FUNCTION_ARGS) { values[0] = Int64GetDatum(result_tuples[funcctx->call_cntr].d1.id); values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].d2.value); - /**********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); diff --git a/src/coloring/pgr_edgeColoring.cpp b/src/coloring/edgeColoring.cpp similarity index 89% rename from src/coloring/pgr_edgeColoring.cpp rename to src/coloring/edgeColoring.cpp index 17ef2764a5b..35ff877b0e5 100644 --- a/src/coloring/pgr_edgeColoring.cpp +++ b/src/coloring/edgeColoring.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_edgeColoring.cpp +File: edgeColoring.cpp Generated with Template by: Copyright (c) 2021 pgRouting developers @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "coloring/pgr_edgeColoring.hpp" +#include "coloring/edgeColoring.hpp" #include #include @@ -36,8 +36,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_assert.h" -#include "cpp_common/interruption.h" +#include "cpp_common/assert.hpp" +#include "cpp_common/interruption.hpp" namespace pgrouting { @@ -65,15 +65,14 @@ Pgr_edgeColoring::edgeColoring() { return results; } -Pgr_edgeColoring::Pgr_edgeColoring(Edge_t *edges, - size_t total_edges) { +Pgr_edgeColoring::Pgr_edgeColoring(const std::vector &edges) { /* * Inserting vertices */ Identifiers ids; - for (size_t i = 0; i < total_edges; ++i) { - ids += edges[i].source; - ids += edges[i].target; + for (const auto &e : edges) { + ids += e.source; + ids += e.target; } for (const auto id : ids) { @@ -86,11 +85,11 @@ Pgr_edgeColoring::Pgr_edgeColoring(Edge_t *edges, * Inserting edges */ bool added; - for (size_t i = 0; i < total_edges; ++i) { - auto edge = edges[i]; + for (const auto &edge : edges) { auto v1 = get_boost_vertex(edge.source); auto v2 = get_boost_vertex(edge.target); auto e_exists = boost::edge(v1, v2, graph); + // NOLINTNEXTLINE if (e_exists.second) continue; if (edge.source == edge.target) continue; @@ -98,6 +97,7 @@ Pgr_edgeColoring::Pgr_edgeColoring(Edge_t *edges, if (edge.cost < 0 && edge.reverse_cost < 0) continue; E e; + // NOLINTNEXTLINE boost::tie(e, added) = boost::add_edge(v1, v2, graph); E_to_id.insert(std::make_pair(e, edge.id)); diff --git a/src/coloring/edgeColoring_driver.cpp b/src/coloring/edgeColoring_driver.cpp index e0871bb1c9a..a69188ad683 100644 --- a/src/coloring/edgeColoring_driver.cpp +++ b/src/coloring/edgeColoring_driver.cpp @@ -29,20 +29,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "drivers/coloring/edgeColoring_driver.h" #include +#include -#include "coloring/pgr_edgeColoring.hpp" +#include "coloring/edgeColoring.hpp" -#include "c_types/graph_enum.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -/************************************************************ - edges_sql TEXT - ***********************************************************/ - -void do_pgr_edgeColoring( - Edge_t *data_edges, - size_t total_edges, +void pgr_do_edgeColoring( + char *edges_sql, II_t_rt **return_tuples, size_t *return_count, @@ -57,6 +53,8 @@ void do_pgr_edgeColoring( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); @@ -64,9 +62,19 @@ void do_pgr_edgeColoring( pgassert(!(*return_tuples)); pgassert(*return_count == 0); + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + std::vector results; - pgrouting::functions::Pgr_edgeColoring fn_edgeColoring {data_edges, total_edges}; + pgrouting::functions::Pgr_edgeColoring fn_edgeColoring(edges); results = fn_edgeColoring.edgeColoring(); @@ -95,6 +103,9 @@ void do_pgr_edgeColoring( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/coloring/sequentialVertexColoring.c b/src/coloring/sequentialVertexColoring.c index 3d266bfbd52..72e5c0427b0 100644 --- a/src/coloring/sequentialVertexColoring.c +++ b/src/coloring/sequentialVertexColoring.c @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/ii_t_rt.h" @@ -47,18 +46,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. PGDLLEXPORT Datum _pgr_sequentialvertexcoloring(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_sequentialvertexcoloring); -/** @brief Static function, loads the data from postgres to C types for further processing. - * - * It first connects the C function to the SPI manager. Then converts - * the postgres array to C array and loads the edges belonging to the graph - * in C types. Then it calls the function `do_pgr_sequentialVertexColoring` defined - * in the `sequentialVertexColoring_driver.h` file for further processing. - * Finally, it frees the memory and disconnects the C function to the SPI manager. - * - * @param edges_sql the edges of the SQL query - * @param result_tuples the rows in the result - * @param result_count the count of rows in the result - */ static void process( @@ -74,22 +61,15 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - clock_t start_t = clock(); - do_pgr_sequentialVertexColoring( - edges, total_edges, + pgr_do_sequentialVertexColoring( + edges_sql, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg("processing pgr_sequentialVertexColoring", start_t, clock()); if (err_msg && (*result_tuples)) { @@ -98,50 +78,28 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ - -/** @brief Helps in converting postgres variables to C variables, and returns the result. - * - */ PGDLLEXPORT Datum _pgr_sequentialvertexcoloring(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ II_t_rt *result_tuples = NULL; size_t result_count = 0; - /**********************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /*********************************************************************** - * - * pgr_sequentialVertexColoring(edges_sql TEXT); - * - **********************************************************************/ - process( text_to_cstring(PG_GETARG_TEXT_P(0)), &result_tuples, &result_count); - /**********************************************************************/ - - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -167,13 +125,6 @@ PGDLLEXPORT Datum _pgr_sequentialvertexcoloring(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - /*********************************************************************** - * - * OUT node BIGINT, - * OUT color BIGINT, - * - **********************************************************************/ - size_t num = 2; values = palloc(num * sizeof(Datum)); nulls = palloc(num * sizeof(bool)); @@ -187,8 +138,6 @@ PGDLLEXPORT Datum _pgr_sequentialvertexcoloring(PG_FUNCTION_ARGS) { values[0] = Int64GetDatum(result_tuples[funcctx->call_cntr].d1.id); values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].d2.value); - /**********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); diff --git a/src/coloring/sequentialVertexColoring_driver.cpp b/src/coloring/sequentialVertexColoring_driver.cpp index 677d8aaef77..40cb7908daa 100644 --- a/src/coloring/sequentialVertexColoring_driver.cpp +++ b/src/coloring/sequentialVertexColoring_driver.cpp @@ -33,23 +33,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -#include "coloring/pgr_sequentialVertexColoring.hpp" +#include "coloring/sequentialVertexColoring.hpp" /** @file sequentialVertexColoring_driver.cpp */ namespace { -/** @brief Calls the main function defined in the C++ Header file. - * - * @param graph the graph containing the edges - * - * @returns results, when results are found - */ - template < class G > std::vector pgr_sequentialVertexColoring(G &graph) { @@ -60,32 +54,9 @@ pgr_sequentialVertexColoring(G &graph) { } // namespace -/** @brief Performs exception handling and converts the results to postgres. - * - * @pre log_msg is empty - * @pre notice_msg is empty - * @pre err_msg is empty - * @pre return_tuples is empty - * @pre return_count is 0 - * - * It builds the undirected graph using the `data_edges` variable. - * Then, it passes the required variables to the template function - * `pgr_sequentialVertexColoring` which calls the main function - * defined in the C++ Header file. It also does exception handling. - * - * @param data_edges the set of edges from the SQL query - * @param total_edges the total number of edges in the SQL query - * @param return_tuples the rows in the result - * @param return_count the count of rows in the result - * @param log_msg stores the log message - * @param notice_msg stores the notice message - * @param err_msg stores the error message - */ - void -do_pgr_sequentialVertexColoring( - Edge_t *data_edges, - size_t total_edges, +pgr_do_sequentialVertexColoring( + char *edges_sql, II_t_rt **return_tuples, size_t *return_count, @@ -100,6 +71,8 @@ do_pgr_sequentialVertexColoring( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); @@ -107,12 +80,20 @@ do_pgr_sequentialVertexColoring( pgassert(!(*return_tuples)); pgassert(*return_count == 0); + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + std::vector results; - graphType gType = UNDIRECTED; - pgrouting::UndirectedGraph undigraph(gType); + pgrouting::UndirectedGraph undigraph; - undigraph.insert_edges(data_edges, total_edges); + undigraph.insert_edges(edges); results = pgr_sequentialVertexColoring(undigraph); @@ -145,6 +126,9 @@ do_pgr_sequentialVertexColoring( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 0d9cce841db..824ad178b02 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -6,7 +6,7 @@ ADD_LIBRARY(common OBJECT check_parameters.c time_msg.c - pgr_assert.cpp + assert.cpp identifier.cpp basic_vertex.cpp @@ -14,5 +14,5 @@ ADD_LIBRARY(common OBJECT ch_vertex.cpp ch_edge.cpp basic_edge.cpp - pgr_alloc.cpp + alloc.cpp ) diff --git a/src/common/pgr_alloc.cpp b/src/common/alloc.cpp similarity index 95% rename from src/common/pgr_alloc.cpp rename to src/common/alloc.cpp index d7b4a75d872..1ff667663ea 100644 --- a/src/common/pgr_alloc.cpp +++ b/src/common/alloc.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_palloc.cpp +File: alloc.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/alloc.hpp" #include #include diff --git a/src/common/pgr_assert.cpp b/src/common/assert.cpp similarity index 97% rename from src/common/pgr_assert.cpp rename to src/common/assert.cpp index 4feea9224c1..cddcae8b895 100644 --- a/src/common/pgr_assert.cpp +++ b/src/common/assert.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: pgr_assert.cpp +File: assert.cpp Copyright (c) 2014 pgRouting developers Mail: project@pgrouting.org @@ -26,7 +25,7 @@ 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 "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" #include #include diff --git a/src/common/basePath_SSEC.cpp b/src/common/basePath_SSEC.cpp index 99636753b67..c2f62c6825c 100644 --- a/src/common/basePath_SSEC.cpp +++ b/src/common/basePath_SSEC.cpp @@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/path_rt.h" #include "c_types/mst_rt.h" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" namespace pgrouting { @@ -216,9 +216,6 @@ void Path::append(const Path &other) { *this = other; return; } -#if 0 - pgassert(path.back().cost == 0); -#endif pgassert(path.back().edge == -1); m_end_id = other.m_end_id; @@ -237,7 +234,6 @@ void Path::append(const Path &other) { void Path::generate_postgres_data( Path_rt **postgres_data, size_t &sequence) const { - int i = 1; for (const auto e : path) { auto agg_cost = std::fabs( e.agg_cost - (std::numeric_limits::max)()) < 1? @@ -245,8 +241,7 @@ void Path::generate_postgres_data( auto cost = std::fabs(e.cost - (std::numeric_limits::max)()) < 1? std::numeric_limits::infinity() : e.cost; - (*postgres_data)[sequence] = {i, start_id(), end_id(), e.node, e.edge, cost, agg_cost}; - ++i; + (*postgres_data)[sequence] = {start_id(), end_id(), e.node, e.edge, cost, agg_cost}; ++sequence; } } @@ -272,7 +267,6 @@ void Path::get_pg_nksp_path( Path_rt **ret_path, size_t &sequence) const { for (unsigned int i = 0; i < path.size(); i++) { - (*ret_path)[sequence].seq = static_cast(i + 1); (*ret_path)[sequence].start_id = start_id(); (*ret_path)[sequence].end_id = end_id(); (*ret_path)[sequence].node = path[i].node; @@ -290,7 +284,6 @@ void Path::get_pg_turn_restricted_path( Path_rt **ret_path, size_t &sequence, int routeId) const { for (unsigned int i = 0; i < path.size(); i++) { - (*ret_path)[sequence].seq = static_cast(i + 1); (*ret_path)[sequence].start_id = routeId; (*ret_path)[sequence].end_id = end_id(); (*ret_path)[sequence].node = path[i].node; diff --git a/src/common/basic_edge.cpp b/src/common/basic_edge.cpp index ba33739d95b..5c720ab7565 100644 --- a/src/common/basic_edge.cpp +++ b/src/common/basic_edge.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** - * +File: basic_edge.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/basic_edge.h" +#include "cpp_common/basic_edge.hpp" namespace pgrouting { diff --git a/src/common/basic_vertex.cpp b/src/common/basic_vertex.cpp index 300a3b82a32..c5d1e92ff94 100644 --- a/src/common/basic_vertex.cpp +++ b/src/common/basic_vertex.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** - * +File: basic_vertex.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,14 +25,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/basic_vertex.h" +#include "cpp_common/basic_vertex.hpp" #include #include #include #include -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" namespace pgrouting { diff --git a/src/common/ch_edge.cpp b/src/common/ch_edge.cpp index 62d607132fd..50f5ab7201f 100644 --- a/src/common/ch_edge.cpp +++ b/src/common/ch_edge.cpp @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/ch_edge.h" +#include "cpp_common/ch_edge.hpp" namespace pgrouting { diff --git a/src/common/ch_vertex.cpp b/src/common/ch_vertex.cpp index fc5a1bc3403..cfc65e418a9 100644 --- a/src/common/ch_vertex.cpp +++ b/src/common/ch_vertex.cpp @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/ch_vertex.h" +#include "cpp_common/ch_vertex.hpp" #include #include diff --git a/src/common/check_parameters.c b/src/common/check_parameters.c index 1f58445787c..a66e417b4db 100644 --- a/src/common/check_parameters.c +++ b/src/common/check_parameters.c @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: astarOneToOne.c +File: check_parameters.c Generated with Template by: Copyright (c) 2015 pgRouting developers diff --git a/src/common/e_report.c b/src/common/e_report.c index 93a46525dd2..15500c849d4 100644 --- a/src/common/e_report.c +++ b/src/common/e_report.c @@ -1,9 +1,6 @@ /*PGR-GNU***************************************************************** File: e_report.c -Copyright (c) 2016 pgRouting developers -Mail: project@pgrouting.org - Function's developer: Copyright (c) 2016 Celia Virginia Vergara Castillo Mail: vicky_vergara@hotmail.com @@ -27,50 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ #include "c_common/postgres_connection.h" -#include "c_common/debug_macro.h" #include "c_common/e_report.h" -void -pgr_notice( - char* notice) { - PGR_DBG("Returned notice message = %s", notice); - - if (notice) { - ereport(NOTICE, - (errmsg("%s", notice))); - } -} - -void -pgr_notice2( - char* log, - char* notice) { - PGR_DBG("Returned log message = %s", log); - PGR_DBG("Returned notice message = %s", notice); - - if (log) { - pgr_notice(notice); - return; - } - - if (notice) { - ereport(NOTICE, - (errmsg("%s", notice), - errhint("%s", log))); - } -} - -void -pgr_error(char* err) { - PGR_DBG("Returned error message = %s", err); - - if (err) { - ereport(ERROR, - (errmsg_internal("Unexpected"), - errhint("%s", err))); - } -} - /** * @param[in] err string with an error message * @param[in] hint string with the hint to be used @@ -78,56 +33,67 @@ pgr_error(char* err) { * Generates an ERROR on postgres when err in not null */ void -throw_error(char *err, char *hint) { +pgr_throw_error(char *err, char *hint) { if (err) { ereport(ERROR, (errmsg("%s", err), errhint("%s", hint))); } } - -void -pgr_error2( - char* log, - char* err) { - PGR_DBG("Returned log message = %s", log); - PGR_DBG("Returned error message = %s", err); - - if (err) { - ereport(ERROR, - (errmsg_internal("%s", err), - errhint("%s", log))); - } -} - +/** + * On C++ side, the message to be returned; + * ~~~~{.c} + * std::ostringstream log; + * log << "the message"; + * *log_msg = to_pg_msg(log.str().c_str()); + * ~~~~ + * + * Then on the C side + * ~~~~{.c} + * vrp_global_report(&log_msg, ¬ice_msg, &error_msg); + * ~~~~ + * + * - When there is ERROR then postgreSQL takes over control + * - The char* messages are cleared automaticalyy with pfree. + * - When there is no error this will free the log & notice + */ void pgr_global_report( - char* log, - char* notice, - char* err) { - if (!notice && log) { + char** log, + char** notice, + char** err) { + if (!(*notice) && (*log)) { ereport(DEBUG1, - (errmsg_internal("%s", log))); + (errmsg_internal("%s", *log))); } - if (notice) { + if (*notice) { if (log) { ereport(NOTICE, - (errmsg_internal("%s", notice), - errhint("%s", log))); + (errmsg_internal("%s", *notice), + errhint("%s", *log))); } else { ereport(NOTICE, - (errmsg_internal("%s", notice))); + (errmsg_internal("%s", *notice))); } } - if (err) { - if (log) { + if (*err) { + if (*log) { ereport(ERROR, - (errmsg_internal("%s", err), - errhint("%s", log))); + (errmsg_internal("%s", *err), + errhint("%s", *log))); } else { ereport(ERROR, - (errmsg_internal("%s", err))); + (errmsg_internal("%s", *err))); + } + } else { + if (*log) { + pfree(*log); + *log = NULL; + } + if (*notice) { + pfree(*notice); + *notice = NULL; } } } diff --git a/src/common/identifier.cpp b/src/common/identifier.cpp index 81d10a9c494..51c3def4660 100644 --- a/src/common/identifier.cpp +++ b/src/common/identifier.cpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: identifier.cpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -24,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/identifier.h" +#include "cpp_common/identifier.hpp" namespace pgrouting { diff --git a/src/common/postgres_connection.c b/src/common/postgres_connection.c index 60cfb87ffcf..774c1122742 100644 --- a/src/common/postgres_connection.c +++ b/src/common/postgres_connection.c @@ -56,9 +56,6 @@ pgr_send_error(int errcode) { // http://www.postgresql.org/docs/9.4/static/spi-spi-finish.html void pgr_SPI_finish(void) { -#if 0 - PGR_DBG("Disconnecting SPI"); -#endif int code = SPI_finish(); if (code != SPI_OK_FINISH) { // SPI_ERROR_UNCONNECTED elog(ERROR, "There was no connection to SPI"); @@ -67,9 +64,6 @@ pgr_SPI_finish(void) { void pgr_SPI_connect(void) { -#if 0 - PGR_DBG("Connecting to SPI"); -#endif int SPIcode; SPIcode = SPI_connect(); if (SPIcode != SPI_OK_CONNECT) { @@ -78,10 +72,7 @@ pgr_SPI_connect(void) { } SPIPlanPtr -pgr_SPI_prepare(char* sql) { -#if 0 - PGR_DBG("Preparing Plan"); -#endif +pgr_SPI_prepare(const char* sql) { SPIPlanPtr SPIplan; SPIplan = SPI_prepare(sql, 0, NULL); if (SPIplan == NULL) { @@ -92,9 +83,6 @@ pgr_SPI_prepare(char* sql) { Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan) { -#if 0 - PGR_DBG("Opening Portal"); -#endif Portal SPIportal; SPIportal = SPI_cursor_open(NULL, SPIplan, NULL, NULL, true); if (SPIportal == NULL) { diff --git a/src/common/signalhandler.cpp b/src/common/signalhandler.cpp index f9927427a93..e97e51ca2f3 100644 --- a/src/common/signalhandler.cpp +++ b/src/common/signalhandler.cpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: signalhandler.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -32,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * *****************************************************************PGR-MIT*/ -#include "cpp_common/signalhandler.h" +#include "cpp_common/signalhandler.hpp" SignalHandler * SignalHandler::instance() { diff --git a/src/common/time_msg.c b/src/common/time_msg.c index b96fa9c5f5c..b86f0454149 100644 --- a/src/common/time_msg.c +++ b/src/common/time_msg.c @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: time_msg.c +File: time_msg.c Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/src/common/xy_vertex.cpp b/src/common/xy_vertex.cpp index f8cfee6ecce..5ded7798206 100644 --- a/src/common/xy_vertex.cpp +++ b/src/common/xy_vertex.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** - * +File: xy_vertex.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,14 +25,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/xy_vertex.h" +#include "cpp_common/xy_vertex.hpp" #include #include #include #include -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" namespace { @@ -120,39 +120,5 @@ extract_vertices( std::vector (data_edges, data_edges + count)); } -#if 0 -/* the following might be needed when using withPoints */ -std::vector < XY_vertex > extract_vertices( - std::vector < XY_vertex > vertices, - const std::vector data_edges) { - if (data_edges.empty()) return vertices; - - vertices.reserve(vertices.size() + data_edges.size() * 2); - - for (const auto edge : data_edges) { - vertices.push_back(XY_vertex(edge.source, edge.x1, edge.y1)); - vertices.push_back(XY_vertex(edge.target, edge.x2, edge.y2)); - } - - /* - * sort and delete duplicates - */ - std::stable_sort(vertices.begin(), vertices.end(), - [](const XY_vertex &lhs, const XY_vertex &rhs) - {return lhs.id < rhs.id;}); - - vertices.erase( - std::unique(vertices.begin(), vertices.end(), - [](const XY_vertex &lhs, const XY_vertex &rhs) - {return lhs.id == rhs.id;}), vertices.end()); - return vertices; -} -std::vector < XY_vertex > extract_vertices( - std::vector < XY_vertex > vertices, - const Edge_xy_t *data_edges, int64_t count) { - return extract_vertices(vertices, - std::vector (data_edges, data_edges + count)); -} -#endif } // namespace pgrouting diff --git a/src/components/CMakeLists.txt b/src/components/CMakeLists.txt index 33f30164681..467bbaa986f 100644 --- a/src/components/CMakeLists.txt +++ b/src/components/CMakeLists.txt @@ -8,7 +8,7 @@ ADD_LIBRARY(components OBJECT makeConnected_driver.cpp componentsResult.cpp - pgr_components.cpp + components.cpp connectedComponents_driver.cpp strongComponents_driver.cpp biconnectedComponents_driver.cpp diff --git a/src/components/articulationPoints.c b/src/components/articulationPoints.c index 68df104e6c4..8cdb4b163b0 100644 --- a/src/components/articulationPoints.c +++ b/src/components/articulationPoints.c @@ -37,7 +37,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/components/articulationPoints_driver.h" @@ -59,39 +58,22 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); - do_pgr_articulationPoints( - edges, - total_edges, + pgr_do_articulationPoints( + edges_sql, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg(" processing pgr_articulationPoints", start_t, clock()); if (err_msg) { if (*result_tuples) pfree(*result_tuples); + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } diff --git a/src/components/articulationPoints_driver.cpp b/src/components/articulationPoints_driver.cpp index 6cb983bcb7d..7feb62160e8 100644 --- a/src/components/articulationPoints_driver.cpp +++ b/src/components/articulationPoints_driver.cpp @@ -32,18 +32,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "components/pgr_components.hpp" +#include "components/components.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/base_graph.hpp" void -do_pgr_articulationPoints( - Edge_t *data_edges, - size_t total_edges, +pgr_do_articulationPoints( + char *edges_sql, + int64_t **return_tuples, size_t *return_count, char ** log_msg, @@ -52,23 +54,31 @@ do_pgr_articulationPoints( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - graphType gType = UNDIRECTED; + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); auto results(pgrouting::algorithms::articulationPoints(undigraph)); auto count = results.size(); @@ -76,8 +86,7 @@ do_pgr_articulationPoints( if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No paths found between start_vid and end_vid vertices"; + notice << "No paths found between start_vid and end_vid vertices"; return; } @@ -103,6 +112,9 @@ do_pgr_articulationPoints( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/components/biconnectedComponents.c b/src/components/biconnectedComponents.c index 7e5bf9bba8e..3299a5fd52c 100644 --- a/src/components/biconnectedComponents.c +++ b/src/components/biconnectedComponents.c @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/components/biconnectedComponents_driver.h" @@ -60,21 +59,9 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); - do_pgr_biconnectedComponents( - edges, - total_edges, + pgr_do_biconnectedComponents( + edges_sql, result_tuples, result_count, @@ -86,13 +73,9 @@ process( if (err_msg) { if (*result_tuples) pfree(*result_tuples); + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } diff --git a/src/components/biconnectedComponents_driver.cpp b/src/components/biconnectedComponents_driver.cpp index 6b07adb6fc3..58bef62d84a 100644 --- a/src/components/biconnectedComponents_driver.cpp +++ b/src/components/biconnectedComponents_driver.cpp @@ -32,19 +32,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "components/pgr_components.hpp" +#include "components/components.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/base_graph.hpp" void -do_pgr_biconnectedComponents( - Edge_t *data_edges, - size_t total_edges, +pgr_do_biconnectedComponents( + char *edges_sql, + II_t_rt **return_tuples, size_t *return_count, char ** log_msg, @@ -53,23 +55,31 @@ do_pgr_biconnectedComponents( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - graphType gType = UNDIRECTED; + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); auto results(pgrouting::algorithms::biconnectedComponents(undigraph)); auto count = results.size(); @@ -101,6 +111,9 @@ do_pgr_biconnectedComponents( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/components/bridges.c b/src/components/bridges.c index aef3be4e742..8a508a3d4c6 100644 --- a/src/components/bridges.c +++ b/src/components/bridges.c @@ -37,7 +37,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/components/bridges_driver.h" @@ -59,39 +58,22 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); - do_pgr_bridges( - edges, - total_edges, + pgr_do_bridges( + edges_sql, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg(" processing pgr_bridges", start_t, clock()); if (err_msg) { if (*result_tuples) pfree(*result_tuples); + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } diff --git a/src/components/bridges_driver.cpp b/src/components/bridges_driver.cpp index 382dcf545c3..6cf50be12c9 100644 --- a/src/components/bridges_driver.cpp +++ b/src/components/bridges_driver.cpp @@ -32,18 +32,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "components/pgr_components.hpp" +#include "components/components.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/base_graph.hpp" void -do_pgr_bridges( - Edge_t *data_edges, - size_t total_edges, +pgr_do_bridges( + char *edges_sql, int64_t **return_tuples, size_t *return_count, char ** log_msg, @@ -52,24 +53,31 @@ do_pgr_bridges( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - - graphType gType = UNDIRECTED; + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); auto results = pgrouting::algorithms::bridges(undigraph); auto count = results.size(); @@ -77,8 +85,7 @@ do_pgr_bridges( if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No paths found between start_vid and end_vid vertices"; + notice << "No paths found between start_vid and end_vid vertices"; return; } @@ -103,6 +110,9 @@ do_pgr_bridges( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/components/pgr_components.cpp b/src/components/components.cpp similarity index 97% rename from src/components/pgr_components.cpp rename to src/components/components.cpp index a90fa71ddd6..c2dbf824ad6 100644 --- a/src/components/pgr_components.cpp +++ b/src/components/components.cpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: components.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "components/pgr_components.hpp" +#include "components/components.hpp" #include #include @@ -38,7 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "cpp_common/identifiers.hpp" -#include "cpp_common/interruption.h" +#include "cpp_common/interruption.hpp" namespace pgrouting { namespace algorithms { @@ -109,6 +110,7 @@ biconnectedComponents( boost::associative_property_map bimap(bicmp_map); size_t num_comps; try { + // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDelete) num_comps = biconnected_components(graph.graph, bimap); } catch (...) { throw; diff --git a/src/components/componentsResult.cpp b/src/components/componentsResult.cpp index 1299fe700e2..5da9b560ff6 100644 --- a/src/components/componentsResult.cpp +++ b/src/components/componentsResult.cpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: componentsResult.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "components/componentsResult.h" +#include "components/componentsResult.hpp" #include #include diff --git a/src/components/connectedComponents.c b/src/components/connectedComponents.c index 81c24bd9695..2fff2f10c5d 100644 --- a/src/components/connectedComponents.c +++ b/src/components/connectedComponents.c @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/components/connectedComponents_driver.h" @@ -60,21 +59,9 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); - do_pgr_connectedComponents( - edges, - total_edges, + pgr_do_connectedComponents( + edges_sql, result_tuples, result_count, @@ -86,13 +73,9 @@ process( if (err_msg) { if (*result_tuples) pfree(*result_tuples); + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } diff --git a/src/components/connectedComponents_driver.cpp b/src/components/connectedComponents_driver.cpp index f8d7014a203..31451923923 100644 --- a/src/components/connectedComponents_driver.cpp +++ b/src/components/connectedComponents_driver.cpp @@ -32,21 +32,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/base_graph.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_base_graph.hpp" - -#include "components/pgr_components.hpp" - - +#include "components/components.hpp" void -do_pgr_connectedComponents( - Edge_t *data_edges, - size_t total_edges, +pgr_do_connectedComponents( + char *edges_sql, + II_t_rt **return_tuples, size_t *return_count, char ** log_msg, @@ -55,23 +54,31 @@ do_pgr_connectedComponents( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - graphType gType = UNDIRECTED; + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); auto results(pgrouting::algorithms::pgr_connectedComponents(undigraph)); auto count = results.size(); @@ -79,8 +86,7 @@ do_pgr_connectedComponents( if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No paths found between start_vid and end_vid vertices"; + notice << "No paths found between start_vid and end_vid vertices"; return; } @@ -103,6 +109,9 @@ do_pgr_connectedComponents( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/components/makeConnected.c b/src/components/makeConnected.c index ee4f967a31a..fe81659d1d4 100644 --- a/src/components/makeConnected.c +++ b/src/components/makeConnected.c @@ -36,7 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/components/makeConnected_driver.h" PGDLLEXPORT Datum _pgr_makeconnected(PG_FUNCTION_ARGS); @@ -53,30 +52,12 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - PGR_DBG("Initializing arrays"); - - (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_makeConnected( - edges, - total_edges, + pgr_do_makeConnected( + edges_sql, result_tuples, result_count, @@ -85,23 +66,17 @@ process( ¬ice_msg, &err_msg); time_msg(" processing pgr_makeConnected", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); if (err_msg) { - if (*result_tuples) - pfree(*result_tuples); + if (*result_tuples) pfree(*result_tuples); + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (edges) - pfree(edges); - if (log_msg) - pfree(log_msg); - if (notice_msg) - pfree(notice_msg); - if (err_msg) - pfree(err_msg); + if (log_msg) pfree(log_msg); + if (notice_msg) pfree(notice_msg); + if (err_msg) pfree(err_msg); pgr_SPI_finish(); } @@ -110,31 +85,20 @@ PGDLLEXPORT Datum _pgr_makeconnected(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ II_t_rt *result_tuples = NULL; size_t result_count = 0; - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - /* - pgr_makeConnected( - edge_sql TEXT) - */ - /**********************************************************************/ - PGR_DBG("Calling process"); process( text_to_cstring(PG_GETARG_TEXT_P(0)), &result_tuples, &result_count); - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -159,12 +123,6 @@ PGDLLEXPORT Datum _pgr_makeconnected(PG_FUNCTION_ARGS) { Datum *values; bool *nulls; - /**********************************************************************/ - /* - OUT start_vid BIGINT, - OUT end_vid BIGINT - */ - /**********************************************************************/ size_t numb = 3; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -178,18 +136,10 @@ PGDLLEXPORT Datum _pgr_makeconnected(PG_FUNCTION_ARGS) { values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].d1.start_vid); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].d2.end_vid); - /**********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/components/makeConnected_driver.cpp b/src/components/makeConnected_driver.cpp index 11057e9360e..ecfd6155434 100644 --- a/src/components/makeConnected_driver.cpp +++ b/src/components/makeConnected_driver.cpp @@ -33,16 +33,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -#include "components/pgr_makeConnected.hpp" -#include "cpp_common/pgr_base_graph.hpp" +#include "components/makeConnected.hpp" +#include "cpp_common/base_graph.hpp" void -do_pgr_makeConnected( - Edge_t *data_edges, - size_t total_edges, +pgr_do_makeConnected( + char *edges_sql, + II_t_rt **return_tuples, size_t *return_count, @@ -52,26 +53,34 @@ do_pgr_makeConnected( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); std::vector results; std::string logstr; + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - graphType gType = UNDIRECTED; - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); pgrouting::functions::Pgr_makeConnected fn_makeConnected; results = fn_makeConnected.makeConnected(undigraph); logstr += fn_makeConnected.get_log(); @@ -108,6 +117,9 @@ do_pgr_makeConnected( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/components/strongComponents.c b/src/components/strongComponents.c index 3176c48f5c8..bd5721db0fb 100644 --- a/src/components/strongComponents.c +++ b/src/components/strongComponents.c @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/components/strongComponents_driver.h" @@ -60,21 +59,9 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); - do_pgr_strongComponents( - edges, - total_edges, + pgr_do_strongComponents( + edges_sql, result_tuples, result_count, @@ -86,13 +73,9 @@ process( if (err_msg) { if (*result_tuples) pfree(*result_tuples); + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } diff --git a/src/components/strongComponents_driver.cpp b/src/components/strongComponents_driver.cpp index 9d055df1bb7..fb12e1d14e9 100644 --- a/src/components/strongComponents_driver.cpp +++ b/src/components/strongComponents_driver.cpp @@ -32,19 +32,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/base_graph.hpp" -#include "components/pgr_components.hpp" +#include "components/components.hpp" void -do_pgr_strongComponents( - Edge_t *data_edges, - size_t total_edges, +pgr_do_strongComponents( + char *edges_sql, + II_t_rt **return_tuples, size_t *return_count, char ** log_msg, @@ -53,22 +55,31 @@ do_pgr_strongComponents( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - graphType gType = DIRECTED; + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); auto results(pgrouting::algorithms::strongComponents(digraph)); auto count = results.size(); @@ -76,8 +87,7 @@ do_pgr_strongComponents( if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No components found"; + notice << "No components found"; return; } @@ -100,6 +110,9 @@ do_pgr_strongComponents( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/contraction/CMakeLists.txt b/src/contraction/CMakeLists.txt index fcbe0469c7a..97ec200e472 100644 --- a/src/contraction/CMakeLists.txt +++ b/src/contraction/CMakeLists.txt @@ -1,5 +1,5 @@ ADD_LIBRARY(contraction OBJECT contractGraph.c contractGraph_driver.cpp - pgr_contract.cpp + contract.cpp ) diff --git a/src/contraction/pgr_contract.cpp b/src/contraction/contract.cpp similarity index 95% rename from src/contraction/pgr_contract.cpp rename to src/contraction/contract.cpp index 0f313ddeb29..a957214da06 100644 --- a/src/contraction/pgr_contract.cpp +++ b/src/contraction/contract.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_contract.cpp +File: contract.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "contraction/pgr_contract.hpp" +#include "contraction/contract.hpp" namespace pgrouting { namespace contraction { diff --git a/src/contraction/contractGraph.c b/src/contraction/contractGraph.c index 7fb0a45a28d..37e3c4c5239 100644 --- a/src/contraction/contractGraph.c +++ b/src/contraction/contractGraph.c @@ -41,7 +41,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" #include "c_types/contracted_rt.h" -#include "c_common/pgdata_getters.h" #include "drivers/contraction/contractGraph_driver.h" PGDLLEXPORT Datum _pgr_contraction(PG_FUNCTION_ARGS); @@ -68,41 +67,17 @@ process(char* edges_sql, char* notice_msg = NULL; char* err_msg = NULL; - size_t size_forbidden_vertices = 0; - int64_t* forbidden_vertices = pgr_get_bigIntArray(&size_forbidden_vertices, forbidden, true, &err_msg); - throw_error(err_msg, "While getting forbidden_vertices"); - PGR_DBG("size_forbidden_vertices %ld", size_forbidden_vertices); - - size_t size_contraction_order = 0; - int64_t* contraction_order = pgr_get_bigIntArray(&size_contraction_order, order, false, &err_msg); - throw_error(err_msg, "While getting contraction order"); - PGR_DBG("size_contraction_order %ld ", size_contraction_order); - - - size_t total_edges = 0; - Edge_t* edges = NULL; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - if (total_edges == 0) { - if (forbidden_vertices) pfree(forbidden_vertices); - if (contraction_order) pfree(contraction_order); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - do_pgr_contractGraph( - edges, total_edges, - forbidden_vertices, size_forbidden_vertices, - contraction_order, size_contraction_order, + pgr_do_contractGraph( + edges_sql, + forbidden, + order, num_cycles, directed, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg("processing pgr_contraction()", start_t, clock()); @@ -111,15 +86,8 @@ process(char* edges_sql, (*result_tuples) = NULL; (*result_count) = 0; } + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (forbidden_vertices) pfree(forbidden_vertices); - if (contraction_order) pfree(contraction_order); pgr_SPI_finish(); } @@ -128,24 +96,13 @@ _pgr_contraction(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ contracted_rt *result_tuples = NULL; size_t result_count = 0; - /**********************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - /* - edges_sql TEXT, - contraction_order BIGINT[], - max_cycles integer DEFAULT 1, - forbidden_vertices BIGINT[] DEFAULT ARRAY[]::BIGINT[], - directed BOOLEAN DEFAULT true, - - **********************************************************************/ process( text_to_cstring(PG_GETARG_TEXT_P(0)), @@ -156,8 +113,6 @@ _pgr_contraction(PG_FUNCTION_ARGS) { &result_tuples, &result_count); - - /**********************************************************************/ funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -183,7 +138,6 @@ _pgr_contraction(PG_FUNCTION_ARGS) { int16 typlen; size_t call_cntr = funcctx->call_cntr; - /**********************************************************************/ size_t numb = 6; values =(Datum *)palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -243,7 +197,6 @@ _pgr_contraction(PG_FUNCTION_ARGS) { values[4] = Int64GetDatum(result_tuples[call_cntr].target); values[5] = Float8GetDatum(result_tuples[call_cntr].cost); - /*********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/contraction/contractGraph_driver.cpp b/src/contraction/contractGraph_driver.cpp index 392845351e8..fcd6a8d2582 100644 --- a/src/contraction/contractGraph_driver.cpp +++ b/src/contraction/contractGraph_driver.cpp @@ -35,12 +35,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include +#include "cpp_common/pgdata_getters.hpp" #include "contraction/ch_graphs.hpp" -#include "contraction/pgr_contract.hpp" +#include "contraction/contract.hpp" #include "c_types/contracted_rt.h" #include "cpp_common/identifiers.hpp" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/alloc.hpp" namespace { @@ -168,21 +169,13 @@ void get_postgres_result( -/************************************************************ - edges_sql TEXT, - contraction_order BIGINT[], - forbidden_vertices BIGINT[] DEFAULT ARRAY[]::BIGINT[], - max_cycles integer DEFAULT 1, - directed BOOLEAN DEFAULT true - ***********************************************************/ void -do_pgr_contractGraph( - Edge_t *data_edges, - size_t total_edges, - int64_t *forbidden_vertices, - size_t size_forbidden_vertices, - int64_t *contraction_order, - size_t size_contraction_order, +pgr_do_contractGraph( + char *edges_sql, + + ArrayType* forbidden, + ArrayType* order, + int64_t max_cycles, bool directed, contracted_rt **return_tuples, @@ -193,13 +186,15 @@ do_pgr_contractGraph( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intArray; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; + try { - pgassert(total_edges != 0); - pgassert(size_contraction_order != 0); pgassert(max_cycles != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); @@ -207,16 +202,17 @@ do_pgr_contractGraph( pgassert(!(*return_tuples)); pgassert(*return_count == 0); - /* - * Converting to C++ structures - */ - std::vector edges(data_edges, data_edges + total_edges); - std::vector forbid( - forbidden_vertices, - forbidden_vertices + size_forbidden_vertices); - std::vector ordering( - contraction_order, - contraction_order + size_contraction_order); + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + auto forbid = get_intArray(forbidden, true); + auto ordering = get_intArray(order, false); for (const auto kind : ordering) { if (!pgrouting::contraction::is_valid_contraction(static_cast(kind))) { @@ -228,10 +224,10 @@ do_pgr_contractGraph( } - graphType gType = directed? DIRECTED: UNDIRECTED; + if (directed) { using DirectedGraph = pgrouting::graph::CHDirectedGraph; - DirectedGraph digraph(gType); + DirectedGraph digraph; process_contraction(digraph, edges, forbid, ordering, max_cycles); @@ -242,7 +238,7 @@ do_pgr_contractGraph( return_count); } else { using UndirectedGraph = pgrouting::graph::CHUndirectedGraph; - UndirectedGraph undigraph(gType); + UndirectedGraph undigraph; process_contraction(undigraph, edges, forbid, ordering, max_cycles); @@ -265,6 +261,9 @@ do_pgr_contractGraph( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/cpp_common/CMakeLists.txt b/src/cpp_common/CMakeLists.txt index 87d81385238..f45cce63ba9 100644 --- a/src/cpp_common/CMakeLists.txt +++ b/src/cpp_common/CMakeLists.txt @@ -3,11 +3,15 @@ ADD_LIBRARY(cpp_common OBJECT compPaths.cpp rule.cpp bpoint.cpp - pgr_messages.cpp + messages.cpp combinations.cpp get_check_data.cpp pgdata_fetchers.cpp - # linked as C, but compiled as C++ pgdata_getters.cpp + + # for old trsp code + trsp_pgfetch.cpp + # linked as C, but compiled as C++ + trsp_pgget.cpp ) diff --git a/src/cpp_common/Dmatrix.cpp b/src/cpp_common/Dmatrix.cpp index a236689a7b7..8a97de2f9c4 100644 --- a/src/cpp_common/Dmatrix.cpp +++ b/src/cpp_common/Dmatrix.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: Dmatrix.cpp +File: Dmatrix.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -23,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/Dmatrix.h" +#include "cpp_common/Dmatrix.hpp" #include #include @@ -34,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" #include "c_types/iid_t_rt.h" @@ -206,36 +205,11 @@ std::ostream& operator<<(std::ostream &log, const Dmatrix &matrix) { log << "Internal(" << i << "," << j << ")" << "\tUsers(" << matrix.ids[i] << "," << matrix.ids[j] << ")" << "\t = " << cost -#if 0 - << "\t(" << matrix.get_index(matrix.ids[i]) - << "," << matrix.get_index(matrix.ids[j]) << ")" - << "\t = " << matrix.costs[i][j] - << "\t = " << matrix.costs[j][i] - << "=inf:" - << (matrix.costs[i][j] == - (std::numeric_limits::infinity)()) - << "=inf:" - << (matrix.costs[j][i] == - (std::numeric_limits::infinity)()) -#endif << "\n"; ++j; } ++i; } -#if 0 - for (size_t i = 0; i < matrix.costs.size(); ++i) { - for (size_t j = 0; j < matrix.costs.size(); ++j) { - for (size_t k = 0; k < matrix.costs.size(); ++k) { - log << matrix.costs[i][k] << " <= (" - << matrix.costs[i][j] << " + " << matrix.costs[j][k] << ")" - << (matrix.costs[i][k] - <= (matrix.costs[i][j] + matrix.costs[j][k])) - << "\n"; - } - } - } -#endif return log; } diff --git a/src/cpp_common/arrays_input.cpp b/src/cpp_common/arrays_input.cpp deleted file mode 100644 index 68e12b1d80d..00000000000 --- a/src/cpp_common/arrays_input.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/*PGR-GNU***************************************************************** -File: arrays_input.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Copyright (c) 2023 Celia Virginia Vergara Castillo -Copyright (c) 2015 Celia Virginia Vergara Castillo -mail: vicky at erosion.dev - ------- - -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 "c_common/arrays_input.h" - -extern "C" { -#include -#include -} - -#include "cpp_common/pgr_alloc.hpp" - -namespace { - -/** @brief get the array contents from postgres - * - * @details This function generates the array inputs according to their type - * received through @a ArrayType *v parameter and store them in @a c_array. It - * can be empty also if received @a allow_empty true. The cases of failure are:- - * 1. When @a ndim is not equal to one dimension. - * 2. When no element is found i.e. nitems is zero or negative. - * 3. If the element type doesn't lie in switch cases, give the error of expected array of any integer type - * 4. When size of @a c_array is out of range or memory. - * 5. When null value is found in the array. - * - * All these failures are represented as error through @a elog. - * @param[in] v Pointer to the postgres C array - * @param[out] arrlen size of the C array - * @param[in] allow_empty flag to allow empty arrays - * - * @pre the array has to be one dimension - * @pre Must have elements (when allow_empty is false) - * - * @returns The resultant array - */ -int64_t* -get_bigIntArr(ArrayType *v, size_t *arrlen, bool allow_empty) { - int64_t *c_array = nullptr; - - auto element_type = ARR_ELEMTYPE(v); - auto dim = ARR_DIMS(v); - auto ndim = ARR_NDIM(v); - auto nitems = ArrayGetNItems(ndim, dim); - Datum *elements = nullptr; - bool *nulls = nullptr; - int16 typlen; - bool typbyval; - char typalign; - - - if (allow_empty && (ndim == 0 || nitems <= 0)) { - return nullptr; - } - - if (ndim != 1) { - elog(ERROR, "One dimension expected"); - return nullptr; - } - - if (nitems <= 0) { - elog(ERROR, "No elements found"); - return nullptr; - } - - get_typlenbyvalalign(element_type, - &typlen, &typbyval, &typalign); - - /* validate input data type */ - switch (element_type) { - case INT2OID: - case INT4OID: - case INT8OID: - break; - default: - elog(ERROR, "Expected array of ANY-INTEGER"); - return nullptr; - break; - } - - deconstruct_array(v, element_type, typlen, typbyval, - typalign, &elements, &nulls, - &nitems); - - c_array = pgrouting::pgr_alloc(static_cast(nitems), (c_array)); - if (!c_array) { - elog(ERROR, "Out of memory!"); - } - - - for (int i = 0; i < nitems; i++) { - if (nulls[i]) { - pfree(c_array); - elog(ERROR, "NULL value found in Array!"); - } else { - switch (element_type) { - case INT2OID: - c_array[i] = static_cast(DatumGetInt16(elements[i])); - break; - case INT4OID: - c_array[i] = static_cast(DatumGetInt32(elements[i])); - break; - case INT8OID: - c_array[i] = DatumGetInt64(elements[i]); - break; - } - } - } - (*arrlen) = static_cast(nitems); - - pfree(elements); - pfree(nulls); - return c_array; -} - -} // namespace - -/** - * @param[out] arrlen Length of the array - * @param[in] input the postgres array - * @param[in] allow_empty when true, empty arrays are accepted. - * @returns Returns a C array of integers - */ - -int64_t* pgr_get_bigIntArray(size_t *arrlen, ArrayType *input, bool allow_empty) { - return get_bigIntArr(input, arrlen, allow_empty); -} diff --git a/src/cpp_common/bpoint.cpp b/src/cpp_common/bpoint.cpp index 6766e5744a0..41d757a754a 100644 --- a/src/cpp_common/bpoint.cpp +++ b/src/cpp_common/bpoint.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -file: bpoint.cpp +File: bpoint.cpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org diff --git a/src/cpp_common/combinations.cpp b/src/cpp_common/combinations.cpp index efe62761f73..739685c449d 100644 --- a/src/cpp_common/combinations.cpp +++ b/src/cpp_common/combinations.cpp @@ -24,18 +24,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "cpp_common/combinations.h" - #include #include #include #include +#include +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" #include "cpp_common/basePath_SSEC.hpp" namespace pgrouting { namespace utilities { +#if 1 std::map> get_combinations(const II_t_rt *combinations, size_t total) { std::map> result; @@ -63,6 +65,7 @@ get_combinations( } return result; } +#endif std::map> get_combinations( @@ -111,5 +114,56 @@ get_combinations( return new_combinations; } +std::map> +get_combinations(const std::vector &combinations) { + std::map> result; + + for (const auto &row : combinations) { + result[row.d1.source].insert(row.d2.target); + } + return result; +} + +/** @brief gets all the departures and destinations + * @param[in] combinations_sql from the @b combinations signatures + * @param[in] startsArr PostgreSQL array with the departures + * @param[in] endsArr PostgreSQL array with the destinations + * @param[in] normal the graph is reversed so reverse starts & ends + * @returns[out] map: for each departure a set of destinations + * + * The resulting map can be empty + */ +std::map> +get_combinations( + char *combinations_sql, + ArrayType* startsArr, ArrayType* endsArr, bool normal) { + using pgrouting::pgget::get_intSet; + std::map> result; + + std::set starts; + std::set ends; + + if (startsArr && endsArr) { + starts = normal? get_intSet(startsArr) : get_intSet(endsArr); + ends = normal? get_intSet(endsArr) : get_intSet(startsArr); + } + + /* TODO Read query storing like std::map> */ + /* queries are stored in vectors */ + auto combinations = combinations_sql? + pgrouting::pgget::get_combinations(std::string(combinations_sql)) : std::vector(); + + /* data comes from a combinations */ + for (const auto &row : combinations) { + result[row.d1.source].insert(row.d2.target); + } + + /* data comes from many to many */ + for (const auto &s : starts) { + result[s] = ends; + } + return result; +} + } // namespace utilities } // namespace pgrouting diff --git a/src/cpp_common/compPaths.cpp b/src/cpp_common/compPaths.cpp index 797b20ae2e8..31bb11368c7 100644 --- a/src/cpp_common/compPaths.cpp +++ b/src/cpp_common/compPaths.cpp @@ -30,8 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_assert.h" -#include "cpp_common/compPaths.h" +#include "cpp_common/assert.hpp" +#include "cpp_common/compPaths.hpp" #include "cpp_common/basePath_SSEC.hpp" diff --git a/src/cpp_common/get_check_data.cpp b/src/cpp_common/get_check_data.cpp index a4fec03cd3e..e4a8bf0fc3a 100644 --- a/src/cpp_common/get_check_data.cpp +++ b/src/cpp_common/get_check_data.cpp @@ -35,10 +35,12 @@ extern "C" { } #include +#include #include -#include "cpp_common/pgr_alloc.hpp" -#include "c_types/info_t.hpp" +#include "cpp_common/undefPostgresDefine.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/info_t.hpp" namespace { @@ -241,6 +243,183 @@ char getChar( return value; } +/** @brief get the array contents from postgres + * + * @details This function generates the array inputs according to their type + * received through @a ArrayType *v parameter and store them in @a c_array. It + * can be empty also if received @a allow_empty true. The cases of failure are:- + * 1. When @a ndim is not equal to one dimension. + * 2. When no element is found i.e. nitems is zero or negative. + * 3. If the element type doesn't lie in switch cases, give the error of expected array of any integer type + * 4. When size of @a c_array is out of range or memory. + * 5. When null value is found in the array. + * + * All these failures are represented as error through @a elog. + * @param[in] v Pointer to the postgres C array + * + * @pre the array has to be one dimension + * @pre Must have elements (when allow_empty is false) + * + * @returns set of elements on the PostgreSQL array + */ +std::set +get_pgset(ArrayType *v) { + std::set results; + + if (!v) return results; + + auto element_type = ARR_ELEMTYPE(v); + auto dim = ARR_DIMS(v); + auto ndim = ARR_NDIM(v); + auto nitems = ArrayGetNItems(ndim, dim); + Datum *elements = nullptr; + bool *nulls = nullptr; + int16 typlen; + bool typbyval; + char typalign; + + + if (ndim == 0 || nitems <= 0) { + return results; + } + + if (ndim != 1) { + throw std::string("One dimension expected"); + } + + get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign); + + switch (element_type) { + case INT2OID: + case INT4OID: + case INT8OID: + break; + default: + throw std::string("Expected array of ANY-INTEGER"); + } + + deconstruct_array(v, element_type, typlen, typbyval, + typalign, &elements, &nulls, + &nitems); + + int64_t data(0); + + for (int i = 0; i < nitems; i++) { + if (nulls[i]) { + throw std::string("NULL value found in Array!"); + } else { + switch (element_type) { + case INT2OID: + data = static_cast(DatumGetInt16(elements[i])); + break; + case INT4OID: + data = static_cast(DatumGetInt32(elements[i])); + break; + case INT8OID: + data = DatumGetInt64(elements[i]); + break; + } + } + results.insert(data); + } + + pfree(elements); + pfree(nulls); + return results; +} + +/** @brief get the array contents from postgres + * + * @details This function generates the array inputs according to their type + * received through @a ArrayType *v parameter and store them in @a c_array. It + * can be empty also if received @a allow_empty true. The cases of failure are:- + * 1. When @a ndim is not equal to one dimension. + * 2. When no element is found i.e. nitems is zero or negative. + * 3. If the element type doesn't lie in switch cases, give the error of expected array of any integer type + * 4. When size of @a c_array is out of range or memory. + * 5. When null value is found in the array. + * + * All these failures are represented as error through @a elog. + * @param[in] v Pointer to the postgres C array + * @param[in] allow_empty flag to allow empty arrays + * + * @pre the array has to be one dimension + * @pre Must have elements (when allow_empty is false) + * + * @returns Vector of elements of the PostgreSQL array + */ +std::vector +get_pgarray(ArrayType *v, bool allow_empty) { + std::vector results; + if (!v) return results; + + auto element_type = ARR_ELEMTYPE(v); + auto dim = ARR_DIMS(v); + auto ndim = ARR_NDIM(v); + auto nitems = ArrayGetNItems(ndim, dim); + Datum *elements = nullptr; + bool *nulls = nullptr; + int16 typlen; + bool typbyval; + char typalign; + + + if (allow_empty && (ndim == 0 || nitems <= 0)) { + return results; + } + + if (ndim != 1) { + throw std::string("One dimension expected"); + } + + if (nitems <= 0) { + throw std::string("No elements found"); + } + + get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign); + + /* validate input data type */ + switch (element_type) { + case INT2OID: + case INT4OID: + case INT8OID: + break; + default: + throw std::string("Expected array of ANY-INTEGER"); + } + + deconstruct_array(v, element_type, typlen, typbyval, + typalign, &elements, &nulls, + &nitems); + + int64_t data(0); + + results.reserve(static_cast(nitems)); + + for (int i = 0; i < nitems; i++) { + if (nulls[i]) { + throw std::string("NULL value found in Array!"); + } else { + switch (element_type) { + case INT2OID: + data = static_cast(DatumGetInt16(elements[i])); + break; + case INT4OID: + data = static_cast(DatumGetInt32(elements[i])); + break; + case INT8OID: + data = DatumGetInt64(elements[i]); + break; + } + } + results.push_back(data); + } + + pfree(elements); + pfree(nulls); + return results; +} + /** @brief get the array contents from postgres * * @details This function generates the array inputs according to their type diff --git a/src/cpp_common/pgr_messages.cpp b/src/cpp_common/messages.cpp similarity index 96% rename from src/cpp_common/pgr_messages.cpp rename to src/cpp_common/messages.cpp index 602f5cbffae..25bf1ca686b 100644 --- a/src/cpp_common/pgr_messages.cpp +++ b/src/cpp_common/messages.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: pgr_pickDeliver.h +File: messages.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -26,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_messages.h" +#include "cpp_common/messages.hpp" namespace pgrouting { diff --git a/src/cpp_common/pgdata_fetchers.cpp b/src/cpp_common/pgdata_fetchers.cpp index d60e41e44aa..aaed7182262 100644 --- a/src/cpp_common/pgdata_fetchers.cpp +++ b/src/cpp_common/pgdata_fetchers.cpp @@ -4,8 +4,10 @@ File: pgdata_fetchers.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org +Copyright (c) 2024 Celia Virginia Vergara Castillo +- Return (C++) structure Copyright (c) 2023 Celia Virginia Vergara Castillo -mail: vicky at erosion.dev +- cat into one file Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com Copyright (c) 2016 Rohith Reddy @@ -36,419 +38,433 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/pgdata_fetchers.hpp" #include -#include +#include #include #include "cpp_common/get_check_data.hpp" -#include "c_types/info_t.hpp" +#include "cpp_common/info_t.hpp" #include "c_types/ii_t_rt.h" -#include "c_types/coordinate_t.h" -#include "c_types/delauny_t.h" +#include "cpp_common/coordinate_t.hpp" +#include "cpp_common/delauny_t.hpp" #include "c_types/edge_bool_t_rt.h" -#include "c_types/costFlow_t.h" -#include "c_types/edge_xy_t.h" -#include "c_types/edge_t.h" +#include "cpp_common/costFlow_t.hpp" +#include "cpp_common/edge_xy_t.hpp" +#include "cpp_common/edge_t.hpp" #include "c_types/iid_t_rt.h" -#include "c_types/pickDeliver/orders_t.h" -#include "c_types/restriction_t.h" -#include "c_types/point_on_edge_t.h" -#include "c_types/pickDeliver/vehicle_t.h" +#include "cpp_common/orders_t.hpp" +#include "cpp_common/restriction_t.hpp" +#include "cpp_common/point_on_edge_t.hpp" +#include "cpp_common/vehicle_t.hpp" namespace pgrouting { +namespace pgget { -void fetch_combination( +II_t_rt fetch_combination( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t*, - II_t_rt *combination, - size_t* valid_combinations, + size_t*, bool) { - combination->d1.source = pgrouting::getBigInt(tuple, tupdesc, info[0]); - combination->d2.target = pgrouting::getBigInt(tuple, tupdesc, info[1]); - - *valid_combinations = *valid_combinations + 1; + II_t_rt combination; + combination.d1.source = getBigInt(tuple, tupdesc, info[0]); + combination.d2.target = getBigInt(tuple, tupdesc, info[1]); + return combination; } -void fetch_coordinate( +Coordinate_t fetch_coordinate( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t *default_id, - Coordinate_t* coordinate, size_t*, bool) { - if (pgrouting::column_found(info[0].colNumber)) { - coordinate->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + Coordinate_t coordinate; + if (column_found(info[0].colNumber)) { + coordinate.id = getBigInt(tuple, tupdesc, info[0]); } else { - coordinate->id = *default_id; + coordinate.id = *default_id; ++(*default_id); } - coordinate->x = pgrouting::getFloat8(tuple, tupdesc, info[1]); - coordinate->y = pgrouting::getFloat8(tuple, tupdesc, info[2]); + coordinate.x = getFloat8(tuple, tupdesc, info[1]); + coordinate.y = getFloat8(tuple, tupdesc, info[2]); + return coordinate; } -void fetch_delauny( +Delauny_t fetch_delauny( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t*, - Delauny_t* delauny, size_t*, bool) { - delauny->tid = pgrouting::getBigInt(tuple, tupdesc, info[0]); - delauny->pid = pgrouting::getBigInt(tuple, tupdesc, info[1]); - delauny->x = pgrouting::getFloat8(tuple, tupdesc, info[2]); - delauny->y = pgrouting::getFloat8(tuple, tupdesc, info[3]); + Delauny_t delauny; + delauny.tid = getBigInt(tuple, tupdesc, info[0]); + delauny.pid = getBigInt(tuple, tupdesc, info[1]); + delauny.x = getFloat8(tuple, tupdesc, info[2]); + delauny.y = getFloat8(tuple, tupdesc, info[3]); + return delauny; } /* edges have many fetchers */ -void fetch_basic_edge( +Edge_bool_t fetch_basic_edge( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t *default_id, - Edge_bool_t *edge, size_t *valid_edges, bool) { - if (pgrouting::column_found(info[0].colNumber)) { - edge->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + Edge_bool_t edge; + if (column_found(info[0].colNumber)) { + edge.id = getBigInt(tuple, tupdesc, info[0]); } else { - edge->id = *default_id; + edge.id = *default_id; ++(*default_id); } - bool new_columns = pgrouting::column_found(info[5].colNumber); + bool new_columns = column_found(info[5].colNumber); - edge->source = pgrouting::getBigInt(tuple, tupdesc, info[1]); - edge->target = pgrouting::getBigInt(tuple, tupdesc, info[2]); + edge.source = getBigInt(tuple, tupdesc, info[1]); + edge.target = getBigInt(tuple, tupdesc, info[2]); if (new_columns) { - edge->going = pgrouting::getFloat8(tuple, tupdesc, info[5]) > 0 - || (pgrouting::column_found(info[6].colNumber) - && pgrouting::getFloat8(tuple, tupdesc, info[6]) > 0); + edge.going = getFloat8(tuple, tupdesc, info[5]) > 0 + || (column_found(info[6].colNumber) + && getFloat8(tuple, tupdesc, info[6]) > 0); } else { - edge->going = pgrouting::getFloat8(tuple, tupdesc, info[3]) > 0 - || (pgrouting::column_found(info[4].colNumber) - && pgrouting::getFloat8(tuple, tupdesc, info[4]) > 0); + edge.going = getFloat8(tuple, tupdesc, info[3]) > 0 + || (column_found(info[4].colNumber) + && getFloat8(tuple, tupdesc, info[4]) > 0); } (*valid_edges)++; + return edge; } -void fetch_edge( +Edge_t fetch_edge( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t *default_id, - Edge_t *edge, size_t *valid_edges, bool normal) { - if (pgrouting::column_found(info[0].colNumber)) { - edge->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + Edge_t edge; + if (column_found(info[0].colNumber)) { + edge.id = getBigInt(tuple, tupdesc, info[0]); } else { - edge->id = *default_id; + edge.id = *default_id; ++(*default_id); } if (normal) { - edge->source = pgrouting::getBigInt(tuple, tupdesc, info[1]); - edge->target = pgrouting::getBigInt(tuple, tupdesc, info[2]); + edge.source = getBigInt(tuple, tupdesc, info[1]); + edge.target = getBigInt(tuple, tupdesc, info[2]); } else { - edge->target = pgrouting::getBigInt(tuple, tupdesc, info[1]); - edge->source = pgrouting::getBigInt(tuple, tupdesc, info[2]); + edge.target = getBigInt(tuple, tupdesc, info[1]); + edge.source = getBigInt(tuple, tupdesc, info[2]); } - edge->cost = pgrouting::getFloat8(tuple, tupdesc, info[3]); + edge.cost = getFloat8(tuple, tupdesc, info[3]); - if (pgrouting::column_found(info[4].colNumber)) { - edge->reverse_cost = pgrouting::getFloat8(tuple, tupdesc, info[4]); + if (column_found(info[4].colNumber)) { + edge.reverse_cost = getFloat8(tuple, tupdesc, info[4]); } else { - edge->reverse_cost = -1; + edge.reverse_cost = -1; } - edge->cost = std::isinf(edge->cost)? - DBL_MAX : edge->cost; + edge.cost = std::isinf(edge.cost)? + std::numeric_limits::max() : edge.cost; - edge->reverse_cost = std::isinf(edge->reverse_cost)? - DBL_MAX : edge->reverse_cost; + edge.reverse_cost = std::isinf(edge.reverse_cost)? + std::numeric_limits::max() : edge.reverse_cost; - *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1; - *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge.cost < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge.reverse_cost < 0? *valid_edges: *valid_edges + 1; + + return edge; } -void fetch_costFlow_edge( + +CostFlow_t fetch_costFlow_edge( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t *default_id, - CostFlow_t *edge, size_t *valid_edges, bool normal) { - if (pgrouting::column_found(info[0].colNumber)) { - edge->edge_id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + CostFlow_t edge; + if (column_found(info[0].colNumber)) { + edge.edge_id = getBigInt(tuple, tupdesc, info[0]); } else { - edge->edge_id = *default_id; + edge.edge_id = *default_id; ++(*default_id); } if (normal) { - edge->source = pgrouting::getBigInt(tuple, tupdesc, info[1]); - edge->target = pgrouting::getBigInt(tuple, tupdesc, info[2]); + edge.source = getBigInt(tuple, tupdesc, info[1]); + edge.target = getBigInt(tuple, tupdesc, info[2]); } else { - edge->target = pgrouting::getBigInt(tuple, tupdesc, info[1]); - edge->source = pgrouting::getBigInt(tuple, tupdesc, info[2]); + edge.target = getBigInt(tuple, tupdesc, info[1]); + edge.source = getBigInt(tuple, tupdesc, info[2]); } - edge->capacity = pgrouting::getBigInt(tuple, tupdesc, info[3]); - if (pgrouting::column_found(info[4].colNumber)) { - edge->reverse_capacity = pgrouting::getBigInt(tuple, tupdesc, info[4]); + edge.capacity = getBigInt(tuple, tupdesc, info[3]); + if (column_found(info[4].colNumber)) { + edge.reverse_capacity = getBigInt(tuple, tupdesc, info[4]); } else { - edge->reverse_capacity = -1; + edge.reverse_capacity = -1; } - edge->cost = pgrouting::getFloat8(tuple, tupdesc, info[5]); - if (pgrouting::column_found(info[6].colNumber)) { - edge->reverse_cost = pgrouting::getFloat8(tuple, tupdesc, info[6]); + edge.cost = getFloat8(tuple, tupdesc, info[5]); + if (column_found(info[6].colNumber)) { + edge.reverse_cost = getFloat8(tuple, tupdesc, info[6]); } else { - edge->reverse_cost = 0; + edge.reverse_cost = 0; } - *valid_edges = edge->capacity < 0? *valid_edges: *valid_edges + 1; - *valid_edges = edge->reverse_capacity < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge.capacity < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge.reverse_capacity < 0? *valid_edges: *valid_edges + 1; + return edge; } -void fetch_edge_with_xy( +Edge_xy_t fetch_edge_xy( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t *default_id, - Edge_xy_t *edge, size_t *valid_edges, bool normal) { - if (pgrouting::column_found(info[0].colNumber)) { - edge->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + Edge_xy_t edge; + if (column_found(info[0].colNumber)) { + edge.id = getBigInt(tuple, tupdesc, info[0]); } else { - edge->id = *default_id; + edge.id = *default_id; ++(*default_id); } if (normal) { - edge->source = pgrouting::getBigInt(tuple, tupdesc, info[1]); - edge->target = pgrouting::getBigInt(tuple, tupdesc, info[2]); + edge.source = getBigInt(tuple, tupdesc, info[1]); + edge.target = getBigInt(tuple, tupdesc, info[2]); } else { - edge->target = pgrouting::getBigInt(tuple, tupdesc, info[1]); - edge->source = pgrouting::getBigInt(tuple, tupdesc, info[2]); + edge.target = getBigInt(tuple, tupdesc, info[1]); + edge.source = getBigInt(tuple, tupdesc, info[2]); } - edge->cost = pgrouting::getFloat8(tuple, tupdesc, info[3]); + edge.cost = getFloat8(tuple, tupdesc, info[3]); - if (pgrouting::column_found(info[4].colNumber)) { - edge->reverse_cost = pgrouting::getFloat8(tuple, tupdesc, info[4]); + if (column_found(info[4].colNumber)) { + edge.reverse_cost = getFloat8(tuple, tupdesc, info[4]); } else { - edge->reverse_cost = -1; + edge.reverse_cost = -1; } - edge->x1 = pgrouting::getFloat8(tuple, tupdesc, info[5]); - edge->y1 = pgrouting::getFloat8(tuple, tupdesc, info[6]); - edge->x2 = pgrouting::getFloat8(tuple, tupdesc, info[7]); - edge->y2 = pgrouting::getFloat8(tuple, tupdesc, info[8]); + edge.x1 = getFloat8(tuple, tupdesc, info[5]); + edge.y1 = getFloat8(tuple, tupdesc, info[6]); + edge.x2 = getFloat8(tuple, tupdesc, info[7]); + edge.y2 = getFloat8(tuple, tupdesc, info[8]); - *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1; - *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge.cost < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge.reverse_cost < 0? *valid_edges: *valid_edges + 1; + return edge; } -void pgr_fetch_row( +IID_t_rt pgr_fetch_row( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t*, - IID_t_rt *distance, size_t*, bool) { - distance->from_vid = pgrouting::getBigInt(tuple, tupdesc, info[0]); - distance->to_vid = pgrouting::getBigInt(tuple, tupdesc, info[1]); - distance->cost = pgrouting::getFloat8(tuple, tupdesc, info[2]); + IID_t_rt distance; + distance.from_vid = getBigInt(tuple, tupdesc, info[0]); + distance.to_vid = getBigInt(tuple, tupdesc, info[1]); + distance.cost = getFloat8(tuple, tupdesc, info[2]); + return distance; } -void fetch_orders( +Orders_t fetch_orders( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t*, - Orders_t* pd_order, size_t*, bool with_id) { - pd_order->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); - pd_order->demand = pgrouting::getFloat8(tuple, tupdesc, info[1]); + Orders_t pd_order; + pd_order.id = getBigInt(tuple, tupdesc, info[0]); + pd_order.demand = getFloat8(tuple, tupdesc, info[1]); /* * the pickups */ - pd_order->pick_x = with_id ? - 0 : pgrouting::getFloat8(tuple, tupdesc, info[2]); - pd_order->pick_y = with_id ? - 0 : pgrouting::getFloat8(tuple, tupdesc, info[3]); - pd_order->pick_open_t = pgrouting::getFloat8(tuple, tupdesc, info[4]); - pd_order->pick_close_t = pgrouting::getFloat8(tuple, tupdesc, info[5]); - pd_order->pick_service_t = pgrouting::column_found(info[6].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[6]) : 0; + pd_order.pick_x = with_id ? + 0 : getFloat8(tuple, tupdesc, info[2]); + pd_order.pick_y = with_id ? + 0 : getFloat8(tuple, tupdesc, info[3]); + pd_order.pick_open_t = getFloat8(tuple, tupdesc, info[4]); + pd_order.pick_close_t = getFloat8(tuple, tupdesc, info[5]); + pd_order.pick_service_t = column_found(info[6].colNumber) ? + getFloat8(tuple, tupdesc, info[6]) : 0; /* * the deliveries */ - pd_order->deliver_x = with_id ? - 0 : pgrouting::getFloat8(tuple, tupdesc, info[7]); - pd_order->deliver_y = with_id ? - 0 : pgrouting::getFloat8(tuple, tupdesc, info[8]); - pd_order->deliver_open_t = pgrouting::getFloat8(tuple, tupdesc, info[9]); - pd_order->deliver_close_t = pgrouting::getFloat8(tuple, tupdesc, info[10]); - pd_order->deliver_service_t = pgrouting::column_found(info[11].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[11]) : 0; - - pd_order->pick_node_id = with_id ? - pgrouting::getBigInt(tuple, tupdesc, info[12]) : 0; - pd_order->deliver_node_id = with_id ? - pgrouting::getBigInt(tuple, tupdesc, info[13]) : 0; + pd_order.deliver_x = with_id ? + 0 : getFloat8(tuple, tupdesc, info[7]); + pd_order.deliver_y = with_id ? + 0 : getFloat8(tuple, tupdesc, info[8]); + pd_order.deliver_open_t = getFloat8(tuple, tupdesc, info[9]); + pd_order.deliver_close_t = getFloat8(tuple, tupdesc, info[10]); + pd_order.deliver_service_t = column_found(info[11].colNumber) ? + getFloat8(tuple, tupdesc, info[11]) : 0; + + pd_order.pick_node_id = with_id ? + getBigInt(tuple, tupdesc, info[12]) : 0; + pd_order.deliver_node_id = with_id ? + getBigInt(tuple, tupdesc, info[13]) : 0; + return pd_order; } -void fetch_restriction( +Restriction_t fetch_restriction( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t*, - Restriction_t *restriction, size_t*, bool) { - restriction->cost = pgrouting::getFloat8(tuple, tupdesc, info[0]); + Restriction_t restriction; + restriction.cost = getFloat8(tuple, tupdesc, info[0]); - restriction->via = NULL; - restriction->via_size = 0; - restriction->via = pgrouting::getBigIntArr(tuple, tupdesc, info[1], &restriction->via_size); + restriction.via = NULL; + restriction.via_size = 0; + restriction.via = getBigIntArr(tuple, tupdesc, info[1], &restriction.via_size); + return restriction; } -void fetch_point( +Point_on_edge_t fetch_point( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t *default_pid, - Point_on_edge_t* point, size_t*, bool) { - if (pgrouting::column_found(info[0].colNumber)) { - point->pid = pgrouting::getBigInt(tuple, tupdesc, info[0]); + Point_on_edge_t point = {}; + if (column_found(info[0].colNumber)) { + point.pid = getBigInt(tuple, tupdesc, info[0]); } else { ++(*default_pid); - point->pid = *default_pid; + point.pid = *default_pid; } - point->edge_id = pgrouting::getBigInt(tuple, tupdesc, info[1]); - point->fraction = pgrouting::getFloat8(tuple, tupdesc, info[2]); + point.edge_id = getBigInt(tuple, tupdesc, info[1]); + point.fraction = getFloat8(tuple, tupdesc, info[2]); - if (pgrouting::column_found(info[3].colNumber)) { - point->side = pgrouting::getChar(tuple, tupdesc, info[3], false, 'b'); + if (column_found(info[3].colNumber)) { + point.side = getChar(tuple, tupdesc, info[3], false, 'b'); } else { - point->side = 'b'; + point.side = 'b'; } + return point; } -void fetch_vehicle( +Vehicle_t fetch_vehicle( const HeapTuple tuple, const TupleDesc &tupdesc, const std::vector &info, int64_t*, - Vehicle_t *vehicle, size_t*, bool with_id) { - vehicle->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); - vehicle->capacity = pgrouting::getFloat8(tuple, tupdesc, info[1]); + Vehicle_t vehicle; + vehicle.id = getBigInt(tuple, tupdesc, info[0]); + vehicle.capacity = getFloat8(tuple, tupdesc, info[1]); - vehicle->start_x = with_id ? + vehicle.start_x = with_id ? 0 : - pgrouting::getFloat8(tuple, tupdesc, info[2]); - vehicle->start_y = with_id ? + getFloat8(tuple, tupdesc, info[2]); + vehicle.start_y = with_id ? 0 : - pgrouting::getFloat8(tuple, tupdesc, info[3]); + getFloat8(tuple, tupdesc, info[3]); - vehicle->speed = pgrouting::column_found(info[13].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[13]) : + vehicle.speed = column_found(info[13].colNumber) ? + getFloat8(tuple, tupdesc, info[13]) : 1; - vehicle->cant_v = pgrouting::column_found(info[4].colNumber) ? - pgrouting::getBigInt(tuple, tupdesc, info[4]) : + vehicle.cant_v = column_found(info[4].colNumber) ? + getBigInt(tuple, tupdesc, info[4]) : 1; - vehicle->start_open_t = pgrouting::column_found(info[5].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[5]) : + vehicle.start_open_t = column_found(info[5].colNumber) ? + getFloat8(tuple, tupdesc, info[5]) : 0; - vehicle->start_close_t = pgrouting::column_found(info[6].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[6]) : - DBL_MAX; - vehicle->start_service_t = pgrouting::column_found(info[7].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[7]) : + vehicle.start_close_t = column_found(info[6].colNumber) ? + getFloat8(tuple, tupdesc, info[6]) : + std::numeric_limits::max(); + vehicle.start_service_t = column_found(info[7].colNumber) ? + getFloat8(tuple, tupdesc, info[7]) : 0; - if (!(pgrouting::column_found(info[8].colNumber)) - && pgrouting::column_found(info[9].colNumber)) { + if (!(column_found(info[8].colNumber)) + && column_found(info[9].colNumber)) { ereport(ERROR, (errmsg("Column \'%s\' not Found", info[8].name.c_str()), errhint("%s was found, also column is expected %s ", info[9].name.c_str(), info[8].name.c_str()))); } - if (pgrouting::column_found(info[8].colNumber) - && !(pgrouting::column_found(info[9].colNumber))) { + if (column_found(info[8].colNumber) + && !(column_found(info[9].colNumber))) { ereport(ERROR, (errmsg("Column \'%s\' not Found", info[9].name.c_str()), errhint("%s was found, also column is expected %s ", info[8].name.c_str(), info[9].name.c_str()))); } - vehicle->end_x = pgrouting::column_found(info[8].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[8]) : - vehicle->start_x; - vehicle->end_y = pgrouting::column_found(info[9].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[9]) : - vehicle->start_y; + vehicle.end_x = column_found(info[8].colNumber) ? + getFloat8(tuple, tupdesc, info[8]) : + vehicle.start_x; + vehicle.end_y = column_found(info[9].colNumber) ? + getFloat8(tuple, tupdesc, info[9]) : + vehicle.start_y; - if (!(pgrouting::column_found(info[10].colNumber)) - && pgrouting::column_found(info[11].colNumber)) { + if (!(column_found(info[10].colNumber)) + && column_found(info[11].colNumber)) { ereport(ERROR, (errmsg("Column \'%s\' not Found", info[10].name.c_str()), errhint("%s was found, also column is expected %s ", info[10].name.c_str(), info[11].name.c_str()))); } - if (pgrouting::column_found(info[10].colNumber) - && !(pgrouting::column_found(info[11].colNumber))) { + if (column_found(info[10].colNumber) + && !(column_found(info[11].colNumber))) { ereport(ERROR, (errmsg("Column \'%s\' not Found", info[11].name.c_str()), errhint("%s was found, also column is expected %s ", info[11].name.c_str(), info[10].name.c_str()))); } - vehicle->end_open_t = pgrouting::column_found(info[10].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[10]) : - vehicle->start_open_t; - vehicle->end_close_t = pgrouting::column_found(info[11].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[11]) : - vehicle->start_close_t; - vehicle->end_service_t = pgrouting::column_found(info[12].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[12]) : - vehicle->start_service_t; - - vehicle->speed = pgrouting::column_found(info[13].colNumber) ? - pgrouting::getFloat8(tuple, tupdesc, info[13]) : + vehicle.end_open_t = column_found(info[10].colNumber) ? + getFloat8(tuple, tupdesc, info[10]) : + vehicle.start_open_t; + vehicle.end_close_t = column_found(info[11].colNumber) ? + getFloat8(tuple, tupdesc, info[11]) : + vehicle.start_close_t; + vehicle.end_service_t = column_found(info[12].colNumber) ? + getFloat8(tuple, tupdesc, info[12]) : + vehicle.start_service_t; + + vehicle.speed = column_found(info[13].colNumber) ? + getFloat8(tuple, tupdesc, info[13]) : 1; - vehicle->start_node_id = with_id ? - pgrouting::getBigInt(tuple, tupdesc, info[14]) : + vehicle.start_node_id = with_id ? + getBigInt(tuple, tupdesc, info[14]) : 0; - vehicle->end_node_id = with_id ? - (pgrouting::column_found(info[12].colNumber) ? - pgrouting::getBigInt(tuple, tupdesc, info[15]) : - vehicle->start_node_id) : + vehicle.end_node_id = with_id ? + (column_found(info[12].colNumber) ? + getBigInt(tuple, tupdesc, info[15]) : + vehicle.start_node_id) : 0; + return vehicle; } +} // namespace pgget } // namespace pgrouting diff --git a/src/cpp_common/pgdata_getters.cpp b/src/cpp_common/pgdata_getters.cpp index ef60c0c1894..552ba8ea9ea 100644 --- a/src/cpp_common/pgdata_getters.cpp +++ b/src/cpp_common/pgdata_getters.cpp @@ -4,8 +4,10 @@ File: pgdata_getters.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org +Copyright (c) 2024 Celia Virginia Vergara Castillo +- Return C++ container Copyright (c) 2023 Celia Virginia Vergara Castillo -mail: vicky at erosion.dev +- cat into one file Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com Copyright (c) 2016 Rohith Reddy @@ -33,213 +35,155 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "c_common/pgdata_getters.h" +extern "C" { + +#include +#include +#include +#include +#include +#include +#include +#include + +} + +#include "cpp_common/pgdata_getters.hpp" #include #include #include #include +#include +#include #include "cpp_common/get_data.hpp" #include "cpp_common/get_check_data.hpp" -#include "cpp_common/pgr_alloc.hpp" #include "cpp_common/pgdata_fetchers.hpp" -#include "c_types/info_t.hpp" -#include "c_types/coordinate_t.h" -#include "c_types/costFlow_t.h" +#include "cpp_common/info_t.hpp" +#include "cpp_common/coordinate_t.hpp" +#include "cpp_common/costFlow_t.hpp" #include "c_types/ii_t_rt.h" #include "c_types/iid_t_rt.h" -#include "c_types/delauny_t.h" -#include "c_types/edge_t.h" +#include "cpp_common/delauny_t.hpp" +#include "cpp_common/edge_t.hpp" #include "c_types/edge_bool_t_rt.h" -#include "c_types/edge_xy_t.h" -#include "c_types/flow_t.h" -#include "c_types/pickDeliver/orders_t.h" -#include "c_types/pickDeliver/vehicle_t.h" -#include "c_types/point_on_edge_t.h" -#include "c_types/restriction_t.h" +#include "cpp_common/edge_xy_t.hpp" +#include "cpp_common/orders_t.hpp" +#include "cpp_common/vehicle_t.hpp" +#include "cpp_common/point_on_edge_t.hpp" +#include "cpp_common/restriction_t.hpp" +namespace pgrouting { +namespace pgget { /** - * @param[out] arrlen Length of the array * @param[in] input the postgres array * @param[in] allow_empty when true, empty arrays are accepted. - * @param[out] err_msg when not null, there was an error and contains the message - * @returns Returns a C array of integers + * @returns Returns a vector of int64_t */ -int64_t* pgr_get_bigIntArray(size_t *arrlen, ArrayType *input, bool allow_empty, char** err_msg) { - using pgrouting::pgr_msg; - try { - return pgrouting::get_array(input, arrlen, allow_empty); - } catch (const std::string &ex) { - (*arrlen) = 0; - *err_msg = pgr_msg(ex.c_str()); - return nullptr; - } catch(...) { - (*arrlen) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - return nullptr; - } +std::vector get_intArray(ArrayType *input, bool allow_empty) { + return pgrouting::get_pgarray(input, allow_empty); +} + +/** + * @param[in] arr 1 dimension postgres array + * @returns Returns a set of int64_t + * + * Can be empty set. + */ +std::set get_intSet(ArrayType *arr) { + return pgrouting::get_pgset(arr); } /** + For queries of the type: ~~~~{.c} SELECT source, target FROM combinations; ~~~~ - @param[in] sql The query - @param [out] rows array of combinations - @param [out] total_rows size of combinations - @param[out] err_msg when not null, there was an error and contains the message + @param[in] sql The combinations query + @returns vector of `II_t_rt` combinations */ -void pgr_get_combinations( - char *sql, - II_t_rt **rows, - size_t *total_rows, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_combinations(const std::string &sql) { using pgrouting::Column_info_t; - try { - std::vector info{2}; - - info[0] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; - pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_combination); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, true, "source", ANY_INTEGER}, + {-1, 0, true, "target", ANY_INTEGER}}; + + return get_data(sql, true, info, &fetch_combination); } +/** @details -/** For queries of the type: ~~~~{.c} SELECT id, x, y FROM coordinates; ~~~~ - @param[in] sql The query - @param[out] rows the matrix coordinates - @param[out] total_rows size of coordinates - @param[out] err_msg when not null, there was an error and contains the message + @param[in] sql The coordinates query + @returns vector of `Coordinate_t` */ -void pgr_get_coordinates( - char *sql, - Coordinate_t **rows, - size_t *total_rows, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_coordinates(const std::string &sql) { using pgrouting::Column_info_t; - try { - std::vector info{3}; - - info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "x", pgrouting::ANY_NUMERICAL}; - info[2] = {-1, 0, true, "y", pgrouting::ANY_NUMERICAL}; - pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_coordinate); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, true, "id", ANY_INTEGER}, + {-1, 0, true, "x", ANY_NUMERICAL}, + {-1, 0, true, "y", ANY_NUMERICAL}}; + + return get_data(sql, true, info, &fetch_coordinate); } -/** +/** @details + For queries of the type: ~~~~{.c} SELECT tid, pid, x, y FROM delauny; SELECT pid, pid, x, y FROM delauny; ~~~~ - @param[in] sql The query - @param[out] rows the delauny array - @param[out] total_rows size of delauny - @param[out] err_msg when not null, there was an error and contains the message + @param[in] sql The delauny triangles query + @returns vector of `Delauny_t` */ -void pgr_get_delauny( - char *sql, - Delauny_t **rows, - size_t *total_rows, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_delauny(const std::string &sql) { using pgrouting::Column_info_t; - try { - std::vector info{4}; - - info[0] = {-1, 0, true, "tid", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "pid", pgrouting::ANY_INTEGER}; - info[2] = {-1, 0, true, "x", pgrouting::ANY_NUMERICAL}; - info[3] = {-1, 0, true, "y", pgrouting::ANY_NUMERICAL}; - pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_delauny); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, true, "tid", ANY_INTEGER}, + {-1, 0, true, "pid", ANY_INTEGER}, + {-1, 0, true, "x", ANY_NUMERICAL}, + {-1, 0, true, "y", ANY_NUMERICAL}}; + + return get_data(sql, true, info, &fetch_delauny); } /** + For queries of the type: ~~~~{.c} SELECT id, source, target, capacity, [reverse_capacity] FROM edge_table; ~~~~ - @param[in] sql The query - @param[out] rows the edges array - @param[out] total_rows size of edges - @param[out] err_msg when not null, there was an error and contains the message + @param[in] sql The flow edges query + @returns vector of `Edge_t` */ -void -pgr_get_flow_edges( - char *sql, - Edge_t **rows, - size_t *total_rows, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_flow_edges(const std::string &sql) { using pgrouting::Column_info_t; - try { - std::vector info{5}; - - info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; - info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; - info[3] = {-1, 0, true, "capacity", pgrouting::ANY_INTEGER}; - info[4] = {-1, 0, false, "reverse_capacity", pgrouting::ANY_INTEGER}; - - pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_edge); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, true, "id", ANY_INTEGER}, + {-1, 0, true, "source", ANY_INTEGER}, + {-1, 0, true, "target", ANY_INTEGER}, + {-1, 0, true, "capacity", ANY_INTEGER}, + {-1, 0, false, "reverse_capacity", ANY_INTEGER}}; + + return get_data(sql, true, info, &fetch_edge); } /** + For queries of the type: ~~~~{.c} SELECT id, source, target, capacity, [reverse_capacity], cost, [reverse_cost] @@ -247,44 +191,25 @@ pgr_get_flow_edges( ~~~~ @param[in] sql The query - @param[out] rows the edges array - @param[out] total_rows size of edges - @param[out] err_msg when not null, there was an error and contains the message + @returns vector of `CostFlow_t` edges */ -void -pgr_get_costFlow_edges( - char *sql, - CostFlow_t **rows, - size_t *total_rows, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_costFlow_edges(const std::string &sql) { using pgrouting::Column_info_t; - try { - std::vector info{7}; - - info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; - info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; - info[3] = {-1, 0, true, "capacity", pgrouting::ANY_INTEGER}; - info[4] = {-1, 0, false, "reverse_capacity", pgrouting::ANY_INTEGER}; - info[5] = {-1, 0, true, "cost", pgrouting::ANY_NUMERICAL}; - info[6] = {-1, 0, false, "reverse_cost", pgrouting::ANY_NUMERICAL}; - - pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_costFlow_edge); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, true, "id", ANY_INTEGER}, + {-1, 0, true, "source", ANY_INTEGER}, + {-1, 0, true, "target", ANY_INTEGER}, + {-1, 0, true, "capacity", ANY_INTEGER}, + {-1, 0, false, "reverse_capacity", ANY_INTEGER}, + {-1, 0, true, "cost", ANY_NUMERICAL}, + {-1, 0, false, "reverse_cost", ANY_NUMERICAL}}; + + return get_data(sql, true, info, &fetch_costFlow_edge); } /** + For queries of the type: ~~~~{.c} SELECT id, source, target, cost, [reverse_cost] FROM edge_table; @@ -297,377 +222,231 @@ pgr_get_costFlow_edges( @todo This option will be removed on V4 @param[in] sql The query - @param[out] rows the edges array - @param[out] total_rows size of edges - @param[out] err_msg when not null, there was an error and contains the message + @returns vector of `Edge_bool_t` */ -void -pgr_get_basic_edges( - char *sql, - Edge_bool_t **rows, - size_t *total_rows, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_basic_edges(const std::string &sql) { using pgrouting::Column_info_t; - try { - std::vector info{7}; - - info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; - info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; - info[3] = {-1, 0, false, "going", pgrouting::ANY_NUMERICAL}; - info[4] = {-1, 0, false, "coming", pgrouting::ANY_NUMERICAL}; - info[5] = {-1, 0, false, "cost", pgrouting::ANY_NUMERICAL}; - info[6] = {-1, 0, false, "reverse_cost", pgrouting::ANY_NUMERICAL}; - - pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_basic_edge); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, true, "id", ANY_INTEGER}, + {-1, 0, true, "source", ANY_INTEGER}, + {-1, 0, true, "target", ANY_INTEGER}, + {-1, 0, false, "going", ANY_NUMERICAL}, + {-1, 0, false, "coming", ANY_NUMERICAL}, + {-1, 0, false, "cost", ANY_NUMERICAL}, + {-1, 0, false, "reverse_cost", ANY_NUMERICAL}}; + + return get_data(sql, true, info, &fetch_basic_edge); } /** + For queries of the type: ~~~~{.c} SELECT id, source, target, cost, [reverse_cost], x1, y1, x2, y2 FROM edge_table; ~~~~ - @param[in] sql The query - @param[out] rows the edges array - @param[out] total_rows size of edges + @param[in] sql The edges query @param[in] normal when false then the graph is reversed - @param[out] err_msg when not null, there was an error and contains the message + @returns vector of `Edge_xy_t` */ -void -pgr_get_edges_xy( - char *sql, - Edge_xy_t **rows, - size_t *total_rows, - bool normal, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_edges_xy(const std::string &sql, bool normal) { using pgrouting::Column_info_t; - try { - std::vector info{9}; - - info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; - info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; - info[3] = {-1, 0, true, "cost", pgrouting::ANY_NUMERICAL}; - info[4] = {-1, 0, false, "reverse_cost", pgrouting::ANY_NUMERICAL}; - info[5] = {-1, 0, true, "x1", pgrouting::ANY_NUMERICAL}; - info[6] = {-1, 0, true, "y1", pgrouting::ANY_NUMERICAL}; - info[7] = {-1, 0, true, "x2", pgrouting::ANY_NUMERICAL}; - info[8] = {-1, 0, true, "y2", pgrouting::ANY_NUMERICAL}; - - pgrouting::get_data(sql, rows, total_rows, normal, info, &pgrouting::fetch_edge_with_xy); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, true, "id", ANY_INTEGER}, + {-1, 0, true, "source", ANY_INTEGER}, + {-1, 0, true, "target", ANY_INTEGER}, + {-1, 0, true, "cost", ANY_NUMERICAL}, + {-1, 0, false, "reverse_cost", ANY_NUMERICAL}, + {-1, 0, true, "x1", ANY_NUMERICAL}, + {-1, 0, true, "y1", ANY_NUMERICAL}, + {-1, 0, true, "x2", ANY_NUMERICAL}, + {-1, 0, true, "y2", ANY_NUMERICAL}}; + + return get_data(sql, normal, info, &fetch_edge_xy); } /** + For queries of the type: ~~~~{.c} SELECT id, source, target, cost, [reverse_cost] FROM edge_table; ~~~~ @param[in] sql The query - @param[out] rows the edges array - @param[out] total_rows size of edges @param[in] normal when false then the graph is reversed @param[in] ignore_id when true id value of edge is ignored - @param[out] err_msg when not null, there was an error and contains the message + @returns vector of `Edge_t` */ -void -pgr_get_edges( - char *sql, - Edge_t **rows, - size_t *total_rows, - bool normal, - bool ignore_id, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_edges(const std::string &sql, bool normal, bool ignore_id) { using pgrouting::Column_info_t; - try { - std::vector info{5}; - - info[0] = {-1, 0, !ignore_id, "id", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "source", pgrouting::ANY_INTEGER}; - info[2] = {-1, 0, true, "target", pgrouting::ANY_INTEGER}; - info[3] = {-1, 0, true, "cost", pgrouting::ANY_NUMERICAL}; - info[4] = {-1, 0, false, "reverse_cost", pgrouting::ANY_NUMERICAL}; - - pgrouting::get_data(sql, rows, total_rows, normal, info, &pgrouting::fetch_edge); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, !ignore_id, "id", ANY_INTEGER}, + {-1, 0, true, "source", ANY_INTEGER}, + {-1, 0, true, "target", ANY_INTEGER}, + {-1, 0, true, "cost", ANY_NUMERICAL}, + {-1, 0, false, "reverse_cost", ANY_NUMERICAL}}; + + return get_data(sql, normal, info, &fetch_edge); } /** + For queries of the type: ~~~~{.c} SELECT start_vid, end_vid, agg_cost FROM matrix_data; ~~~~ - @param[in] sql The query - @param[out] rows of the matrix array - @param[out] total_rows size of matrix rows - @param[out] err_msg when not null, there was an error and contains the message + @param[in] sql The matrix + @returns vector of `IID_t_rt` */ -void pgr_get_matrixRows( - char *sql, - IID_t_rt **rows, - size_t *total_rows, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_matrixRows(const std::string &sql) { using pgrouting::Column_info_t; - try { - std::vector info{3}; - - info[0] = {-1, 0, true, "start_vid", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "end_vid", pgrouting::ANY_INTEGER}; - info[2] = {-1, 0, true, "agg_cost", pgrouting::ANY_NUMERICAL}; - pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::pgr_fetch_row); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, true, "start_vid", ANY_INTEGER}, + {-1, 0, true, "end_vid", ANY_INTEGER}, + {-1, 0, true, "agg_cost", ANY_NUMERICAL}}; + return get_data(sql, true, info, &pgr_fetch_row); } /** + For queries of the type: ~~~~{.c} SELECT id, demand - [p_node_id | p_x, p_y], p_open, p_close, p_service, - [d_node_id | d_x, d_y], d_open, d_close, d_service, + [p_node_id | p_x, p_y], p_open, p_close, p_service, + [d_node_id | d_x, d_y], d_open, d_close, d_service, FROM orders; ~~~~ - @param[in] sql The query - @param[out] rows of the orders - @param[out] total_rows size of orders rows - @param[out] with_id flag to choose if its euclidean or matrix - @param[out] err_msg when not null, there was an error and contains the message + @param[in] sql The orders query + @param[in] with_id flag that idicates if id is to be used + @returns vector of `Orders_t` */ -void pgr_get_orders( - char *sql, - Orders_t **rows, - size_t *total_rows, - bool with_id, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_orders( + const std::string &sql, + bool with_id + ) { using pgrouting::Column_info_t; - try { - std::vector info{14}; - - info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "demand", pgrouting::ANY_NUMERICAL}; - info[2] = {-1, 0, true, "p_x", pgrouting::ANY_NUMERICAL}; - info[3] = {-1, 0, true, "p_y", pgrouting::ANY_NUMERICAL}; - info[4] = {-1, 0, true, "p_open", pgrouting::ANY_NUMERICAL}; - info[5] = {-1, 0, true, "p_close", pgrouting::ANY_NUMERICAL}; - info[6] = {-1, 0, false, "p_service", pgrouting::ANY_NUMERICAL}; - info[7] = {-1, 0, true, "d_x", pgrouting::ANY_NUMERICAL}; - info[8] = {-1, 0, true, "d_y", pgrouting::ANY_NUMERICAL}; - info[9] = {-1, 0, true, "d_open", pgrouting::ANY_NUMERICAL}; - info[10] = {-1, 0, true, "d_close", pgrouting::ANY_NUMERICAL}; - info[11] = {-1, 0, false, "d_service", pgrouting::ANY_NUMERICAL}; - /* nodes are going to be ignored*/ - info[12] = {-1, 0, false, "p_node_id", pgrouting::ANY_INTEGER}; - info[13] = {-1, 0, false, "d_node_id", pgrouting::ANY_INTEGER}; - - if (with_id) { - /* (x,y) values are ignored*/ - info[2].strict = false; - info[3].strict = false; - info[7].strict = false; - info[8].strict = false; - /* nodes are compulsory*/ - info[12].strict = true; - info[13].strict = true; - } - - pgrouting::get_data(sql, rows, total_rows, with_id, info, &pgrouting::fetch_orders); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); + std::vector info{ + {-1, 0, true, "id", ANY_INTEGER}, + {-1, 0, true, "demand", ANY_NUMERICAL}, + {-1, 0, true, "p_x", ANY_NUMERICAL}, + {-1, 0, true, "p_y", ANY_NUMERICAL}, + {-1, 0, true, "p_open", ANY_NUMERICAL}, + {-1, 0, true, "p_close", ANY_NUMERICAL}, + {-1, 0, false, "p_service", ANY_NUMERICAL}, + {-1, 0, true, "d_x", ANY_NUMERICAL}, + {-1, 0, true, "d_y", ANY_NUMERICAL}, + {-1, 0, true, "d_open", ANY_NUMERICAL}, + {-1, 0, true, "d_close", ANY_NUMERICAL}, + {-1, 0, false, "d_service", ANY_NUMERICAL}, + /* nodes are going to be ignored*/ + {-1, 0, false, "p_node_id", ANY_INTEGER}, + {-1, 0, false, "d_node_id", ANY_INTEGER}}; + + if (with_id) { + /* (x,y) values are ignored*/ + info[2].strict = false; + info[3].strict = false; + info[7].strict = false; + info[8].strict = false; + /* nodes are compulsory*/ + info[12].strict = true; + info[13].strict = true; } -} + return get_data(sql, with_id, info, &fetch_orders); +} /** + For queries of the type: ~~~~{.c} SELECT pid, edge_id, fraction side FROM points; ~~~~ - @param[in] sql The query - @param[out] rows the points array - @param[out] total_rows size of points - @param[out] err_msg when not null, there was an error and contains the message + @param[in] sql The points query + @returns vector of `Point_on_edge_t` */ -void pgr_get_points( - char *sql, - Point_on_edge_t **rows, - size_t *total_rows, - char **err_msg) { - using pgrouting::pgr_free; - using pgrouting::pgr_msg; +std::vector get_points(const std::string &sql) { using pgrouting::Column_info_t; - try { - std::vector info{4}; - - info[0] = {-1, 0, false, "pid", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "edge_id", pgrouting::ANY_INTEGER}; - info[2] = {-1, 0, true, "fraction", pgrouting::ANY_NUMERICAL}; - info[3] = {-1, 0, false, "side", pgrouting::CHAR1}; - pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_point); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, false, "pid", ANY_INTEGER}, + {-1, 0, true, "edge_id", ANY_INTEGER}, + {-1, 0, true, "fraction", ANY_NUMERICAL}, + {-1, 0, false, "side", pgrouting::CHAR1}}; + + return get_data(sql, true, info, &fetch_point); } /** + For queries of the type: ~~~~{.c} SELECT cost, path FROM restrictions; ~~~~ - @param[in] sql The query - @param[out] rows the restrictions array - @param[out] total_rows size of restrictions - @param[out] err_msg when not null, there was an error and contains the message + @param[in] sql The restrictions query + @returns vector of `Restriction_t` */ -void pgr_get_restrictions( - char *sql, - Restriction_t **rows, - size_t *total_rows, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_restrictions(const std::string &sql) { using pgrouting::Column_info_t; - try { - std::vector info{2}; - - info[0] = {-1, 0, true, "cost", pgrouting::ANY_NUMERICAL}; - info[1] = {-1, 0, true, "path", pgrouting::ANY_INTEGER_ARRAY}; - pgrouting::get_data(sql, rows, total_rows, true, info, &pgrouting::fetch_restriction); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); - } + std::vector info{ + {-1, 0, true, "cost", ANY_NUMERICAL}, + {-1, 0, true, "path", ANY_INTEGER_ARRAY}}; + + return get_data(sql, true, info, &fetch_restriction); } /** + For queries of the type: ~~~~{.c} SELECT id, capacity, speed, number - [start_node_id | start_x, start_y], start_open, start_close, start_service, - [end_node_id | end_x, end_y], end_open, end_close, end_service, + [start_node_id | start_x, start_y], start_open, start_close, start_service, + [end_node_id | end_x, end_y], end_open, end_close, end_service, FROM orders; ~~~~ - @param[in] sql The query - @param[out] rows of vehicles - @param[out] total_rows size of vehicles rows - @param[out] with_id flag to choose if its euclidean or matrix - @param[out] err_msg when not null, there was an error and contains the message + @param[in] sql The vehicles query + @param[in] with_id flag that idicates if id is to be used + @returns vector of `Vehicle_t` */ -void pgr_get_vehicles( - char *sql, - Vehicle_t **rows, - size_t *total_rows, - bool with_id, - char **err_msg) { - using pgrouting::pgr_msg; - using pgrouting::pgr_free; +std::vector get_vehicles(const std::string &sql, bool with_id) { using pgrouting::Column_info_t; - try { - std::vector info{16}; - - info[0] = {-1, 0, true, "id", pgrouting::ANY_INTEGER}; - info[1] = {-1, 0, true, "capacity", pgrouting::ANY_NUMERICAL}; - info[2] = {-1, 0, true, "start_x", pgrouting::ANY_NUMERICAL}; - info[3] = {-1, 0, true, "start_y", pgrouting::ANY_NUMERICAL}; - info[4] = {-1, 0, false, "number", pgrouting::ANY_INTEGER}; - info[5] = {-1, 0, false, "start_open", pgrouting::ANY_NUMERICAL}; - info[6] = {-1, 0, false, "start_close", pgrouting::ANY_NUMERICAL}; - info[7] = {-1, 0, false, "start_service", pgrouting::ANY_NUMERICAL}; - info[8] = {-1, 0, false, "end_x", pgrouting::ANY_NUMERICAL}; - info[9] = {-1, 0, false, "end_y", pgrouting::ANY_NUMERICAL}; - info[10] = {-1, 0, false, "end_open", pgrouting::ANY_NUMERICAL}; - info[11] = {-1, 0, false, "end_close", pgrouting::ANY_NUMERICAL}; - info[12] = {-1, 0, false, "end_service", pgrouting::ANY_NUMERICAL}; - info[13] = {-1, 0, false, "speed", pgrouting::ANY_NUMERICAL}; - /* nodes are going to be ignored*/ - info[14] = {-1, 0, false, "start_node_id", pgrouting::ANY_INTEGER}; - info[15] = {-1, 0, false, "end_node_id", pgrouting::ANY_INTEGER}; - - if (with_id) { - /* (x,y) values are ignored*/ - info[2].strict = false; - info[3].strict = false; - /* start nodes are compulsory*/ - info[14].strict = false; - } - - pgrouting::get_data(sql, rows, total_rows, with_id, info, &pgrouting::fetch_vehicle); - } catch (const std::string &ex) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg(ex.c_str()); - } catch(...) { - (*rows) = pgr_free(*rows); - (*total_rows) = 0; - *err_msg = pgr_msg("Caught unknown exception!"); + std::vector info{ + {-1, 0, true, "id", ANY_INTEGER}, + {-1, 0, true, "capacity", ANY_NUMERICAL}, + {-1, 0, true, "start_x", ANY_NUMERICAL}, + {-1, 0, true, "start_y", ANY_NUMERICAL}, + {-1, 0, false, "number", ANY_INTEGER}, + {-1, 0, false, "start_open", ANY_NUMERICAL}, + {-1, 0, false, "start_close", ANY_NUMERICAL}, + {-1, 0, false, "start_service", ANY_NUMERICAL}, + {-1, 0, false, "end_x", ANY_NUMERICAL}, + {-1, 0, false, "end_y", ANY_NUMERICAL}, + {-1, 0, false, "end_open", ANY_NUMERICAL}, + {-1, 0, false, "end_close", ANY_NUMERICAL}, + {-1, 0, false, "end_service", ANY_NUMERICAL}, + {-1, 0, false, "speed", ANY_NUMERICAL}, + /* nodes are going to be ignored*/ + {-1, 0, false, "start_node_id", ANY_INTEGER}, + {-1, 0, false, "end_node_id", ANY_INTEGER}}; + + if (with_id) { + /* (x,y) values are ignored*/ + info[2].strict = false; + info[3].strict = false; + /* start nodes are compulsory*/ + info[14].strict = false; } + + return get_data(sql, with_id, info, &fetch_vehicle); } + +} // namespace pgget +} // namespace pgrouting diff --git a/src/cpp_common/rule.cpp b/src/cpp_common/rule.cpp index c91203663b4..4f4377b18d3 100644 --- a/src/cpp_common/rule.cpp +++ b/src/cpp_common/rule.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: rule.cpp +File: rule.cpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -28,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "c_types/restriction_t.h" +#include "cpp_common/restriction_t.hpp" namespace pgrouting { diff --git a/src/cpp_common/trsp_pgfetch.cpp b/src/cpp_common/trsp_pgfetch.cpp new file mode 100644 index 00000000000..aa4a5028605 --- /dev/null +++ b/src/cpp_common/trsp_pgfetch.cpp @@ -0,0 +1,108 @@ +/*PGR-GNU***************************************************************** +File: trsp_pgfetch.cpp + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2023 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev +Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI +mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com +Copyright (c) 2016 Rohith Reddy +Copyright (c) 2016 Andrea Nardelli +mail: nrd.nardelli at gmail.com +Copyright (c) 2015 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev + + +------ + +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*/ +/** @file + +This is a copy of pgdata_fetchers.cpp + +The old version of TRSP +- Is the only function that has its own edge reader within its code, + hence the name of the file. +- The old version of TRSP will exist during 3.x series + + +Notes +- The only function that remains is `fetch_edge` +- The old version of TRSP will be removed on V4 + +@todo: V4 TODO Delete this file + */ + +#include "cpp_common/trsp_pgfetch.hpp" + +#include +#include +#include + +#include "cpp_common/get_check_data.hpp" + +#include "cpp_common/info_t.hpp" +#include "c_types/edge_rt.h" + + +namespace pgrouting { + +void fetch_edge( + const HeapTuple tuple, + const TupleDesc &tupdesc, + const std::vector &info, + int64_t *default_id, + Edge_t *edge, + size_t *valid_edges, + bool normal) { + if (pgrouting::column_found(info[0].colNumber)) { + edge->id = pgrouting::getBigInt(tuple, tupdesc, info[0]); + } else { + edge->id = *default_id; + ++(*default_id); + } + + if (normal) { + edge->source = pgrouting::getBigInt(tuple, tupdesc, info[1]); + edge->target = pgrouting::getBigInt(tuple, tupdesc, info[2]); + } else { + edge->target = pgrouting::getBigInt(tuple, tupdesc, info[1]); + edge->source = pgrouting::getBigInt(tuple, tupdesc, info[2]); + } + + edge->cost = pgrouting::getFloat8(tuple, tupdesc, info[3]); + + if (pgrouting::column_found(info[4].colNumber)) { + edge->reverse_cost = pgrouting::getFloat8(tuple, tupdesc, info[4]); + } else { + edge->reverse_cost = -1; + } + + edge->cost = std::isinf(edge->cost)? + DBL_MAX : edge->cost; + + edge->reverse_cost = std::isinf(edge->reverse_cost)? + DBL_MAX : edge->reverse_cost; + + *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1; + *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1; +} + + +} // namespace pgrouting diff --git a/src/cpp_common/trsp_pgget.cpp b/src/cpp_common/trsp_pgget.cpp new file mode 100644 index 00000000000..59dfe49a163 --- /dev/null +++ b/src/cpp_common/trsp_pgget.cpp @@ -0,0 +1,110 @@ +/*PGR-GNU***************************************************************** +File: trsp_pgget.cpp + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Copyright (c) 2023 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev +Copyright (c) 2020 Mahmoud SAKR and Esteban ZIMANYI +mail: m_attia_sakrcw at yahoo.com, estebanzimanyicw at gmail.com +Copyright (c) 2016 Rohith Reddy +Copyright (c) 2016 Andrea Nardelli +mail: nrd.nardelli at gmail.com +Copyright (c) 2015 Celia Virginia Vergara Castillo +mail: vicky at erosion.dev + + +------ + +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*/ +/** file + +This is a copy of pgdata_getters.cpp + +The old version of TRSP +- Is the only function that has its own edge reader within its code, + hence the name of the file. +- The old version of TRSP will exist during 3.x series + + +@note +- The only function that remains is `fetch_edge` +- The old version of TRSP will be removed on V4 + + @todo: V4 TODO Delete this file +*/ + +#include "c_common/trsp_pgget.h" +#include +#include +#include +#include + +#include "cpp_common/get_data.hpp" +#include "cpp_common/get_check_data.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/trsp_pgfetch.hpp" + +#include "cpp_common/info_t.hpp" +#include "c_types/edge_rt.h" + + +/** + For queries of the type: + ~~~~{.c} + SELECT id, source, target, cost, [reverse_cost] FROM edge_table; + ~~~~ + + @param[in] sql The query + @param[out] rows the edges array + @param[out] total_rows size of edges + @param[in] normal when false then the graph is reversed + @param[in] ignore_id when true id value of edge is ignored + @param[out] err_msg when not null, there was an error and contains the message + */ +void +pgr_get_edges( + char *sql, + Edge_t **rows, + size_t *total_rows, + bool normal, + bool ignore_id, + char **err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + using pgrouting::Column_info_t; + try { + std::vector info{ + {-1, 0, !ignore_id, "id", pgrouting::ANY_INTEGER}, + {-1, 0, true, "source", pgrouting::ANY_INTEGER}, + {-1, 0, true, "target", pgrouting::ANY_INTEGER}, + {-1, 0, true, "cost", pgrouting::ANY_NUMERICAL}, + {-1, 0, false, "reverse_cost", pgrouting::ANY_NUMERICAL}}; + + pgrouting::get_data(sql, rows, total_rows, normal, info, &pgrouting::fetch_edge); + } catch (const std::string &ex) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg(ex.c_str()); + } catch(...) { + (*rows) = pgr_free(*rows); + (*total_rows) = 0; + *err_msg = pgr_msg("Caught unknown exception!"); + } +} + diff --git a/src/dagShortestPath/dagShortestPath.c b/src/dagShortestPath/dagShortestPath.c index 5d4a12df543..74295b2a905 100644 --- a/src/dagShortestPath/dagShortestPath.c +++ b/src/dagShortestPath/dagShortestPath.c @@ -35,8 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" -#include "drivers/dagShortestPath/dagShortestPath_driver.h" // the link to the C++ code of the function +#include "drivers/dagShortestPath/dagShortestPath_driver.h" PGDLLEXPORT Datum _pgr_dagshortestpath(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_dagshortestpath); @@ -53,69 +52,18 @@ process( bool only_cost, Path_rt **result_tuples, size_t *result_count) { - /* - * https://www.postgresql.org/docs/current/static/spi-spi-connect.html - */ pgr_SPI_connect(); char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - - - - - PGR_DBG("Initializing arrays"); - size_t size_start_vidsArr = 0; - int64_t* start_vidsArr = NULL; - - size_t size_end_vidsArr = 0; - int64_t* end_vidsArr = NULL; - - size_t total_combinations = 0; - II_t_rt *combinations = NULL; - - if (starts && ends) { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - if (total_combinations == 0) { - if (combinations) - pfree(combinations); - pgr_SPI_finish(); - return; - } - } - (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - PGR_DBG("No edges found"); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_dagShortestPath( - edges, - total_edges, - combinations, - total_combinations, - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, + pgr_do_dagShortestPath( + edges_sql, + combinations_sql, + starts, ends, directed, only_cost, @@ -124,28 +72,15 @@ process( &log_msg, ¬ice_msg, &err_msg); - time_msg(" processing pgr_dagShortestPath", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); if (err_msg) { if (*result_tuples) pfree(*result_tuples); } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - - - if (end_vidsArr) pfree(end_vidsArr); - if (start_vidsArr) pfree(start_vidsArr); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ PGDLLEXPORT Datum _pgr_dagshortestpath(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; @@ -228,14 +163,17 @@ PGDLLEXPORT Datum _pgr_dagshortestpath(PG_FUNCTION_ARGS) { nulls[i] = false; } - // postgres starts counting from 1 + int64_t seq = funcctx->call_cntr == 0? 1 : result_tuples[funcctx->call_cntr - 1].start_id; + values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); values[4] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); + result_tuples[funcctx->call_cntr].start_id = result_tuples[funcctx->call_cntr].edge < 0? 1 : seq + 1; + tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); diff --git a/src/dagShortestPath/dagShortestPath_driver.cpp b/src/dagShortestPath/dagShortestPath_driver.cpp index 8ca6a0f63f5..10923ae6ea0 100644 --- a/src/dagShortestPath/dagShortestPath_driver.cpp +++ b/src/dagShortestPath/dagShortestPath_driver.cpp @@ -33,14 +33,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include +#include +#include -#include "dagShortestPath/pgr_dagShortestPath.hpp" - -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" - - +#include "dagShortestPath/dagShortestPath.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" namespace { @@ -48,25 +50,10 @@ template < class G > std::deque pgr_dagShortestPath( G &graph, - std::vector &combinations, - std::vector < int64_t > sources, - std::vector < int64_t > targets, + std::map> &combinations, bool only_cost = false) { - std::sort(sources.begin(), sources.end()); - sources.erase( - std::unique(sources.begin(), sources.end()), - sources.end()); - - std::sort(targets.begin(), targets.end()); - targets.erase( - std::unique(targets.begin(), targets.end()), - targets.end()); - - - pgrouting::Pgr_dag< G > fn_dag; - auto paths = combinations.empty() ? - fn_dag.dag(graph, sources, targets, only_cost) - : fn_dag.dag(graph, combinations, only_cost); + pgrouting::Pgr_dag fn_dag; + auto paths = fn_dag.dag(graph, combinations, only_cost); return paths; } @@ -74,88 +61,84 @@ pgr_dagShortestPath( } // namespace void -do_pgr_dagShortestPath( - Edge_t *data_edges, - size_t total_edges, - II_t_rt *combinations, - size_t total_combinations, - int64_t *start_vidsArr, - size_t size_start_vidsArr, - int64_t *end_vidsArr, - size_t size_end_vidsArr, +pgr_do_dagShortestPath( + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, + bool directed, bool only_cost, Path_rt **return_tuples, size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg) { + char **log_msg, + char **notice_msg, + char **err_msg) { using pgrouting::Path; using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; + using pgrouting::pgget::get_edges; + std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - pgassert(data_edges); - pgassert((start_vidsArr && end_vidsArr) || combinations); - pgassert((size_start_vidsArr && size_end_vidsArr) || total_combinations); - graphType gType = directed? DIRECTED: UNDIRECTED; + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + - log << "Inserting vertices into a c++ vector structure"; - std::vector - start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr); - std::vector< int64_t > - end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr); - std::vector< II_t_rt > - combinations_vector(combinations, combinations + total_combinations); + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); - std::deque< Path >paths; + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + std::deque paths; if (directed) { - log << "Working with directed Graph\n"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); - paths = pgr_dagShortestPath(digraph, - combinations_vector, - start_vertices, - end_vertices, - only_cost); + pgrouting::DirectedGraph graph; + graph.insert_edges(edges); + paths = pgr_dagShortestPath(graph, combinations, only_cost); } else { - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); - paths = pgr_dagShortestPath( - undigraph, - combinations_vector, - start_vertices, - end_vertices, - only_cost); + pgrouting::UndirectedGraph graph; + graph.insert_edges(edges); + paths = pgr_dagShortestPath(graph, combinations, only_cost); } - size_t count(0); - count = count_tuples(paths); + auto count = count_tuples(paths); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No paths found between start_vid and end_vid vertices"; + notice << "No paths found"; + *log_msg = pgr_msg(notice.str().c_str()); return; } (*return_tuples) = pgr_alloc(count, (*return_tuples)); - log << "\nConverting a set of paths into the tuples"; (*return_count) = (collapse_paths(return_tuples, paths)); *log_msg = log.str().empty()? @@ -170,6 +153,9 @@ do_pgr_dagShortestPath( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/dijkstra/dijkstra.c b/src/dijkstra/dijkstra.c index fa764c67e5a..0e47f3a6414 100644 --- a/src/dijkstra/dijkstra.c +++ b/src/dijkstra/dijkstra.c @@ -1,5 +1,4 @@ /*PGR-GNU***************************************************************** - File: dijkstra.c Generated with Template by: @@ -34,14 +33,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ #include - #include "c_common/postgres_connection.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/dijkstra/dijkstra_driver.h" PG_MODULE_MAGIC; @@ -53,7 +50,7 @@ static void process( char *edges_sql, - char* combinations_sql, + char *combinations_sql, ArrayType *starts, ArrayType *ends, @@ -70,60 +67,11 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - int64_t* start_vidsArr = NULL; - size_t size_start_vidsArr = 0; - - int64_t* end_vidsArr = NULL; - size_t size_end_vidsArr = 0; - - Edge_t *edges = NULL; - size_t total_edges = 0; - - II_t_rt *combinationsArr = NULL; - size_t total_combinations = 0; - - if (normal) { - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinationsArr, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - } else { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } - } else { - pgr_get_edges(edges_sql, &edges, &total_edges, false, false, &err_msg); - throw_error(err_msg, edges_sql); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } - - if (total_edges == 0) { - if (end_vidsArr) pfree(end_vidsArr); - if (start_vidsArr) pfree(start_vidsArr); - if (combinationsArr) pfree(combinationsArr); - pgr_SPI_finish(); - return; - } - - if (total_combinations == 0 && (size_end_vidsArr== 0 || size_start_vidsArr == 0)) { - if (edges) pfree(edges); - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); pgr_do_dijkstra( - edges, total_edges, - combinationsArr, total_combinations, - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, + edges_sql, + combinations_sql, + starts, ends, directed, only_cost, @@ -159,15 +107,8 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (start_vidsArr) pfree(start_vidsArr); - if (end_vidsArr) pfree(end_vidsArr); - if (combinationsArr) pfree(combinationsArr); pgr_SPI_finish(); } @@ -183,6 +124,7 @@ _pgr_dijkstra(PG_FUNCTION_ARGS) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + if (PG_NARGS() == 7) { /* kept for backwards compatibility * TODO remove on 4.0.0 */ @@ -274,8 +216,10 @@ _pgr_dijkstra(PG_FUNCTION_ARGS) { nulls[i] = false; } + int64_t seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; + values[0] = Int32GetDatum((int32_t)call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[call_cntr].seq); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); values[4] = Int64GetDatum(result_tuples[call_cntr].node); @@ -283,6 +227,8 @@ _pgr_dijkstra(PG_FUNCTION_ARGS) { values[6] = Float8GetDatum(result_tuples[call_cntr].cost); values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); + result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : seq + 1; + tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); @@ -290,4 +236,3 @@ _pgr_dijkstra(PG_FUNCTION_ARGS) { SRF_RETURN_DONE(funcctx); } } - diff --git a/src/dijkstra/dijkstraVia.c b/src/dijkstra/dijkstraVia.c index 4151503655e..149e766b49f 100644 --- a/src/dijkstra/dijkstraVia.c +++ b/src/dijkstra/dijkstraVia.c @@ -1,11 +1,12 @@ /*PGR-GNU***************************************************************** -File: dijkstraViaVertex.c +File: dijkstraVia.c Generated with Template by: Copyright (c) 2015 pgRouting developers Function's developer: Copyright (c) 2015 Celia Virginia Vergara Castillo +Mail: vicky at erosion.dev ------ @@ -26,13 +27,13 @@ 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/pgdata_getters.h" #include "drivers/dijkstra/dijkstraVia_driver.h" PGDLLEXPORT Datum _pgr_dijkstravia(PG_FUNCTION_ARGS); @@ -52,26 +53,11 @@ process(char* edges_sql, char* notice_msg = NULL; char* err_msg = NULL; - size_t size_via_vidsArr = 0; - int64_t* via_vidsArr = pgr_get_bigIntArray(&size_via_vidsArr, vias, false, &err_msg); - throw_error(err_msg, "While getting via vertices"); - - Edge_t* edges = NULL; - size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - if (via_vidsArr) pfree(via_vidsArr); - pgr_SPI_finish(); - return; - } - PGR_DBG("Starting timer"); clock_t start_t = clock(); - do_pgr_dijkstraVia( - edges, total_edges, - via_vidsArr, size_via_vidsArr, + pgr_do_dijkstraVia( + edges_sql, + vias, directed, strict, U_turn_on_edge, @@ -87,14 +73,8 @@ process(char* edges_sql, (*result_tuples) = NULL; (*result_count) = 0; } + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (via_vidsArr) pfree(via_vidsArr); pgr_SPI_finish(); } @@ -104,25 +84,14 @@ _pgr_dijkstravia(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); - - /********************************************************************** - * pgr_dijkstraVia(edges_sql text, - * vertices anyarray, - * directed boolean default true, - * strict boolean default false, - * U_turn_on_edge boolean default false, - **********************************************************************/ - process( text_to_cstring(PG_GETARG_TEXT_P(0)), PG_GETARG_ARRAYTYPE_P(1), @@ -132,8 +101,6 @@ _pgr_dijkstravia(PG_FUNCTION_ARGS) { &result_tuples, &result_count); - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -159,20 +126,6 @@ _pgr_dijkstravia(PG_FUNCTION_ARGS) { bool* nulls; size_t call_cntr = funcctx->call_cntr; - /**********************************************************************/ - /* - 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 - */ - size_t numb_out = 10; values = palloc(numb_out * sizeof(Datum)); nulls = palloc(numb_out * sizeof(bool)); @@ -181,7 +134,6 @@ _pgr_dijkstravia(PG_FUNCTION_ARGS) { nulls[i] = false; } - // postgres starts counting from 1 values[0] = Int32GetDatum((int32_t)call_cntr + 1); values[1] = Int32GetDatum(result_tuples[call_cntr].path_id); values[2] = Int32GetDatum(result_tuples[call_cntr].path_seq + 1); @@ -193,8 +145,6 @@ _pgr_dijkstravia(PG_FUNCTION_ARGS) { 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); diff --git a/src/dijkstra/dijkstraVia_driver.cpp b/src/dijkstra/dijkstraVia_driver.cpp index 4ac213d5226..0fb0842e174 100644 --- a/src/dijkstra/dijkstraVia_driver.cpp +++ b/src/dijkstra/dijkstraVia_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: dijkstraViaVertex_driver.cpp +File: dijkstraVia_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -30,11 +30,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "dijkstra/pgr_dijkstraVia.hpp" #include "c_types/routes_t.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "dijkstra/dijkstraVia.hpp" namespace { @@ -87,9 +89,10 @@ get_route( } // namespace void -do_pgr_dijkstraVia( - Edge_t* data_edges, size_t total_edges, - int64_t* via_vidsArr, size_t size_via_vidsArr, +pgr_do_dijkstraVia( + char *edges_sql, + ArrayType* viaArr, + bool directed, bool strict, bool U_turn_on_edge, @@ -102,44 +105,52 @@ do_pgr_dijkstraVia( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intArray; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - graphType gType = directed? DIRECTED: UNDIRECTED; - std::deque< Path >paths; - log << "\nInserting vertices into a c++ vector structure"; - std::vector< int64_t > via_vertices( - via_vidsArr, via_vidsArr + size_via_vidsArr); + auto via = get_intArray(viaArr, false); + + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + std::dequepaths; if (directed) { - log << "\nWorking with directed Graph"; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); pgrouting::pgr_dijkstraVia( digraph, - via_vertices, + via, paths, strict, U_turn_on_edge, log); } else { - log << "\nWorking with Undirected Graph"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); pgrouting::pgr_dijkstraVia( undigraph, - via_vertices, + via, paths, strict, U_turn_on_edge, @@ -175,6 +186,9 @@ do_pgr_dijkstraVia( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; @@ -189,5 +203,3 @@ do_pgr_dijkstraVia( *log_msg = pgr_msg(log.str().c_str()); } } - - diff --git a/src/dijkstra/dijkstra_driver.cpp b/src/dijkstra/dijkstra_driver.cpp index 3539f1c1b56..5c9aecc51fd 100644 --- a/src/dijkstra/dijkstra_driver.cpp +++ b/src/dijkstra/dijkstra_driver.cpp @@ -39,16 +39,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "c_types/ii_t_rt.h" -#include "cpp_common/combinations.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "dijkstra/dijkstra.hpp" -namespace detail { +namespace { void post_process(std::deque &paths, bool only_cost, bool normal, size_t n_goals, bool global) { @@ -98,16 +99,15 @@ post_process(std::deque &paths, bool only_cost, bool normal, si } } -} // namespace detail +} // namespace void pgr_do_dijkstra( - Edge_t *data_edges, size_t total_edges, - - II_t_rt *combinationsArr, size_t total_combinations, - int64_t *start_vidsArr, size_t size_start_vidsArr, - int64_t *end_vidsArr, size_t size_end_vidsArr, + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, bool directed, bool only_cost, @@ -117,50 +117,66 @@ pgr_do_dijkstra( Path_rt **return_tuples, size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg) { + char **log_msg, + char **notice_msg, + char **err_msg) { using pgrouting::Path; using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_combinations != 0 || (size_start_vidsArr != 0 && size_end_vidsArr != 0)); - graphType gType = directed? DIRECTED: UNDIRECTED; + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, normal); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + + + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), normal, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; size_t n = n_goals <= 0? (std::numeric_limits::max)() : static_cast(n_goals); std::dequepaths; - auto combinations = total_combinations? - pgrouting::utilities::get_combinations(combinationsArr, total_combinations) - : pgrouting::utilities::get_combinations(start_vidsArr, size_start_vidsArr, end_vidsArr, size_end_vidsArr); - if (directed) { - pgrouting::DirectedGraph graph(gType); - graph.insert_edges(data_edges, total_edges); + pgrouting::DirectedGraph graph; + graph.insert_edges(edges); paths = pgrouting::algorithms::dijkstra(graph, combinations, only_cost, n); } else { - pgrouting::UndirectedGraph graph(gType); - graph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph graph; + graph.insert_edges(edges); paths = pgrouting::algorithms::dijkstra(graph, combinations, only_cost, n); } - detail::post_process(paths, only_cost, normal, n, global); + post_process(paths, only_cost, normal, n, global); combinations.clear(); - size_t count(0); - count = count_tuples(paths); + auto count = count_tuples(paths); if (count == 0) { (*return_tuples) = NULL; @@ -185,6 +201,9 @@ pgr_do_dijkstra( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/dominator/lengauerTarjanDominatorTree.c b/src/dominator/lengauerTarjanDominatorTree.c index fc5eaafea06..6eea54f4412 100644 --- a/src/dominator/lengauerTarjanDominatorTree.c +++ b/src/dominator/lengauerTarjanDominatorTree.c @@ -35,7 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" #include "c_types/ii_t_rt.h" -#include "c_common/pgdata_getters.h" #include "drivers/dominator/lengauerTarjanDominatorTree_driver.h" @@ -55,26 +54,15 @@ process(char* edges_sql, char* notice_msg = NULL; char* err_msg = NULL; - size_t total_edges = 0; - Edge_t* edges = NULL; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - do_pgr_LTDTree( - edges, total_edges, + pgr_do_LTDTree( + edges_sql, + root_vertex, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg("processing pgr_LTDTree()", start_t, clock()); @@ -84,12 +72,8 @@ process(char* edges_sql, (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); pgr_SPI_finish(); } @@ -98,17 +82,13 @@ _pgr_lengauertarjandominatortree(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ II_t_rt *result_tuples = NULL; 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)), @@ -116,8 +96,6 @@ _pgr_lengauertarjandominatortree(PG_FUNCTION_ARGS) { &result_tuples, &result_count); - - /**********************************************************************/ funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; diff --git a/src/dominator/lengauerTarjanDominatorTree_driver.cpp b/src/dominator/lengauerTarjanDominatorTree_driver.cpp index 714d57071a1..b9d014dc2bb 100644 --- a/src/dominator/lengauerTarjanDominatorTree_driver.cpp +++ b/src/dominator/lengauerTarjanDominatorTree_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: lengauerTarjanDominatorTree_driver.pp +File: lengauerTarjanDominatorTree_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,30 +27,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ - - +#include "drivers/dominator/lengauerTarjanDominatorTree_driver.h" #include #include #include #include #include + +#include "cpp_common/pgdata_getters.hpp" #include "cpp_common/identifiers.hpp" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/alloc.hpp" #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/base_graph.hpp" #include "c_types/ii_t_rt.h" -#include "drivers/dominator/lengauerTarjanDominatorTree_driver.h" -#include "dominator/pgr_lengauerTarjanDominatorTree_driver.hpp" +#include "dominator/lengauerTarjanDominatorTree_driver.hpp" -/************************************************************ - edges_sql TEXT - ***********************************************************/ void -do_pgr_LTDTree( - Edge_t *data_edges, - size_t total_edges, +pgr_do_LTDTree( + char *edges_sql, + int64_t root_vertex, II_t_rt **return_tuples, size_t *return_count, @@ -65,23 +62,28 @@ do_pgr_LTDTree( std::ostringstream log; std::ostringstream notice; std::ostringstream err; - + char *hint = nullptr; try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - std::string logstr; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; -/***********************Working with graph**************************/ + std::string logstr; - graphType gType = DIRECTED; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); std::vector results; pgrouting::functions::Pgr_LTDTree fn_LTDTree; results = fn_LTDTree.pgr_ltdtree(digraph, root_vertex); @@ -122,6 +124,9 @@ do_pgr_LTDTree( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/driving_distance/CMakeLists.txt b/src/driving_distance/CMakeLists.txt index 9d568dfd70c..ff953c003df 100644 --- a/src/driving_distance/CMakeLists.txt +++ b/src/driving_distance/CMakeLists.txt @@ -1,7 +1,7 @@ ADD_LIBRARY(driving_distance OBJECT - many_to_dist_driving_distance.c - many_to_dist_withPointsDD.c + driving_distance.c + driving_distance_withPoints.c - drivedist_driver.cpp - withPoints_dd_driver.cpp - ) + driving_distance_driver.cpp + driving_distance_withPoints_driver.cpp +) diff --git a/src/driving_distance/many_to_dist_driving_distance.c b/src/driving_distance/driving_distance.c similarity index 88% rename from src/driving_distance/many_to_dist_driving_distance.c rename to src/driving_distance/driving_distance.c index 03e7300436a..d687beb3dad 100644 --- a/src/driving_distance/many_to_dist_driving_distance.c +++ b/src/driving_distance/driving_distance.c @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: many_to_dist_driving_distance.c +File: driving_distance.c Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -35,8 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" -#include "drivers/driving_distance/drivedist_driver.h" +#include "drivers/driving_distance/driving_distance_driver.h" PGDLLEXPORT Datum _pgr_drivingdistance(PG_FUNCTION_ARGS); @@ -49,7 +48,7 @@ static void process( char* edges_sql, ArrayType *starts, - float8 distance, + double distance, bool directed, bool equicost, MST_rt **result_tuples, @@ -59,24 +58,10 @@ void process( char* notice_msg = NULL; char* err_msg = NULL; - size_t size_start_vidsArr = 0; - int64_t* start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - - Edge_t *edges = NULL; - size_t total_tuples = 0; - pgr_get_edges(edges_sql, &edges, &total_tuples, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_tuples == 0) { - return; - } - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - pgr_do_drivingdist( - edges, total_tuples, - start_vidsArr, size_start_vidsArr, + pgr_do_drivingDistance( + edges_sql, + starts, distance, directed, equicost, @@ -94,13 +79,7 @@ void process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (start_vidsArr) pfree(start_vidsArr); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } diff --git a/src/driving_distance/drivedist_driver.cpp b/src/driving_distance/driving_distance_driver.cpp similarity index 73% rename from src/driving_distance/drivedist_driver.cpp rename to src/driving_distance/driving_distance_driver.cpp index a086152fd77..e41e38967d4 100644 --- a/src/driving_distance/drivedist_driver.cpp +++ b/src/driving_distance/driving_distance_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: drivedist_driver.cpp +File: driving_distance_driver.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -27,26 +27,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "drivers/driving_distance/drivedist_driver.h" +#include "drivers/driving_distance/driving_distance_driver.h" #include #include #include +#include #include +#include "cpp_common/pgdata_getters.hpp" #include "dijkstra/drivingDist.hpp" #include "c_types/mst_rt.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" void -pgr_do_drivingdist( - Edge_t *data_edges, size_t total_edges, - int64_t *start_vertex, size_t s_len, +pgr_do_drivingDistance( + char *edges_sql, + ArrayType* starts, double distance, - bool directedFlag, + bool directed, bool equiCostFlag, MST_rt **return_tuples, size_t *return_count, char **log_msg, @@ -56,13 +58,15 @@ pgr_do_drivingdist( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::algorithm::drivingDistance; + using pgrouting::pgget::get_intSet; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); @@ -70,21 +74,29 @@ pgr_do_drivingdist( pgassert(*return_count == 0); pgassert((*return_tuples) == NULL); - graphType gType = directedFlag? DIRECTED: UNDIRECTED; + auto roots = get_intSet(starts); - std::deque paths; - std::vector start_vertices(start_vertex, start_vertex + s_len); + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + std::deque paths; std::vector> depths; - if (directedFlag) { - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); - paths = pgr_drivingdistance(digraph, start_vertices, distance, equiCostFlag, depths, true); + if (directed) { + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); + paths = drivingDistance(digraph, roots, distance, equiCostFlag, depths, true); } else { - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); - paths = pgr_drivingdistance(undigraph, start_vertices, distance, equiCostFlag, depths, true); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); + paths = drivingDistance(undigraph, roots, distance, equiCostFlag, depths, true); } size_t count(count_tuples(paths)); @@ -124,6 +136,9 @@ pgr_do_drivingdist( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/driving_distance/many_to_dist_withPointsDD.c b/src/driving_distance/driving_distance_withPoints.c similarity index 78% rename from src/driving_distance/many_to_dist_withPointsDD.c rename to src/driving_distance/driving_distance_withPoints.c index 6c97f3c1545..236f23546c7 100644 --- a/src/driving_distance/many_to_dist_withPointsDD.c +++ b/src/driving_distance/driving_distance_withPoints.c @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: many_to_dist_driving_distance.c +File: driving_distance_withPoints.c Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -30,22 +30,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" +#include "c_types/mst_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_types/mst_rt.h" - -#include "c_common/pgdata_getters.h" - #include "drivers/withPoints/get_new_queries.h" -#include "drivers/driving_distance/withPoints_dd_driver.h" - +#include "drivers/driving_distance/driving_distance_withPoints_driver.h" PGDLLEXPORT Datum _pgr_withpointsddv4(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_withpointsddv4); static -void process( +void +process( char* edges_sql, char* points_sql, ArrayType* starts, @@ -62,18 +59,18 @@ void process( char d_side = estimate_drivingSide(driving_side[0]); if (is_new) { if (d_side == ' ') { - throw_error("Invalid value of 'driving side'", "Valid value are 'r', 'l', 'b'"); + pgr_throw_error("Invalid value of 'driving side'", "Valid value are 'r', 'l', 'b'"); return; } else if (directed && !(d_side == 'r' || d_side == 'l')) { - throw_error("Invalid value of 'driving side'", "Valid values are for directed graph are: 'r', 'l'"); + pgr_throw_error("Invalid value of 'driving side'", "Valid values are for directed graph are: 'r', 'l'"); return; } else if (!directed && !(d_side == 'b')) { - throw_error("Invalid value of 'driving side'", "Valid values are for undirected graph is: 'b'"); + pgr_throw_error("Invalid value of 'driving side'", "Valid values are for undirected graph is: 'b'"); return; } } else { /* TODO remove on v4 */ - char d_side = (char)tolower(driving_side[0]); + d_side = (char)tolower(driving_side[0]); if (!((d_side == 'r') || (d_side == 'l'))) d_side = 'b'; } @@ -82,16 +79,6 @@ void process( char* notice_msg = NULL; char* err_msg = NULL; - size_t total_starts = 0; - int64_t* start_pidsArr = pgr_get_bigIntArray(&total_starts, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - PGR_DBG("sourcesArr size %ld ", total_starts); - - Point_on_edge_t *points = NULL; - size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points, &err_msg); - throw_error(err_msg, points_sql); - char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; get_new_queries( @@ -100,35 +87,12 @@ void process( &edges_no_points_query); - Edge_t *edges_of_points = NULL; - size_t total_edges_of_points = 0; - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); - throw_error(err_msg, edges_of_points_query); - - Edge_t *edges = NULL; - size_t total_edges = 0; - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_no_points_query); - - PGR_DBG("freeing allocated memory not used anymore"); - pfree(edges_of_points_query); - pfree(edges_no_points_query); - - if ((total_edges + total_edges_of_points) == 0) { - if (edges) pfree(edges); - if (edges_of_points) pfree(edges_of_points); - if (points) pfree(points); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting timer"); clock_t start_t = clock(); pgr_do_withPointsDD( - edges, total_edges, - points, total_points, - edges_of_points, total_edges_of_points, - start_pidsArr, total_starts, + edges_no_points_query, + points_sql, + edges_of_points_query, + starts, distance, d_side, @@ -148,20 +112,11 @@ void process( (*result_tuples) = NULL; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (edges_of_points) pfree(edges_of_points); - if (points) pfree(points); - if (start_pidsArr) pfree(start_pidsArr); pgr_SPI_finish(); } - - PGDLLEXPORT Datum _pgr_withpointsddv4(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; @@ -201,8 +156,8 @@ _pgr_withpointsddv4(PG_FUNCTION_ARGS) { funcctx->tuple_desc = tuple_desc; MemoryContextSwitchTo(oldcontext); } - funcctx = SRF_PERCALL_SETUP(); + funcctx = SRF_PERCALL_SETUP(); tuple_desc = funcctx->tuple_desc; result_tuples = (MST_rt*) funcctx->user_fctx; diff --git a/src/driving_distance/withPoints_dd_driver.cpp b/src/driving_distance/driving_distance_withPoints_driver.cpp similarity index 65% rename from src/driving_distance/withPoints_dd_driver.cpp rename to src/driving_distance/driving_distance_withPoints_driver.cpp index 5e9ec658221..6816f2589ae 100644 --- a/src/driving_distance/withPoints_dd_driver.cpp +++ b/src/driving_distance/driving_distance_withPoints_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: withPoints_dd_driver.cpp +File: driving_distance_withPoints.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -30,27 +30,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "drivers/driving_distance/withPoints_dd_driver.h" +#include "drivers/driving_distance/driving_distance_withPoints_driver.h" #include #include #include #include +#include #include +#include "cpp_common/pgdata_getters.hpp" #include "dijkstra/drivingDist.hpp" -#include "withPoints/pgr_withPoints.hpp" +#include "withPoints/withPoints.hpp" #include "c_types/mst_rt.h" - -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/alloc.hpp" void pgr_do_withPointsDD( - 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 *start_pidsArr, size_t s_len, + char *edges_sql, + char *points_sql, + char *edges_of_points_sql, + ArrayType* starts, double distance, char driving_side, @@ -67,30 +69,47 @@ pgr_do_withPointsDD( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intSet; + using pgrouting::utilities::get_combinations; + using pgrouting::pgget::get_points; + using pgrouting::pgget::get_edges; + using pgrouting::algorithm::drivingDistance; std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); - pgassert((*return_count) == 0); - pgassert(edges); - pgassert(start_pidsArr); - - - 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); + pgassert(*return_count == 0); + + auto roots = get_intSet(starts); + + hint = points_sql; + auto points = get_points(std::string(points_sql)); + + hint = edges_of_points_sql; + auto edges_of_points = get_edges(std::string(edges_of_points_sql), true, false); + + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + + if (edges.size() + edges_of_points.size() == 0) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + /* + * processing points + */ + pgrouting::Pg_points_graph pg_graph(points, edges_of_points, + true, driving_side, directed); if (pg_graph.has_error()) { log << pg_graph.get_log(); @@ -100,42 +119,41 @@ pgr_do_withPointsDD( return; } - std::vector start_vids(start_pidsArr, start_pidsArr + s_len); - graphType gType = directed? DIRECTED: UNDIRECTED; std::deque paths; std::vector> depths; if (directed) { - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); digraph.insert_edges(pg_graph.new_edges()); - paths = pgr_drivingdistance(digraph, start_vids, distance, equiCost, depths, details); + paths = drivingDistance(digraph, roots, distance, equiCost, depths, details); } else { - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); undigraph.insert_edges(pg_graph.new_edges()); - paths = pgr_drivingdistance(undigraph, start_vids, distance, equiCost, depths, details); + paths = drivingDistance(undigraph, roots, distance, equiCost, depths, details); } if (!details) { - for (auto &path : paths) { - pg_graph.eliminate_details_dd(path); - } + for (auto &path : paths) pg_graph.eliminate_details_dd(path); } - size_t count(count_tuples(paths)); + auto count(count_tuples(paths)); + if (count == 0) { - log << "\nNo return values were found"; - *notice_msg = pgr_msg(log.str().c_str()); + (*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 = collapse_paths(return_tuples, paths); + (*return_tuples) = pgr_alloc(count, (*return_tuples)); + (*return_count) = (collapse_paths(return_tuples, paths)); for (size_t i = 0; i < count; i++) { auto row = (*return_tuples)[i]; @@ -170,6 +188,9 @@ pgr_do_withPointsDD( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/ksp/ksp.c b/src/ksp/ksp.c index 113ddc5aaaf..5476f588bdb 100644 --- a/src/ksp/ksp.c +++ b/src/ksp/ksp.c @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ - #include #include "c_common/postgres_connection.h" @@ -37,7 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/yen/ksp_driver.h" @@ -45,9 +43,10 @@ PGDLLEXPORT Datum _pgr_ksp(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_ksp); static -void process( - char* edges_sql, - char* combinations_sql, +void +process( + char *edges_sql, + char *combinations_sql, ArrayType *starts, ArrayType *ends, @@ -57,59 +56,25 @@ void process( int p_k, bool directed, bool heap_paths, - Path_rt **result_tuples, size_t *result_count) { + Path_rt **result_tuples, + size_t *result_count) { pgr_SPI_connect(); char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; if (p_k < 0) { - return; - } - - size_t k = (size_t)p_k; - - int64_t* start_vidsArr = NULL; - size_t size_start_vidsArr = 0; - - int64_t* end_vidsArr = NULL; - size_t size_end_vidsArr = 0; - - II_t_rt *combinations = NULL; - size_t total_combinations = 0; - - if (start_vertex && end_vertex) { - start_vidsArr = start_vertex; size_start_vidsArr = 1; - end_vidsArr = end_vertex; size_end_vidsArr = 1; - } else if (starts && ends) { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - } - - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - PGR_DBG("No edges found"); - pgr_SPI_finish(); + /* TODO return error message */ return; } clock_t start_t = clock(); - pgr_do_ksp( - edges, total_edges, - combinations, total_combinations, - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, - k, + edges_sql, + combinations_sql, + starts, ends, + + start_vertex, end_vertex, + (size_t) p_k, directed, heap_paths, result_tuples, @@ -125,33 +90,17 @@ void process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - - if (start_vertex && end_vertex) { - start_vidsArr = NULL; - end_vidsArr = NULL; - } - if (start_vidsArr) pfree(start_vidsArr); - if (end_vidsArr) pfree(end_vidsArr); - - - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - pfree(edges); pgr_SPI_finish(); } - - PGDLLEXPORT Datum _pgr_ksp(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; Path_rt *path = NULL; + size_t result_count = 0; if (SRF_IS_FIRSTCALL()) { @@ -159,7 +108,6 @@ _pgr_ksp(PG_FUNCTION_ARGS) { funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - if (PG_NARGS() == 7) { /* * many to many @@ -207,38 +155,33 @@ _pgr_ksp(PG_FUNCTION_ARGS) { } funcctx->max_calls = result_count; - funcctx->user_fctx = path; if (get_call_result_type(fcinfo, NULL, &tuple_desc) - != TYPEFUNC_COMPOSITE) + != TYPEFUNC_COMPOSITE) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function returning record called in context " - "that cannot accept type record\n"))); + "that cannot accept type record"))); + } funcctx->tuple_desc = tuple_desc; MemoryContextSwitchTo(oldcontext); } - funcctx = SRF_PERCALL_SETUP(); - - tuple_desc = funcctx->tuple_desc; path = (Path_rt*) funcctx->user_fctx; if (funcctx->call_cntr < funcctx->max_calls) { HeapTuple tuple; Datum result; - Datum *values; - bool* nulls; + Datum *values; + bool* nulls; size_t n = (PG_NARGS() == 6)? 7 : 9; - values = palloc(n * sizeof(Datum)); nulls = palloc(n * sizeof(bool)); - size_t i; for (i = 0; i < n; ++i) { nulls[i] = false; @@ -252,10 +195,11 @@ _pgr_ksp(PG_FUNCTION_ARGS) { path_id = path[funcctx->call_cntr - 1].start_id; } } + int64_t seq = funcctx->call_cntr == 0? 1 : path[funcctx->call_cntr - 1].end_id; values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); values[1] = Int32GetDatum((int32_t)path_id); - values[2] = Int32GetDatum(path[funcctx->call_cntr].seq); + values[2] = Int32GetDatum((int32_t)seq); if (PG_NARGS() != 6) { values[3] = Int64GetDatum(path[funcctx->call_cntr].start_id); values[4] = Int64GetDatum(path[funcctx->call_cntr].end_id); @@ -266,11 +210,12 @@ _pgr_ksp(PG_FUNCTION_ARGS) { values[n - 1] = Float8GetDatum(path[funcctx->call_cntr].agg_cost); path[funcctx->call_cntr].start_id = path_id; + path[funcctx->call_cntr].end_id = path[funcctx->call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); - } else { /* do when there is no more left */ + } else { SRF_RETURN_DONE(funcctx); } } diff --git a/src/ksp/ksp_driver.cpp b/src/ksp/ksp_driver.cpp index b231760a2dd..96a8a5fd1d1 100644 --- a/src/ksp/ksp_driver.cpp +++ b/src/ksp/ksp_driver.cpp @@ -34,81 +34,111 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "yen/pgr_ksp.hpp" +#include "yen/ksp.hpp" -#include "cpp_common/combinations.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" - -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "c_types/ii_t_rt.h" -void pgr_do_ksp( - Edge_t *data_edges, size_t total_edges, - II_t_rt *combinationsArr, size_t total_combinations, - int64_t* start_vids, size_t size_start_vids, - int64_t * end_vids, size_t size_end_vids, +void pgr_do_ksp( + char* edges_sql, + char* combinations_sql, + ArrayType* starts, + ArrayType* ends, + + int64_t *start_vid, + int64_t *end_vid, + size_t k, bool directed, bool heap_paths, Path_rt **return_tuples, size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg) { + char **log_msg, + char **notice_msg, + char **err_msg) { using pgrouting::Path; using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; using pgrouting::yen::Pgr_ksp; std::ostringstream err; std::ostringstream log; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - auto combinations = total_combinations? - pgrouting::utilities::get_combinations(combinationsArr, total_combinations) - : pgrouting::utilities::get_combinations(start_vids, size_start_vids, end_vids, size_end_vids); - graphType gType = directed? DIRECTED: UNDIRECTED; - std::deque< Path > paths; + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (start_vid && end_vid) { + combinations[*start_vid].insert(*end_vid); + } + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + std::dequepaths; if (directed) { - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); - paths = pgrouting::algorithms::Yen(digraph, combinations, k, heap_paths); + pgrouting::DirectedGraph graph; + graph.insert_edges(edges); + paths = pgrouting::algorithms::Yen(graph, combinations, k, heap_paths); } else { - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); - paths = pgrouting::algorithms::Yen(undigraph, combinations, k, heap_paths); + pgrouting::UndirectedGraph graph; + graph.insert_edges(edges); + paths = pgrouting::algorithms::Yen(graph, combinations, k, heap_paths); } + combinations.clear(); + auto count = count_tuples(paths); - auto 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; + } - if (!(count == 0)) { - *return_tuples = NULL; - *return_tuples = pgr_alloc(count, (*return_tuples)); + (*return_tuples) = pgr_alloc(count, (*return_tuples)); + (*return_count) = (collapse_paths(return_tuples, paths)); - size_t sequence = 0; - for (const auto &path : paths) { - if (path.size() > 0) - path.get_pg_nksp_path(return_tuples, sequence); - } + size_t sequence = 0; + for (const auto &path : paths) { + if (path.size() > 0) path.get_pg_nksp_path(return_tuples, sequence); } *return_count = count; - pgassert(*err_msg == NULL); *log_msg = log.str().empty()? *log_msg : pgr_msg(log.str().c_str()); @@ -121,6 +151,9 @@ void pgr_do_ksp( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/ksp/turnRestrictedPath.c b/src/ksp/turnRestrictedPath.c index c8a1dd93919..e0de7adbf86 100644 --- a/src/ksp/turnRestrictedPath.c +++ b/src/ksp/turnRestrictedPath.c @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/yen/turnRestrictedPath_driver.h" @@ -81,32 +80,11 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - - Edge_t *edges = NULL; - size_t total_edges = 0; - - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - Restriction_t *restrictions = NULL; - size_t total_restrictions = 0; - - pgr_get_restrictions(restrictions_sql, &restrictions, &total_restrictions, &err_msg); - throw_error(err_msg, restrictions_sql); - - if (total_edges == 0) { - PGR_DBG("No edges found"); - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); - do_pgr_turnRestrictedPath( - edges, - total_edges, - restrictions, - total_restrictions, + pgr_do_turnRestrictedPath( + edges_sql, + restrictions_sql, + start_vid, end_vid, k, @@ -126,13 +104,7 @@ process( if (err_msg) { if (*path) pfree(*path); } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) {pfree(edges); edges = 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;} - if (restrictions) {pfree(restrictions); edges = NULL;} + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } @@ -151,26 +123,6 @@ _pgr_turnrestrictedpath(PG_FUNCTION_ARGS) { oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - /* - TEXT, -- edges_sql - TEXT, -- restrictions_sql - BIGINT, -- start_vertex - BIGINT, -- end_vertex - INTEGER,-- K cycles - directed BOOLEAN DEFAULT true, - heap_paths BOOLEAN DEFAULT false, - stop_on_first BOOLEAN DEFAULT true, - - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT) - **********************************************************************/ - - PGR_DBG("Calling process"); process( text_to_cstring(PG_GETARG_TEXT_P(0)), @@ -210,17 +162,6 @@ _pgr_turnrestrictedpath(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - /**********************************************************************/ - /* MODIFY AS NEEDED */ - /* - OUT seq INTEGER, - OUT path_seq INTEGER, - OUT node BIGINT, - OUT edge BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT - ***********************************************************************/ - size_t v_count = 7; values = palloc(v_count * sizeof(Datum)); @@ -232,14 +173,17 @@ _pgr_turnrestrictedpath(PG_FUNCTION_ARGS) { nulls[i] = false; } + int64_t seq = funcctx->call_cntr == 0? 1 : path[funcctx->call_cntr - 1].start_id; + values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); values[1] = Int32GetDatum((int32_t)path[funcctx->call_cntr].start_id + 1); - values[2] = Int32GetDatum(path[funcctx->call_cntr].seq); + values[2] = Int32GetDatum((int32_t)seq); values[3] = Int64GetDatum(path[funcctx->call_cntr].node); values[4] = Int64GetDatum(path[funcctx->call_cntr].edge); values[5] = Float8GetDatum(path[funcctx->call_cntr].cost); values[6] = Float8GetDatum(path[funcctx->call_cntr].agg_cost); + path[funcctx->call_cntr].start_id = path[funcctx->call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/ksp/turnRestrictedPath_driver.cpp b/src/ksp/turnRestrictedPath_driver.cpp index 9fd20409d90..d79b49a9c50 100644 --- a/src/ksp/turnRestrictedPath_driver.cpp +++ b/src/ksp/turnRestrictedPath_driver.cpp @@ -34,14 +34,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "cpp_common/rule.hpp" #include "cpp_common/basePath_SSEC.hpp" -#include "c_types/restriction_t.h" -#include "yen/pgr_turnRestrictedPath.hpp" +#include "cpp_common/restriction_t.hpp" +#include "yen/turnRestrictedPath.hpp" namespace { @@ -77,12 +78,9 @@ pgr_dijkstraTR( } // namespace void -do_pgr_turnRestrictedPath( - Edge_t *data_edges, - size_t total_edges, - - Restriction_t *restrictions, - size_t total_restrictions, +pgr_do_turnRestrictedPath( + char *edges_sql, + char *restrictions_sql, int64_t start_vid, int64_t end_vid, @@ -105,39 +103,49 @@ do_pgr_turnRestrictedPath( using pgrouting::pgr_free; using pgrouting::yen::Pgr_turnRestrictedPath; using pgrouting::trsp::Rule; + using pgrouting::pgget::get_restrictions; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - std::vector ruleList; - for (size_t i = 0; i < total_restrictions; ++i) { - ruleList.push_back(Rule(*(restrictions + i))); - } - log << "\n---------------------------------------\nRestrictions data\n"; - for (const auto &r : ruleList) { - log << r << "\n"; + + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; } - log <<"------------------------------------------------------------\n"; + hint = nullptr; - graphType gType = directed? DIRECTED: UNDIRECTED; + hint = restrictions_sql; + auto restrictions = restrictions_sql? + get_restrictions(std::string(restrictions_sql)) + : std::vector(); + hint = nullptr; - std::vector < Edge_t > edges(data_edges, data_edges + total_edges); + std::vector ruleList; + for (const auto &r : restrictions) { + ruleList.push_back(Rule(r)); + } std::deque paths; std::string logstr; if (directed) { log << "Working with directed Graph\n"; - pgrouting::DirectedGraph digraph(gType); + pgrouting::DirectedGraph digraph; Pgr_turnRestrictedPath < pgrouting::DirectedGraph > fn_TRSP; digraph.insert_edges(edges); log << digraph; @@ -154,9 +162,9 @@ do_pgr_turnRestrictedPath( strict); } else { log << "TODO Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); + pgrouting::UndirectedGraph undigraph; Pgr_turnRestrictedPath < pgrouting::UndirectedGraph > fn_TRSP; - undigraph.insert_edges(data_edges, total_edges); + undigraph.insert_edges(edges); paths = pgr_dijkstraTR(undigraph, ruleList, @@ -216,6 +224,9 @@ do_pgr_turnRestrictedPath( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch(...) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/ksp/withPoints_ksp.c b/src/ksp/withPoints_ksp.c index 554e02e3c94..316bf102b58 100644 --- a/src/ksp/withPoints_ksp.c +++ b/src/ksp/withPoints_ksp.c @@ -36,12 +36,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/path_rt.h" #include "c_common/time_msg.h" #include "c_common/e_report.h" - -#include "c_common/pgdata_getters.h" - #include "drivers/withPoints/get_new_queries.h" #include "drivers/yen/withPoints_ksp_driver.h" -#include "c_common/debug_macro.h" PGDLLEXPORT Datum _pgr_withpointsksp(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_withpointsksp); @@ -55,8 +51,8 @@ process( ArrayType *starts, ArrayType *ends, - int64_t* start_pid, - int64_t* end_pid, + int64_t* start_vid, + int64_t* end_vid, int p_k, char *driving_side, @@ -68,12 +64,13 @@ process( Path_rt **result_tuples, size_t *result_count) { if (p_k < 0) { + /* TODO add error message */ return; } size_t k = (size_t)p_k; - if (start_pid) { + if (start_vid) { driving_side[0] = (char) tolower(driving_side[0]); if (!((driving_side[0] == 'r') || (driving_side[0] == 'l'))) { @@ -83,11 +80,11 @@ process( driving_side[0] = (char) tolower(driving_side[0]); if (directed) { if (!((driving_side[0] == 'r') || (driving_side[0] == 'l'))) { - throw_error("Invalid value of 'driving side'", "Valid values are for directed graph are: 'r', 'l'"); + pgr_throw_error("Invalid value of 'driving side'", "Valid values are for directed graph are: 'r', 'l'"); return; } } else if (!(driving_side[0] == 'b')) { - throw_error("Invalid value of 'driving side'", "Valid values are for undirected graph is: 'b'"); + pgr_throw_error("Invalid value of 'driving side'", "Valid values are for undirected graph is: 'b'"); return; } } @@ -98,11 +95,6 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - Point_on_edge_t *points = NULL; - size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points, &err_msg); - throw_error(err_msg, points_sql); - char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; get_new_queries( @@ -110,62 +102,17 @@ process( &edges_of_points_query, &edges_no_points_query); - Edge_t *edges_of_points = NULL; - size_t total_edges_of_points = 0; - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); - throw_error(err_msg, edges_of_points_query); - - Edge_t *edges = NULL; - size_t total_edges = 0; - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_no_points_query); - - int64_t* start_pidsArr = NULL; - size_t size_start_pidsArr = 0; - int64_t* end_pidsArr = NULL; - size_t size_end_pidsArr = 0; - II_t_rt *combinationsArr = NULL; - size_t total_combinations = 0; - if (start_pid && end_pid) { - start_pidsArr = start_pid; size_start_pidsArr = 1; - end_pidsArr = end_pid; size_end_pidsArr = 1; - } else if (starts && ends) { - start_pidsArr = pgr_get_bigIntArray(&size_start_pidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start pids"); - end_pidsArr = pgr_get_bigIntArray(&size_end_pidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end pids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinationsArr, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - } - - pfree(edges_of_points_query); - pfree(edges_no_points_query); - - if ((total_edges + total_edges_of_points) == 0) { - if (end_pidsArr) pfree(end_pidsArr); - if (start_pidsArr) pfree(start_pidsArr); - if (combinationsArr) pfree(combinationsArr); - pgr_SPI_finish(); - return; - } - - if (total_combinations == 0 && (size_start_pidsArr== 0 || size_end_pidsArr == 0)) { - if (edges) pfree(edges); - pgr_SPI_finish(); - return; - } clock_t start_t = clock(); pgr_do_withPointsKsp( - edges, total_edges, - points, total_points, - edges_of_points, total_edges_of_points, - combinationsArr, total_combinations, - start_pidsArr, size_start_pidsArr, - end_pidsArr, size_end_pidsArr, + edges_no_points_query, + points_sql, + edges_of_points_query, + combinations_sql, + starts, ends, + start_vid, end_vid, k, directed, @@ -187,19 +134,7 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (start_pid && end_pid) { - start_pidsArr = NULL; - end_pidsArr = NULL; - } - if (start_pidsArr) pfree(start_pidsArr); - if (end_pidsArr) pfree(end_pidsArr); - if (combinationsArr) pfree(combinationsArr); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } @@ -312,10 +247,11 @@ PGDLLEXPORT Datum _pgr_withpointsksp(PG_FUNCTION_ARGS) { path_id = result_tuples[funcctx->call_cntr - 1].start_id; } } + int64_t seq = funcctx->call_cntr == 0? 1 : result_tuples[funcctx->call_cntr - 1].end_id; values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); values[1] = Int32GetDatum((int32_t)path_id); - values[2] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq); + values[2] = Int32GetDatum((int32_t)seq); if (PG_NARGS() != 9) { values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id); values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id); @@ -326,6 +262,7 @@ PGDLLEXPORT Datum _pgr_withpointsksp(PG_FUNCTION_ARGS) { values[n - 1] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); result_tuples[funcctx->call_cntr].start_id = path_id; + result_tuples[funcctx->call_cntr].end_id = result_tuples[funcctx->call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/ksp/withPoints_ksp_driver.cpp b/src/ksp/withPoints_ksp_driver.cpp index d1b5ac7f614..dae3a9e8562 100644 --- a/src/ksp/withPoints_ksp_driver.cpp +++ b/src/ksp/withPoints_ksp_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: withPoints_driver.cpp +File: withPoints_ksp_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -14,8 +14,6 @@ Mail: this.abhinav at gmail.com ------ - - 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 @@ -38,26 +36,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "c_types/ii_t_rt.h" -#include "cpp_common/combinations.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" - -#include "yen/pgr_ksp.hpp" -#include "withPoints/pgr_withPoints.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "withPoints/withPoints.hpp" -using pgrouting::yen::Pgr_ksp; +#include "yen/ksp.hpp" -int +void pgr_do_withPointsKsp( - 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, + char *edges_sql, + char *points_sql, + char *edges_of_points_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, - II_t_rt *combinationsArr, size_t total_combinations, - int64_t *start_pidsArr, size_t size_start_pidsArr, - int64_t *end_pidsArr, size_t size_end_pidsArr, + int64_t *start_vid, + int64_t *end_vid, size_t k, bool directed, @@ -73,27 +72,57 @@ pgr_do_withPointsKsp( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::yen::Pgr_ksp; + using pgrouting::utilities::get_combinations; + using pgrouting::pgget::get_points; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_combinations != 0 || (size_start_pidsArr != 0 && size_end_pidsArr != 0)); - 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), + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (start_vid && end_vid) { + combinations[*start_vid].insert(*end_vid); + } + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + log << "Combinations size " << combinations.size(); + + hint = points_sql; + auto points = get_points(std::string(points_sql)); + + hint = edges_of_points_sql; + auto edges_of_points = get_edges(std::string(edges_of_points_sql), true, false); + + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, false); + + if (edges.size() + edges_of_points.size() == 0) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + pgrouting::Pg_points_graph pg_graph(points, edges_of_points, true, driving_side, directed); @@ -103,31 +132,19 @@ pgr_do_withPointsKsp( err << pg_graph.get_error(); *log_msg = pgr_msg(log.str().c_str()); *err_msg = pgr_msg(err.str().c_str()); - return -1; + return; } - - graphType gType = directed? DIRECTED: UNDIRECTED; - - std::deque< Path > paths; - - auto combinations = total_combinations? - pgrouting::utilities::get_combinations(combinationsArr, total_combinations) - : pgrouting::utilities::get_combinations(start_pidsArr, size_start_pidsArr, end_pidsArr, size_end_pidsArr); - - auto vertices(pgrouting::extract_vertices(edges, total_edges)); - vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges()); - - + std::deque paths; if (directed) { - pgrouting::DirectedGraph digraph(vertices, gType); - digraph.insert_edges(edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); digraph.insert_edges(pg_graph.new_edges()); paths = pgrouting::algorithms::Yen(digraph, combinations, k, heap_paths); } else { - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); undigraph.insert_edges(pg_graph.new_edges()); paths = pgrouting::algorithms::Yen(undigraph, combinations, k, heap_paths); @@ -143,7 +160,11 @@ pgr_do_withPointsKsp( auto count(count_tuples(paths)); if (count == 0) { - return 0; + (*return_tuples) = NULL; + (*return_count) = 0; + notice << "No paths found"; + *log_msg = pgr_msg(notice.str().c_str()); + return; } @@ -157,7 +178,10 @@ pgr_do_withPointsKsp( } if (count != sequence) { - return 2; + (*return_count) = 0; + notice << "Something went wrong"; + *log_msg = pgr_msg(notice.str().c_str()); + return; } (*return_count) = sequence; @@ -167,13 +191,15 @@ pgr_do_withPointsKsp( *notice_msg = notice.str().empty()? *notice_msg : pgr_msg(notice.str().c_str()); - return 0; } 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 (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; @@ -187,5 +213,4 @@ pgr_do_withPointsKsp( *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); } - return 1000; } diff --git a/src/lineGraph/lineGraph.c b/src/lineGraph/lineGraph.c index cbaafb7417e..cac946a544e 100644 --- a/src/lineGraph/lineGraph.c +++ b/src/lineGraph/lineGraph.c @@ -27,55 +27,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -/** @file lineGraph.c - * @brief Connecting code with postgres. - * - * This file is fully documented for understanding - * how the postgres connectinon works - * - * TODO Remove unnecessary comments before submiting the function. - * some comments are in form of PGR_DBG message - */ - -/** - * postgres_connection.h - * - * - should always be first in the C code - */ #include #include "c_common/postgres_connection.h" -#include "c_types/edge_t.h" +#include "c_types/edge_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" -#include "drivers/lineGraph/lineGraph_driver.h" // the link to the C++ code of the function +#include "drivers/lineGraph/lineGraph_driver.h" PGDLLEXPORT Datum _pgr_linegraph(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_linegraph); -/******************************************************************************/ -/* MODIFY AS NEEDED */ static void process( char* edges_sql, bool directed, - Edge_t **result_tuples, + Edge_rt **result_tuples, size_t *result_count) { - /* - * https://www.postgresql.org/docs/current/static/spi-spi-connect.html - */ - PGR_DBG("\nSQL QUERY: %s\n", edges_sql); - if (directed) { - PGR_DBG("\nDirectedGraph\n"); - } else { - PGR_DBG("\nUndirectedGraph\n"); - } pgr_SPI_connect(); char* log_msg = NULL; char* notice_msg = NULL; @@ -84,25 +57,10 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - PGR_DBG("No edges found"); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_lineGraph( - edges, - total_edges, + pgr_do_lineGraph( + edges_sql, + directed, result_tuples, result_count, @@ -111,34 +69,21 @@ process( &err_msg); time_msg(" processing pgr_lineGraph", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); if (err_msg) { if (*result_tuples) pfree(*result_tuples); } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ PGDLLEXPORT Datum _pgr_linegraph(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ - /* MODIFY AS NEEDED */ - /* */ - Edge_t *result_tuples = NULL; + Edge_rt *result_tuples = NULL; size_t result_count = 0; - /* */ - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; @@ -146,25 +91,12 @@ PGDLLEXPORT Datum _pgr_linegraph(PG_FUNCTION_ARGS) { oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - /* MODIFY AS NEEDED */ - /* - TEXT, - directed BOOLEAN DEFAULT true, - **********************************************************************/ - - - PGR_DBG("Calling process"); process( text_to_cstring(PG_GETARG_TEXT_P(0)), PG_GETARG_BOOL(1), &result_tuples, &result_count); - - /* */ - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) @@ -181,7 +113,7 @@ PGDLLEXPORT Datum _pgr_linegraph(PG_FUNCTION_ARGS) { funcctx = SRF_PERCALL_SETUP(); tuple_desc = funcctx->tuple_desc; - result_tuples = (Edge_t*) funcctx->user_fctx; + result_tuples = (Edge_rt*) funcctx->user_fctx; if (funcctx->call_cntr < funcctx->max_calls) { HeapTuple tuple; @@ -198,25 +130,16 @@ PGDLLEXPORT Datum _pgr_linegraph(PG_FUNCTION_ARGS) { nulls[i] = false; } - // postgres starts counting from 1 values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].source); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].target); values[3] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); - values[4] = Float8GetDatum(result_tuples[ - funcctx->call_cntr].reverse_cost); + values[4] = Float8GetDatum(result_tuples[funcctx->call_cntr].reverse_cost); tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - /* MODIFY AS NEEDED */ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/lineGraph/lineGraphFull.c b/src/lineGraph/lineGraphFull.c index cb8970c93f9..1d273d03448 100644 --- a/src/lineGraph/lineGraphFull.c +++ b/src/lineGraph/lineGraphFull.c @@ -34,7 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/lineGraph/lineGraphFull_driver.h" PGDLLEXPORT Datum _pgr_linegraphfull(PG_FUNCTION_ARGS); @@ -46,8 +45,6 @@ process( char* edges_sql, Line_graph_full_rt **result_tuples, size_t *result_count) { - PGR_DBG("\nSQL QUERY: %s\n", edges_sql); - PGR_DBG("\nDirectedGraph\n"); pgr_SPI_connect(); char* log_msg = NULL; char* notice_msg = NULL; @@ -56,49 +53,25 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - PGR_DBG("No edges found"); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_lineGraphFull( - edges, - total_edges, + pgr_do_lineGraphFull( + edges_sql, + result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg(" processing pgr_lineGraphFull", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); if (err_msg) { if (*result_tuples) pfree(*result_tuples); } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ PGDLLEXPORT Datum _pgr_linegraphfull(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; diff --git a/src/lineGraph/lineGraphFull_driver.cpp b/src/lineGraph/lineGraphFull_driver.cpp index c4847411692..ac19b177dc4 100644 --- a/src/lineGraph/lineGraphFull_driver.cpp +++ b/src/lineGraph/lineGraphFull_driver.cpp @@ -32,15 +32,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include - -#include "dijkstra/dijkstra.hpp" +#include #include "c_types/line_graph_full_rt.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -#include "lineGraph/pgr_lineGraphFull.hpp" -#include "cpp_common/linear_directed_graph.h" +#include "lineGraph/lineGraphFull.hpp" +#include "cpp_common/linear_directed_graph.hpp" + +#include "dijkstra/dijkstra.hpp" namespace { @@ -65,9 +67,9 @@ void get_turn_penalty_postgres_result( } // namespace void -do_pgr_lineGraphFull( - Edge_t *data_edges, - size_t total_edges, +pgr_do_lineGraphFull( + char *edges_sql, + Line_graph_full_rt **return_tuples, size_t *return_count, char ** log_msg, @@ -79,26 +81,31 @@ do_pgr_lineGraphFull( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - graphType gType = DIRECTED; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges_neg(data_edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges_neg(edges); -#if 0 - log << digraph << "\n"; -#endif pgrouting::graph::Pgr_lineGraphFull< pgrouting::LinearDirectedGraph, pgrouting::Line_vertex, - pgrouting::Basic_edge > line(digraph); + pgrouting::Basic_edge, true> line(digraph); std::vector< Line_graph_full_rt > line_graph_edges; line_graph_edges = line.get_postgres_results_directed(); @@ -137,6 +144,9 @@ do_pgr_lineGraphFull( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/lineGraph/lineGraph_driver.cpp b/src/lineGraph/lineGraph_driver.cpp index ed5a5b94efb..2f837e5282f 100644 --- a/src/lineGraph/lineGraph_driver.cpp +++ b/src/lineGraph/lineGraph_driver.cpp @@ -33,39 +33,35 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "dijkstra/dijkstra.hpp" - -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" - -#include "lineGraph/pgr_lineGraph.hpp" -#include "cpp_common/linear_directed_graph.h" +#include "bgraph/line_graph.hpp" +#include "bgraph/graph_to_edges.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/base_graph.hpp" +#include "c_types/edge_rt.h" namespace { -void get_postgres_result( - std::vector< Edge_t > edge_result, - Edge_t **return_tuples, - size_t &sequence) { - using pgrouting::pgr_alloc; - (*return_tuples) = pgr_alloc(edge_result.size(), (*return_tuples)); - - for (const auto &edge : edge_result) { - (*return_tuples)[sequence] = {edge.id, edge.source, edge.target, - edge.cost, edge.reverse_cost}; - sequence++; - } +template +std::vector line_graph(const G& original, bool add_self_loop) { + auto lg_result = pgrouting::b_g::line_graph(original.graph); + + return pgrouting::b_g::graph_to_existing_edges(lg_result, add_self_loop); } + } // namespace void -do_pgr_lineGraph( - Edge_t *data_edges, - size_t total_edges, +pgr_do_lineGraph( + char *edges_sql, bool directed, - Edge_t **return_tuples, + + Edge_rt **return_tuples, size_t *return_count, + char ** log_msg, char ** notice_msg, char ** err_msg) { @@ -75,56 +71,68 @@ do_pgr_lineGraph( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - graphType gType = directed? DIRECTED: UNDIRECTED; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges_neg(data_edges, total_edges); + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + std::vector line_graph_edges; + if (directed) { + pgrouting::DirectedGraph ograph; + ograph.insert_edges(edges); + line_graph_edges = line_graph(ograph, directed); + } else { + pgrouting::UndirectedGraph ograph; + ograph.insert_edges(edges); + line_graph_edges = line_graph(ograph, directed); + } - log << digraph << "\n"; - pgrouting::graph::Pgr_lineGraph< - pgrouting::LinearDirectedGraph, - pgrouting::Line_vertex, - pgrouting::Basic_edge> line(digraph); - std::vector< Edge_t > line_graph_edges; - line_graph_edges = line.get_postgres_results_directed(); auto count = line_graph_edges.size(); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "Only vertices graph"; - } else { - size_t sequence = 0; + *log_msg = pgr_msg(log.str().c_str()); + return; + } + + size_t sequence = 0; + using pgrouting::pgr_alloc; + (*return_tuples) = pgr_alloc(line_graph_edges.size(), (*return_tuples)); - get_postgres_result( - line_graph_edges, - return_tuples, - sequence); - (*return_count) = sequence; + for (const auto &e : line_graph_edges) { + auto rev_c = directed? e.reverse_cost : -1; + (*return_tuples)[sequence] = {e.id, e.source, e.target, e.cost, rev_c}; + sequence++; } + (*return_count) = sequence; pgassert(*err_msg == NULL); - *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()); + *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 (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/max_flow/CMakeLists.txt b/src/max_flow/CMakeLists.txt index 971691528e1..26a5a99bd1b 100644 --- a/src/max_flow/CMakeLists.txt +++ b/src/max_flow/CMakeLists.txt @@ -9,7 +9,7 @@ ADD_LIBRARY(max_flow OBJECT edge_disjoint_paths_driver.cpp minCostMaxFlow_driver.cpp - pgr_maxflow.cpp - pgr_flowgraph.cpp - pgr_minCostMaxFlow.cpp + maxflow.cpp + flowgraph.cpp + minCostMaxFlow.cpp ) diff --git a/src/max_flow/edge_disjoint_paths.c b/src/max_flow/edge_disjoint_paths.c index afee7829fea..33051f2c4d7 100644 --- a/src/max_flow/edge_disjoint_paths.c +++ b/src/max_flow/edge_disjoint_paths.c @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: edge_disjoint_paths_many_to_many.c +File: edge_disjoint_paths.c Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -35,7 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/max_flow/edge_disjoint_paths_driver.h" PGDLLEXPORT Datum @@ -57,54 +56,11 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - int64_t *source_vertices = NULL; - size_t size_source_verticesArr = 0; - - int64_t *sink_vertices = NULL; - size_t size_sink_verticesArr = 0; - - - Edge_t *edges = NULL; - size_t total_edges = 0; - - II_t_rt *combinations = NULL; - size_t total_combinations = 0; - - if (starts && ends) { - source_vertices = pgr_get_bigIntArray(&size_source_verticesArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - sink_vertices = pgr_get_bigIntArray(&size_sink_verticesArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end_vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - if (total_combinations == 0) { - if (combinations) - pfree(combinations); - pgr_SPI_finish(); - return; - } - } - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - if (source_vertices) pfree(source_vertices); - if (sink_vertices) pfree(sink_vertices); - pgr_SPI_finish(); - return; - } - - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - - do_pgr_edge_disjoint_paths( - edges, total_edges, - combinations, total_combinations, - source_vertices, size_source_verticesArr, - sink_vertices, size_sink_verticesArr, + pgr_do_edge_disjoint_paths( + edges_sql, + combinations_sql, + starts, ends, directed, result_tuples, result_count, @@ -112,24 +68,16 @@ process( &log_msg, ¬ice_msg, &err_msg); - time_msg("pgr_edgeDisjointPaths(many to many)", start_t, clock()); - if (edges) pfree(edges); - if (source_vertices) pfree(source_vertices); - if (sink_vertices) pfree(sink_vertices); - if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_tuples) = NULL; (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); pgr_SPI_finish(); } diff --git a/src/max_flow/edge_disjoint_paths_driver.cpp b/src/max_flow/edge_disjoint_paths_driver.cpp index 5e2b438672c..35fadb4069f 100644 --- a/src/max_flow/edge_disjoint_paths_driver.cpp +++ b/src/max_flow/edge_disjoint_paths_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: edge_disjoint_paths_many_to_many_driver.cpp +File: edge_disjoint_paths_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -32,13 +32,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "max_flow/pgr_maxflow.hpp" +#include "max_flow/maxflow.hpp" -#include "cpp_common/combinations.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/combinations.hpp" #include "cpp_common/identifiers.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" +#include "cpp_common/alloc.hpp" #include "c_types/ii_t_rt.h" @@ -69,15 +71,11 @@ single_execution( } // namespace void -do_pgr_edge_disjoint_paths( - Edge_t *data_edges, - size_t total_edges, - II_t_rt *combinations, - size_t total_combinations, - int64_t *sources, - size_t size_source_verticesArr, - int64_t *sinks, - size_t size_sink_verticesArr, +pgr_do_edge_disjoint_paths( + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, bool directed, Path_rt **return_tuples, size_t *return_count, @@ -87,30 +85,42 @@ do_pgr_edge_disjoint_paths( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char* hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(data_edges); - pgassert(total_edges != 0); - pgassert((sources && sinks) || combinations); - pgassert((size_source_verticesArr && size_sink_verticesArr) || total_combinations); - auto combinations_data = total_combinations? - pgrouting::utilities::get_combinations(combinations, total_combinations) - : pgrouting::utilities::get_combinations(sources, size_source_verticesArr, sinks, size_sink_verticesArr); + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } - std::vector edges( - data_edges, data_edges + total_edges); + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + hint = nullptr; + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = pgr_msg(edges_sql); + return; + } std::vector paths; - for (const auto &c : combinations_data) { + for (const auto &c : combinations) { for (const auto &t : c.second) { /* * a source can not be a sink @@ -159,7 +169,7 @@ do_pgr_edge_disjoint_paths( */ auto prev = paths[0]; for (auto &r : paths) { - if (r.seq == 1) { + if (&r == &paths[0] || prev.edge < 0) { r.agg_cost = 0; } else { r.agg_cost = prev.agg_cost + prev.cost; @@ -192,6 +202,9 @@ do_pgr_edge_disjoint_paths( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch(...) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/max_flow/pgr_flowgraph.cpp b/src/max_flow/flowgraph.cpp similarity index 94% rename from src/max_flow/pgr_flowgraph.cpp rename to src/max_flow/flowgraph.cpp index d2111f6c585..f41b0420335 100644 --- a/src/max_flow/pgr_flowgraph.cpp +++ b/src/max_flow/flowgraph.cpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: flowgraph.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,4 +25,4 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "max_flow/pgr_flowgraph.hpp" +#include "max_flow/flowgraph.hpp" diff --git a/src/max_flow/max_flow.c b/src/max_flow/max_flow.c index d582616682b..a59188ab322 100644 --- a/src/max_flow/max_flow.c +++ b/src/max_flow/max_flow.c @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: max_flow_many_to_many.c +File: max_flow.c Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -34,7 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/max_flow/max_flow_driver.h" #include "c_types/flow_t.h" @@ -62,56 +61,12 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - int64_t *source_vertices = NULL; - size_t size_source_verticesArr = 0; - - int64_t *sink_vertices = NULL; - size_t size_sink_verticesArr = 0; - - Edge_t *edges = NULL; - size_t total_edges = 0; - - II_t_rt *combinations = NULL; - size_t total_combinations = 0; - - if (starts && ends) { - source_vertices = pgr_get_bigIntArray(&size_source_verticesArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - sink_vertices = pgr_get_bigIntArray(&size_sink_verticesArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - if (total_combinations == 0) { - if (combinations) - pfree(combinations); - pgr_SPI_finish(); - return; - } - } - - /* NOTE: - * For flow, cost and reverse_cost are really capacity and reverse_capacity - */ - pgr_get_flow_edges(edges_sql, &edges, &total_edges, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - if (source_vertices) pfree(source_vertices); - if (sink_vertices) pfree(sink_vertices); - pgr_SPI_finish(); - return; - } - - - PGR_DBG("Starting timer"); clock_t start_t = clock(); + pgr_do_max_flow( + edges_sql, + combinations_sql, + starts, ends, - do_pgr_max_flow( - edges, total_edges, - combinations, total_combinations, - source_vertices, size_source_verticesArr, - sink_vertices, size_sink_verticesArr, algorithm, only_flow, @@ -122,35 +77,22 @@ process( &err_msg); if (only_flow) { - time_msg("pgr_maxFlow(many to many)", - start_t, clock()); + time_msg("pgr_maxFlow(many to many)", start_t, clock()); } else if (algorithm == 1) { - time_msg("pgr_maxFlowPushRelabel(many to many)", - start_t, clock()); + time_msg("pgr_maxFlowPushRelabel(many to many)", start_t, clock()); } else if (algorithm == 3) { - time_msg("pgr_maxFlowEdmondsKarp(many to many)", - start_t, clock()); + time_msg("pgr_maxFlowEdmondsKarp(many to many)", start_t, clock()); } else { - time_msg("pgr_maxFlowBoykovKolmogorov(many to many)", - start_t, clock()); + time_msg("pgr_maxFlowBoykovKolmogorov(many to many)", start_t, clock()); } - - if (edges) pfree(edges); - if (source_vertices) pfree(source_vertices); - if (sink_vertices) pfree(sink_vertices); - if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_tuples) = NULL; (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } diff --git a/src/max_flow/max_flow_driver.cpp b/src/max_flow/max_flow_driver.cpp index bc82a2aac30..7f7fd67cd68 100644 --- a/src/max_flow/max_flow_driver.cpp +++ b/src/max_flow/max_flow_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: max_flow_many_to_many_driver.cpp +File: max_flow_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -32,20 +32,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "max_flow/pgr_maxflow.hpp" +#include "max_flow/maxflow.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/alloc.hpp" #include "c_types/ii_t_rt.h" void -do_pgr_max_flow( - Edge_t *data_edges, size_t total_edges, - II_t_rt *combinations, size_t total_combinations, - int64_t *source_vertices, size_t size_source_verticesArr, - int64_t *sink_vertices, size_t size_sink_verticesArr, +pgr_do_max_flow( + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, + int algorithm, bool only_flow, @@ -56,10 +60,12 @@ do_pgr_max_flow( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char* hint = nullptr; try { pgassert(!(*log_msg)); @@ -67,39 +73,41 @@ do_pgr_max_flow( pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(data_edges); - pgassert(total_edges != 0); - pgassert((source_vertices && sink_vertices) || combinations); - pgassert((size_source_verticesArr && size_sink_verticesArr) || total_combinations); - - std::vector edges(data_edges, data_edges + total_edges); - std::set sources( - source_vertices, source_vertices + size_source_verticesArr); - std::set targets( - sink_vertices, sink_vertices + size_sink_verticesArr); - std::vector< II_t_rt > combinations_vector( - combinations, combinations + total_combinations); - - if (!combinations_vector.empty()) { - pgassert(sources.empty()); - pgassert(targets.empty()); - - for (const II_t_rt &comb : combinations_vector) { - sources.insert(comb.d1.source); - targets.insert(comb.d2.target); - } + + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + std::set sources; + std::set targets; + for (const auto &c : combinations) { + sources.insert(c.first); + targets.insert(c.second.begin(), c.second.end()); } std::set vertices(sources); vertices.insert(targets.begin(), targets.end()); - if (vertices.size() - != (sources.size() + targets.size())) { + if (vertices.size() != (sources.size() + targets.size())) { *err_msg = pgr_msg("A source found as sink"); - // TODO(vicky) return as hint the sources that are also sinks return; } + hint = edges_sql; + auto edges = pgrouting::pgget::get_flow_edges(std::string(edges_sql)); + hint = nullptr; + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = edges_sql; + return; + } pgrouting::graph::PgrFlowGraph digraph( @@ -125,12 +133,7 @@ do_pgr_max_flow( std::vector flow_edges; if (only_flow) { - Flow_t edge; - edge.edge = -1; - edge.source = -1; - edge.target = -1; - edge.flow = max_flow; - edge.residual_capacity = -1; + Flow_t edge = {-1, -1, -1, max_flow, -1, 0, 0}; flow_edges.push_back(edge); } else { flow_edges = digraph.get_flow_edges(); @@ -160,6 +163,9 @@ do_pgr_max_flow( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch(...) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; @@ -168,4 +174,3 @@ do_pgr_max_flow( *log_msg = pgr_msg(log.str().c_str()); } } - diff --git a/src/max_flow/pgr_maxflow.cpp b/src/max_flow/maxflow.cpp similarity index 99% rename from src/max_flow/pgr_maxflow.cpp rename to src/max_flow/maxflow.cpp index dad55491edb..e7dc626b94a 100644 --- a/src/max_flow/pgr_maxflow.cpp +++ b/src/max_flow/maxflow.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_maxflow.cpp +File: maxflow.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "max_flow/pgr_maxflow.hpp" +#include "max_flow/maxflow.hpp" #include #include diff --git a/src/max_flow/maximum_cardinality_matching.c b/src/max_flow/maximum_cardinality_matching.c index 22a6dc9821d..848194497e2 100644 --- a/src/max_flow/maximum_cardinality_matching.c +++ b/src/max_flow/maximum_cardinality_matching.c @@ -34,7 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/edge_bool_t_rt.h" @@ -44,8 +43,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. PGDLLEXPORT Datum _pgr_maxcardinalitymatch(PG_FUNCTION_ARGS); -/******************************************************************************/ -/* MODIFY AS NEEDED */ static void process( @@ -58,21 +55,9 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - Edge_bool_t* edges = NULL; - size_t total_edges = 0; - pgr_get_basic_edges(edges_sql, &edges, &total_edges, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - - do_pgr_maximum_cardinality_matching( - edges, total_edges, + pgr_do_maximum_cardinality_matching( + edges_sql, directed, result_tuples, result_count, @@ -80,23 +65,15 @@ process( &log_msg, ¬ice_msg, &err_msg); - time_msg("pgr_maximumCardinalityMatching()", start_t, clock()); - if (edges) pfree(edges); - if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_tuples) = NULL; (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } @@ -109,7 +86,6 @@ _pgr_maxcardinalitymatch(PG_FUNCTION_ARGS) { Only_int_rt* result_tuples = NULL; size_t result_count = 0; - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; @@ -117,16 +93,12 @@ _pgr_maxcardinalitymatch(PG_FUNCTION_ARGS) { oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - PGR_DBG("Calling process"); process( text_to_cstring(PG_GETARG_TEXT_P(0)), PG_GETARG_BOOL(1), &result_tuples, &result_count); - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) @@ -151,8 +123,6 @@ _pgr_maxcardinalitymatch(PG_FUNCTION_ARGS) { Datum *values; bool *nulls; - /**********************************************************************/ - values = palloc(4 * sizeof(Datum)); nulls = palloc(4 * sizeof(bool)); @@ -167,8 +137,6 @@ _pgr_maxcardinalitymatch(PG_FUNCTION_ARGS) { values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].source); values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].target); - /**********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); diff --git a/src/max_flow/maximum_cardinality_matching_driver.cpp b/src/max_flow/maximum_cardinality_matching_driver.cpp index cd9c6d6a36e..fc1587e7dd8 100644 --- a/src/max_flow/maximum_cardinality_matching_driver.cpp +++ b/src/max_flow/maximum_cardinality_matching_driver.cpp @@ -35,18 +35,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include +#include -#include "max_flow/pgr_maximumcardinalitymatching.hpp" +#include "c_types/edge_bool_t_rt.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "max_flow/maximumcardinalitymatching.hpp" -#include "c_types/edge_bool_t_rt.h" void -do_pgr_maximum_cardinality_matching( - Edge_bool_t *data_edges, - size_t total_tuples, +pgr_do_maximum_cardinality_matching( + char *edges_sql, /* TODO(v4) flag directed is to be removed */ bool, @@ -63,9 +64,20 @@ do_pgr_maximum_cardinality_matching( std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char* hint = nullptr; try { - pgrouting::flow::PgrCardinalityGraph G(data_edges, total_tuples); + hint = edges_sql; + auto edges = pgrouting::pgget::get_basic_edges(std::string(edges_sql)); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + pgrouting::flow::PgrCardinalityGraph G(edges); auto matched_vertices = G.get_matched_vertices(); (*return_tuples) = pgr_alloc(matched_vertices.size(), (*return_tuples)); @@ -86,6 +98,9 @@ do_pgr_maximum_cardinality_matching( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/max_flow/minCostMaxFlow.c b/src/max_flow/minCostMaxFlow.c index 1b2706540da..8ef46153c9f 100644 --- a/src/max_flow/minCostMaxFlow.c +++ b/src/max_flow/minCostMaxFlow.c @@ -28,29 +28,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -/** @file minCostMaxFlow.c - * @brief Connecting code with postgres. - * - * This file is fully documented for understanding - * how the postgres connectinon works - * - * TODO Remove unnecessary comments before submiting the function. - * some comments are in form of PGR_DBG message - */ - -/** - * postgres_connection.h - * - * - should always be first in the C code - */ #include #include "c_common/postgres_connection.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" - #include "drivers/max_flow/minCostMaxFlow_driver.h" #include "c_types/flow_t.h" @@ -59,8 +42,6 @@ PGDLLEXPORT Datum _pgr_maxflowmincost(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_maxflowmincost); -/******************************************************************************/ -/* MODIFY AS NEEDED */ static void process( @@ -71,65 +52,16 @@ process( bool only_cost, Flow_t **result_tuples, size_t *result_count) { - /* - * https://www.postgresql.org/docs/current/static/spi-spi-connect.html - */ pgr_SPI_connect(); char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - int64_t *sourceVertices = NULL; - size_t sizeSourceVerticesArr = 0; - - int64_t *sinkVertices = NULL; - size_t sizeSinkVerticesArr = 0; - - PGR_DBG("Load data"); - CostFlow_t *edges = NULL; - size_t total_edges = 0; - - II_t_rt *combinations = NULL; - size_t total_combinations = 0; - - if (starts && ends) { - sourceVertices = pgr_get_bigIntArray(&sizeSourceVerticesArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - sinkVertices = pgr_get_bigIntArray(&sizeSinkVerticesArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - if (total_combinations == 0) { - if (combinations) - pfree(combinations); - pgr_SPI_finish(); - return; - } - } - - pgr_get_costFlow_edges(edges_sql, &edges, &total_edges, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - if (sourceVertices) - pfree(sourceVertices); - if (sinkVertices) - pfree(sinkVertices); - PGR_DBG("No edges found"); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - - do_pgr_minCostMaxFlow( - edges, total_edges, - combinations, total_combinations, - sourceVertices, sizeSourceVerticesArr, - sinkVertices, sizeSinkVerticesArr, + pgr_do_minCostMaxFlow( + edges_sql, + combinations_sql, + starts, ends, only_cost, result_tuples, result_count, @@ -137,50 +69,29 @@ process( &log_msg, ¬ice_msg, &err_msg); - if (only_cost) { time_msg(" processing pgr_minCostMaxFlow_Cost", start_t, clock()); } else { time_msg(" processing pgr_minCostMaxFlow", start_t, clock()); } - PGR_DBG("Returning %ld tuples", *result_count); - - if (edges) - pfree(edges); - if (sourceVertices) - pfree(sourceVertices); - if (sinkVertices) - pfree(sinkVertices); - if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_tuples) = NULL; (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ PGDLLEXPORT Datum _pgr_maxflowmincost(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ - /* MODIFY AS NEEDED */ - /* */ Flow_t *result_tuples = NULL; size_t result_count = 0; - /* */ - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; @@ -188,17 +99,6 @@ PGDLLEXPORT Datum _pgr_maxflowmincost(PG_FUNCTION_ARGS) { oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - /* MODIFY AS NEEDED */ - /* - TEXT, - BIGINT, - BIGINT, - **********************************************************************/ - - - PGR_DBG("Calling process"); - if (PG_NARGS() == 4) { /* * many to many @@ -226,9 +126,6 @@ PGDLLEXPORT Datum _pgr_maxflowmincost(PG_FUNCTION_ARGS) { &result_count); } - /* */ - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) @@ -252,44 +149,27 @@ PGDLLEXPORT Datum _pgr_maxflowmincost(PG_FUNCTION_ARGS) { Datum result; Datum *values; bool* nulls; - - /**********************************************************************/ - /* MODIFY AS NEEDED */ - /* - ***********************************************************************/ - values = palloc(8 * sizeof(Datum)); nulls = palloc(8 * sizeof(bool)); - size_t i; for (i = 0; i < 8; ++i) { nulls[i] = false; } - // postgres starts counting from 1 values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].source); values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].target); values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].flow); - values[5] = Int64GetDatum( - result_tuples[funcctx->call_cntr].residual_capacity); + values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].residual_capacity); values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - /* MODIFY AS NEEDED */ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/max_flow/pgr_minCostMaxFlow.cpp b/src/max_flow/minCostMaxFlow.cpp similarity index 98% rename from src/max_flow/pgr_minCostMaxFlow.cpp rename to src/max_flow/minCostMaxFlow.cpp index 23d2e48e38a..8bf71c61b3c 100644 --- a/src/max_flow/pgr_minCostMaxFlow.cpp +++ b/src/max_flow/minCostMaxFlow.cpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: minCostMaxFlow.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "max_flow/pgr_minCostMaxFlow.hpp" +#include "max_flow/minCostMaxFlow.hpp" #include #include diff --git a/src/max_flow/minCostMaxFlow_driver.cpp b/src/max_flow/minCostMaxFlow_driver.cpp index 752405d91f2..512b39c2274 100644 --- a/src/max_flow/minCostMaxFlow_driver.cpp +++ b/src/max_flow/minCostMaxFlow_driver.cpp @@ -33,72 +33,84 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "max_flow/pgr_minCostMaxFlow.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/costFlow_t.hpp" -#include "c_types/costFlow_t.h" -#include "c_types/ii_t_rt.h" +#include "cpp_common/combinations.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" + +#include "max_flow/minCostMaxFlow.hpp" void -do_pgr_minCostMaxFlow( - CostFlow_t *data_edges, size_t total_edges, - II_t_rt *combinations, size_t total_combinations, - int64_t *sourceVertices, size_t sizeSourceVerticesArr, - int64_t *sinkVertices, size_t sizeSinkVerticesArr, +pgr_do_minCostMaxFlow( + char *edges_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, + bool only_cost, Flow_t **return_tuples, size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg) { + char **log_msg, + char **notice_msg, + char **err_msg) { using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(data_edges); - pgassert(total_edges != 0); - pgassert((sourceVertices && sinkVertices) || combinations); - pgassert((sizeSourceVerticesArr && sizeSinkVerticesArr) || total_combinations); - - std::vector edges(data_edges, data_edges + total_edges); - std::set sources( - sourceVertices, sourceVertices + sizeSourceVerticesArr); - std::set targets( - sinkVertices, sinkVertices + sizeSinkVerticesArr); - std::vector< II_t_rt > combinations_vector( - combinations, combinations + total_combinations); - - if (!combinations_vector.empty()) { - pgassert(sources.empty()); - pgassert(targets.empty()); - - for (const II_t_rt &comb : combinations_vector) { - sources.insert(comb.d1.source); - targets.insert(comb.d2.target); - } + + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + std::set sources; + std::set targets; + for (const auto &c : combinations) { + sources.insert(c.first); + targets.insert(c.second.begin(), c.second.end()); } std::set vertices(sources); vertices.insert(targets.begin(), targets.end()); - if (vertices.size() - != (sources.size() + targets.size())) { + if (vertices.size() != (sources.size() + targets.size())) { *err_msg = pgr_msg("A source found as sink"); return; } + hint = edges_sql; + auto edges = pgrouting::pgget::get_costFlow_edges(std::string(edges_sql)); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + pgrouting::graph::PgrCostFlowGraph digraph( edges, sources, targets); @@ -140,6 +152,9 @@ do_pgr_minCostMaxFlow( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; @@ -154,4 +169,3 @@ do_pgr_minCostMaxFlow( *log_msg = pgr_msg(log.str().c_str()); } } - diff --git a/src/metrics/CMakeLists.txt b/src/metrics/CMakeLists.txt new file mode 100644 index 00000000000..c88a1dfd8eb --- /dev/null +++ b/src/metrics/CMakeLists.txt @@ -0,0 +1,4 @@ +ADD_LIBRARY(metrics OBJECT + betweennessCentrality.c + betweennessCentrality_driver.cpp + ) diff --git a/src/metrics/betweennessCentrality.c b/src/metrics/betweennessCentrality.c new file mode 100644 index 00000000000..bbebd4f3cd7 --- /dev/null +++ b/src/metrics/betweennessCentrality.c @@ -0,0 +1,136 @@ +/*PGR-GNU***************************************************************** +File: betweennessCentrality.c + +Generated with Template by: +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2024 Arun Thakur +Mail: bedupako12mas at gmail.com + +------ + +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 "c_types/iid_t_rt.h" +#include "c_common/debug_macro.h" +#include "c_common/e_report.h" +#include "c_common/time_msg.h" + +#include "drivers/metrics/betweennessCentrality_driver.h" + +PGDLLEXPORT Datum _pgr_betweennesscentrality(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_betweennesscentrality); + +static +void +process( + char* edges_sql, + bool directed, + IID_t_rt **result_tuples, + size_t *result_count) { + pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; + char* err_msg = NULL; + + clock_t start_t = clock(); + pgr_do_betweennessCentrality( + edges_sql, + directed, + result_tuples, + result_count, + &log_msg, + &err_msg); + time_msg(" processing Centrality", start_t, clock()); + + if (err_msg && (*result_tuples)) { + pfree(*result_tuples); + (*result_tuples) = NULL; + (*result_count) = 0; + } + + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); + + pgr_SPI_finish(); +} + + +PGDLLEXPORT Datum +_pgr_betweennesscentrality(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + + + IID_t_rt *result_tuples = NULL; + 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)), + PG_GETARG_BOOL(1), + &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 = (IID_t_rt*) funcctx->user_fctx; + + if (funcctx->call_cntr < funcctx->max_calls) { + HeapTuple tuple; + Datum result; + Datum *values; + bool* nulls; + + values = palloc(2 * sizeof(Datum)); + nulls = palloc(2 * sizeof(bool)); + + // postgres starts counting from 1 + values[0] = Int64GetDatum(result_tuples[funcctx->call_cntr].from_vid); + nulls[0] = false; + values[1] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); + nulls[1] = false; + + 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/metrics/betweennessCentrality_driver.cpp b/src/metrics/betweennessCentrality_driver.cpp new file mode 100644 index 00000000000..5b71b132347 --- /dev/null +++ b/src/metrics/betweennessCentrality_driver.cpp @@ -0,0 +1,118 @@ +/*PGR-GNU***************************************************************** +File: betweennessCentrality_driver.cpp + +Generated with Template by: +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2024 Arun Thakur +Mail: bedupako12mas at gmail.com + +------ + +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/metrics/betweennessCentrality_driver.h" + +#include +#include +#include +#include +#include "metrics/betweennessCentrality.hpp" +#include "cpp_common/pgdata_getters.hpp" + +#include "cpp_common/assert.hpp" + + +void +pgr_do_betweennessCentrality( + char *edges_sql, + bool directed, + + IID_t_rt **return_tuples, + size_t *return_count, + char ** log_msg, + char ** err_msg) { + using pgrouting::pgr_msg; + using pgrouting::pgr_free; + + std::ostringstream log; + std::ostringstream err; + char *hint = nullptr; + + try { + pgassert(!(*log_msg)); + pgassert(!(*err_msg)); + pgassert(!(*return_tuples)); + pgassert(*return_count == 0); + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, true); + + if (edges.empty()) { + throw std::string("No edges found"); + } + hint = nullptr; + + if (directed) { + log << "Processing Directed graph\n"; + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); + pgr_betweennesscentrality(digraph, *return_count, return_tuples); + } else { + log << "Processing Undirected graph\n"; + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); + pgr_betweennesscentrality(undigraph, *return_count, return_tuples); + } + + + if (*return_count == 0) { + err << "No result generated, report this error\n"; + *err_msg = pgr_msg(err.str().c_str()); + *return_tuples = NULL; + *return_count = 0; + return; + } + + *log_msg = log.str().empty()? + *log_msg : + pgr_msg(log.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 (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : 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()); + } +} diff --git a/src/mincut/stoerWagner.c b/src/mincut/stoerWagner.c index c074b9ba301..9601789821f 100644 --- a/src/mincut/stoerWagner.c +++ b/src/mincut/stoerWagner.c @@ -33,7 +33,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/stoerWagner_t.h" #include "drivers/mincut/stoerWagner_driver.h" @@ -50,9 +49,6 @@ process( char* edges_sql, StoerWagner_t **result_tuples, size_t *result_count) { - /* - * https://www.postgresql.org/docs/current/static/spi-spi-connect.html - */ pgr_SPI_connect(); char* log_msg = NULL; char* notice_msg = NULL; @@ -61,60 +57,31 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - PGR_DBG("No edges found"); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_stoerWagner( - edges, - total_edges, + pgr_do_stoerWagner( + edges_sql, + result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg(" processing pgr_stoerWagner", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); if (err_msg) { if (*result_tuples) pfree(*result_tuples); } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ PGDLLEXPORT Datum _pgr_stoerwagner(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ - /* MODIFY AS NEEDED */ - /* */ StoerWagner_t *result_tuples = NULL; size_t result_count = 0; - /* */ - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; @@ -128,13 +95,7 @@ PGDLLEXPORT Datum _pgr_stoerwagner(PG_FUNCTION_ARGS) { &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) { @@ -167,24 +128,15 @@ PGDLLEXPORT Datum _pgr_stoerwagner(PG_FUNCTION_ARGS) { nulls[i] = false; } - // postgres starts counting from 1 values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); values[2] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[3] = Float8GetDatum(result_tuples[funcctx->call_cntr].mincut); - /**********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - /* MODIFY AS NEEDED */ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/mincut/stoerWagner_driver.cpp b/src/mincut/stoerWagner_driver.cpp index b60dccfeded..14200fddf8a 100644 --- a/src/mincut/stoerWagner_driver.cpp +++ b/src/mincut/stoerWagner_driver.cpp @@ -31,11 +31,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "mincut/pgr_stoerWagner.hpp" +#include "mincut/stoerWagner.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "c_types/stoerWagner_t.h" namespace { @@ -50,9 +52,9 @@ pgr_stoerWagner( } // namespace void -do_pgr_stoerWagner( - Edge_t *data_edges, - size_t total_edges, +pgr_do_stoerWagner( + char *edges_sql, + StoerWagner_t **return_tuples, size_t *return_count, char ** log_msg, @@ -65,22 +67,28 @@ do_pgr_stoerWagner( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); - graphType gType = UNDIRECTED; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; std::vector results; - log << "Working with Undirected Graph\n"; - - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); results = pgr_stoerWagner( undigraph); @@ -113,6 +121,9 @@ do_pgr_stoerWagner( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/ordering/cuthillMckeeOrdering.c b/src/ordering/cuthillMckeeOrdering.c index 51d97894fd5..6ac06bcdaa9 100644 --- a/src/ordering/cuthillMckeeOrdering.c +++ b/src/ordering/cuthillMckeeOrdering.c @@ -25,11 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -/** @file cuthillMckeeOrdering.c - * @brief Connecting code with postgres. - * - */ - #include #include "c_common/postgres_connection.h" @@ -37,7 +32,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/ii_t_rt.h" @@ -46,26 +40,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. PGDLLEXPORT Datum _pgr_cuthillmckeeordering(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_cuthillmckeeordering); -/** @brief Static function, loads the data from postgres to C types for further processing. - * - * It first connects the C function to the SPI manager. Then converts - * the postgres array to C array and loads the edges belonging to the graph - * in C types. Then it calls the function `do_cuthillMckeeOrdering` defined - * in the `cuthillMckeeOrdering_driver.h` file for further processing. - * Finally, it frees the memory and disconnects the C function to the SPI manager. - * - * @param edges_sql the edges of the SQL query - * @param result_tuples the rows in the result - * @param result_count the count of rows in the result - */ - static void process( - char* edges_sql, + char* edges_sql, - II_t_rt **result_tuples, - size_t *result_count) { + II_t_rt **result_tuples, + size_t *result_count) { pgr_SPI_connect(); char* log_msg = NULL; char* notice_msg = NULL; @@ -74,32 +55,15 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - if (total_edges == 0) { - ereport(WARNING, - (errmsg("Insufficient data edges SQL."), - errhint("%s", edges_sql))); - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting timer"); clock_t start_t = clock(); + pgr_do_cuthillMckeeOrdering( + edges_sql, - do_cuthillMckeeOrdering( - edges, total_edges, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg("processing cuthillmckeeordering", start_t, clock()); if (err_msg && (*result_tuples)) { @@ -108,20 +72,11 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/** @brief Helps in converting postgres variables to C variables, and returns the result. - * - */ - PGDLLEXPORT Datum _pgr_cuthillmckeeordering(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; @@ -135,19 +90,12 @@ _pgr_cuthillmckeeordering(PG_FUNCTION_ARGS) { funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /*********************************************************************** - * - * pgr_cuthillMckeeOrdering(edges_sql TEXT); - * - **********************************************************************/ - process( text_to_cstring(PG_GETARG_TEXT_P(0)), &result_tuples, &result_count); - funcctx->max_calls = result_count; - + funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) { @@ -171,13 +119,6 @@ _pgr_cuthillmckeeordering(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - /*********************************************************************** - * - * OUT seq BIGINT, - * OUT node BIGINT, - * - **********************************************************************/ - size_t num = 3; values = palloc(num * sizeof(Datum)); nulls = palloc(num * sizeof(bool)); diff --git a/src/ordering/cuthillMckeeOrdering_driver.cpp b/src/ordering/cuthillMckeeOrdering_driver.cpp index 3ea32109522..cc2315d7a18 100644 --- a/src/ordering/cuthillMckeeOrdering_driver.cpp +++ b/src/ordering/cuthillMckeeOrdering_driver.cpp @@ -31,8 +31,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "c_types/ii_t_rt.h" #include "ordering/cuthillMckeeOrdering.hpp" @@ -67,31 +68,9 @@ cuthillMckeeOrdering(G &graph) { } // namespace -/** @brief Performs exception handling and converts the results to postgres. - * - * @pre log_msg is empty - * @pre notice_msg is empty - * @pre err_msg is empty - * @pre return_tuples is empty - * @pre return_count is 0 - * - * It builds the undirected graph using the `data_edges` variable. - * Then, it passes the required variables to the template function - * `cuthillMckeeOrdering` which calls the main function - * defined in the C++ Header file. It also does exception handling. - * - * @param data_edges the set of edges from the SQL query - * @param total_edges the total number of edges in the SQL query - * @param return_tuples the rows in the result - * @param return_count the count of rows in the result - * @param log_msg stores the log message - * @param notice_msg stores the notice message - * @param err_msg stores the error message - */ -void do_cuthillMckeeOrdering( - Edge_t *data_edges, - size_t total_edges, +void pgr_do_cuthillMckeeOrdering( + char *edges_sql, II_t_rt **return_tuples, size_t *return_count, @@ -106,6 +85,8 @@ void do_cuthillMckeeOrdering( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); @@ -113,12 +94,18 @@ void do_cuthillMckeeOrdering( pgassert(!(*return_tuples)); pgassert(*return_count == 0); - graphType gType = UNDIRECTED; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; std::vectorresults; - - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); results = cuthillMckeeOrdering(undigraph); auto count = results.size(); @@ -149,6 +136,9 @@ void do_cuthillMckeeOrdering( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/pickDeliver/CMakeLists.txt b/src/pickDeliver/CMakeLists.txt index 13891c4ecdb..ae22c9adb32 100644 --- a/src/pickDeliver/CMakeLists.txt +++ b/src/pickDeliver/CMakeLists.txt @@ -1,7 +1,7 @@ ADD_LIBRARY(pickDeliver OBJECT pd_orders.cpp fleet.cpp - pgr_pickDeliver.cpp + pickDeliver.cpp dnode.cpp vehicle_pickDeliver.cpp solution.cpp diff --git a/src/pickDeliver/book_keeping.cpp b/src/pickDeliver/book_keeping.cpp index baabb521bee..d5cdb05cf06 100644 --- a/src/pickDeliver/book_keeping.cpp +++ b/src/pickDeliver/book_keeping.cpp @@ -1,4 +1,5 @@ /*PGR-GNU***************************************************************** +File: book_keeping.cpp FILE: book_keeping.cpp @@ -24,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/book_keeping.h" +#include "vrp/book_keeping.hpp" #include #include diff --git a/src/pickDeliver/dnode.cpp b/src/pickDeliver/dnode.cpp index 3e2a457ef0e..a6fe2b4d9ee 100644 --- a/src/pickDeliver/dnode.cpp +++ b/src/pickDeliver/dnode.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: dnode.cpp +File: dnode.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -23,9 +22,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/dnode.h" +#include "vrp/dnode.hpp" -#include "vrp/pgr_pickDeliver.h" +#include "vrp/pickDeliver.hpp" namespace pgrouting { namespace vrp { diff --git a/src/pickDeliver/fleet.cpp b/src/pickDeliver/fleet.cpp index ea97e839070..d3646db3354 100644 --- a/src/pickDeliver/fleet.cpp +++ b/src/pickDeliver/fleet.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: solution.cpp +File: fleet.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -23,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/fleet.h" +#include "vrp/fleet.hpp" #include #include @@ -31,8 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "vrp/dnode.h" -#include "vrp/pgr_pickDeliver.h" +#include "vrp/dnode.hpp" +#include "vrp/pickDeliver.hpp" namespace pgrouting { namespace vrp { @@ -81,10 +80,6 @@ Fleet::get_truck() { Vehicle_pickDeliver Fleet::get_truck(size_t order) { -#if 0 - msg().log << "Available vehicles: " << m_un_used << "\n"; - msg().log << "NOT Available vehicles: " << m_used << "\n"; -#endif size_t idx{0}; for (const auto &i : m_un_used) { @@ -139,9 +134,6 @@ Fleet::add_vehicle( vehicle.capacity, vehicle.speed, factor)); -#if 0 - msg().log << "inserting vehicle: " << m_trucks.back().tau() << "\n"; -#endif pgassert((m_trucks.back().idx() + 1) == m_trucks.size()); pgassert(m_trucks.back().is_ok()); } diff --git a/src/pickDeliver/initial_solution.cpp b/src/pickDeliver/initial_solution.cpp index b9fc6ba032c..2bc78b50340 100644 --- a/src/pickDeliver/initial_solution.cpp +++ b/src/pickDeliver/initial_solution.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: initial_solution.cpp +File: initial_solution.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,13 +23,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/initial_solution.h" +#include "vrp/initial_solution.hpp" #include #include #include -#include "cpp_common/pgr_assert.h" -#include "vrp/solution.h" -#include "vrp/pgr_pickDeliver.h" +#include "cpp_common/assert.hpp" +#include "vrp/solution.hpp" +#include "vrp/pickDeliver.hpp" namespace pgrouting { namespace vrp { @@ -79,30 +78,15 @@ Initial_solution::do_while_foo(int kind) { invariant(); pgassert(kind > 0 && kind <= OneDepot); -#if 0 - msg().log << "\nInitial_solution::do_while_foo\n"; -#endif Identifiers notused; while (!m_unassigned.empty()) { -#if 0 - msg().log << m_unassigned.size() << " m_unassigned: " << m_unassigned << "\n"; - msg().log << m_assigned.size() << " m_assigned:" << m_assigned << "\n"; -#endif auto current = m_unassigned.size(); auto truck = trucks.get_truck(m_unassigned.front()); -#if 0 - msg().log << "got truck:" << truck.tau() << "\n"; -#endif /* * kind 1 to 7 work with the same code structure */ truck.do_while_feasable((Initials_code)kind, m_unassigned, m_assigned); -#if 0 - msg().log << m_unassigned.size() << " m_unassigned: " << m_unassigned << "\n"; - msg().log << m_assigned.size() << " m_assigned:" << m_assigned << "\n"; - msg().log << "current" << current << " m_unassigned: " << m_unassigned.size(); -#endif pgassertwm(current > m_unassigned.size(), msg().get_log().c_str()); fleet.push_back(truck); diff --git a/src/pickDeliver/optimize.cpp b/src/pickDeliver/optimize.cpp index 8821786cfd2..983aeb52906 100644 --- a/src/pickDeliver/optimize.cpp +++ b/src/pickDeliver/optimize.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: optimize.cpp +File: optimize.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -28,11 +27,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" -#include "vrp/solution.h" -#include "vrp/optimize.h" -#include "vrp/pgr_pickDeliver.h" +#include "vrp/solution.hpp" +#include "vrp/optimize.hpp" +#include "vrp/pickDeliver.hpp" namespace pgrouting { namespace vrp { @@ -103,17 +102,8 @@ Optimize::inter_swap() { for (auto &to : fleet) { if (&from == &to) break; -#if 0 - msg().log - << "\n to " << to.id() - << "from " << from.id(); - auto swapped = false; -#endif swap_worse(to, from); move_reduce_cost(from, to); -#if 0 - msg().log << "++++++++" << p_swaps; -#endif } } @@ -259,7 +249,7 @@ Optimize::swap_worse(Vehicle_pickDeliver &to, Vehicle_pickDeliver &from) { } } - return false && swapped; + return swapped; } @@ -493,17 +483,11 @@ Optimize::save_if_best() { best_solution = (*this); msg().log << "\n*********** best by duration" << best_solution.cost_str(); -#if 0 - msg().dbg_log << best_solution.tau("best by duration"); -#endif } if (fleet.size() < best_solution.fleet.size()) { best_solution = (*this); msg().log << "\n*********** best by fleet size" << best_solution.cost_str(); -#if 0 - msg().dbg_log << best_solution.tau("best by fleet size"); -#endif } } diff --git a/src/pickDeliver/order.cpp b/src/pickDeliver/order.cpp index 61e32264304..d68341693e7 100644 --- a/src/pickDeliver/order.cpp +++ b/src/pickDeliver/order.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: order.cpp +File: order.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/order.h" +#include "vrp/order.hpp" namespace pgrouting { diff --git a/src/pickDeliver/pd_orders.cpp b/src/pickDeliver/pd_orders.cpp index fdb7c990093..656ea1b99f6 100644 --- a/src/pickDeliver/pd_orders.cpp +++ b/src/pickDeliver/pd_orders.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: solution.cpp +File: pd_orders.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -23,15 +22,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/pd_orders.h" +#include "vrp/pd_orders.hpp" #include #include #include #include -#include "vrp/pgr_pickDeliver.h" -#include "vrp/dnode.h" +#include "vrp/pickDeliver.hpp" +#include "vrp/dnode.hpp" namespace pgrouting { namespace vrp { @@ -64,9 +63,6 @@ void PD_Orders::build_orders( const std::vector &pd_orders ) { -#if 0 - ENTERING(); -#endif for (const auto &order : pd_orders) { /* * SAMPLE CORRECT INFORMATION @@ -93,10 +89,6 @@ PD_Orders::build_orders( add_order(order, pickup, delivery); } // for (creating orders) - -#if 0 - EXITING(); -#endif } diff --git a/src/pickDeliver/pd_problem.cpp b/src/pickDeliver/pd_problem.cpp index 40e01fc4dcf..b0409cdad9e 100644 --- a/src/pickDeliver/pd_problem.cpp +++ b/src/pickDeliver/pd_problem.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: pgr_pickDeliver.h +File: pd_problem.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,13 +23,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/pd_problem.h" -#include "vrp/dnode.h" -#include "vrp/fleet.h" -#include "vrp/solution.h" -#include "vrp/tw_node.h" -#include "vrp/pd_orders.h" -#include "vrp/vehicle.h" +#include "vrp/pd_problem.hpp" +#include "vrp/dnode.hpp" +#include "vrp/fleet.hpp" +#include "vrp/solution.hpp" +#include "vrp/tw_node.hpp" +#include "vrp/pd_orders.hpp" +#include "vrp/vehicle.hpp" namespace pgrouting { namespace vrp { diff --git a/src/pickDeliver/pickDeliver.c b/src/pickDeliver/pickDeliver.c index 431aa948aa1..9da28534f78 100644 --- a/src/pickDeliver/pickDeliver.c +++ b/src/pickDeliver/pickDeliver.c @@ -31,10 +31,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/iid_t_rt.h" -#include "c_types/pickDeliver/schedule_rt.h" +#include "c_types/schedule_rt.h" #include "drivers/pickDeliver/pickDeliver_driver.h" @@ -84,92 +83,11 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - PGR_DBG("Load orders"); - Orders_t *pd_orders_arr = NULL; - size_t total_pd_orders = 0; - pgr_get_orders(pd_orders_sql, &pd_orders_arr, &total_pd_orders, true, &err_msg); - throw_error(err_msg, pd_orders_sql); - - PGR_DBG("Load vehicles"); - Vehicle_t *vehicles_arr = NULL; - size_t total_vehicles = 0; - pgr_get_vehicles(vehicles_sql, &vehicles_arr, &total_vehicles, true, &err_msg); - throw_error(err_msg, vehicles_sql); - PGR_DBG("total vehicles %ld", total_vehicles); - - -#if 0 - for (size_t i = 0; i < total_pd_orders; i++) { - PGR_DBG("%ld %f pick %f %f %ld - " - "%f %f %f deliver %f %f %ld - %f %f %f ", - pd_orders_arr[i].id, - pd_orders_arr[i].demand, - - pd_orders_arr[i].pick_x, - pd_orders_arr[i].pick_y, - pd_orders_arr[i].pick_node_id, - - pd_orders_arr[i].pick_open_t, - pd_orders_arr[i].pick_close_t, - pd_orders_arr[i].pick_service_t, - - pd_orders_arr[i].deliver_x, - pd_orders_arr[i].deliver_y, - pd_orders_arr[i].deliver_node_id, - - pd_orders_arr[i].deliver_open_t, - pd_orders_arr[i].deliver_close_t, - pd_orders_arr[i].deliver_service_t); - } - - for (size_t i = 0; i < total_vehicles; i++) { - PGR_DBG("%ld %f %f / %ld %f %f %f %f %f / %ld %f %f %f %f %f / %ld ", - vehicles_arr[i].id, - vehicles_arr[i].capacity, - vehicles_arr[i].speed, - - vehicles_arr[i].start_node_id, - vehicles_arr[i].start_x, - vehicles_arr[i].start_y, - vehicles_arr[i].start_open_t, - vehicles_arr[i].start_close_t, - vehicles_arr[i].start_service_t, - - vehicles_arr[i].end_node_id, - vehicles_arr[i].end_x, - vehicles_arr[i].end_y, - vehicles_arr[i].end_open_t, - vehicles_arr[i].end_close_t, - vehicles_arr[i].end_service_t, - - vehicles_arr[i].cant_v); - } -#endif - PGR_DBG("load matrix"); - IID_t_rt *matrix_cells_arr = NULL; - size_t total_cells = 0; - pgr_get_matrixRows(matrix_sql, &matrix_cells_arr, &total_cells, &err_msg); - throw_error(err_msg, matrix_sql); - - - if (total_pd_orders == 0 || total_vehicles == 0 || total_cells == 0) { - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - PGR_DBG("Total %ld orders in query:", total_pd_orders); - PGR_DBG("Total %ld vehicles in query:", total_vehicles); - PGR_DBG("Total %ld matrix cells in query:", total_cells); - - - PGR_DBG("Starting processing"); - clock_t start_t = clock(); - - do_pgr_pickDeliver( - pd_orders_arr, total_pd_orders, - vehicles_arr, total_vehicles, - matrix_cells_arr, total_cells, + clock_t start_t = clock(); + pgr_do_pickDeliver( + pd_orders_sql, + vehicles_sql, + matrix_sql, factor, max_cycles, @@ -189,51 +107,26 @@ process( (*result_count) = 0; (*result_tuples) = NULL; } -#if 1 - pgr_global_report(log_msg, notice_msg, err_msg); -#else - pgr_global_report(notice_msg, log_msg, err_msg); -#endif - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (pd_orders_arr) pfree(pd_orders_arr); - if (vehicles_arr) pfree(vehicles_arr); - if (matrix_cells_arr) pfree(matrix_cells_arr); + + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } - -/******************************************************************************/ - - PGDLLEXPORT Datum _pgr_pickdeliver(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ Schedule_rt *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); - /********************************************************************** - orders_sql TEXT, - vehicles_sql TEXT, - matrix_cell_sql TEXT, - factor FLOAT DEFAULT 1, - max_cycles INTEGER DEFAULT 10, - initial_sol INTEGER DEFAULT 4, - **********************************************************************/ - process( text_to_cstring(PG_GETARG_TEXT_P(0)), text_to_cstring(PG_GETARG_TEXT_P(1)), @@ -244,9 +137,6 @@ _pgr_pickdeliver(PG_FUNCTION_ARGS) { &result_tuples, &result_count); - /*********************************************************************/ - - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -273,24 +163,6 @@ _pgr_pickdeliver(PG_FUNCTION_ARGS) { bool* nulls; size_t call_cntr = funcctx->call_cntr; - /********************************************************************* - - OUT seq INTEGER, - OUT vehicle_number INTEGER, - OUT vehicle_id BIGINT, - OUT vehicle_seq INTEGER, - OUT order_id BIGINT, - OUT stop_type INT, - OUT cargo FLOAT, - OUT travel_time FLOAT, - OUT arrival_time FLOAT, - OUT wait_time FLOAT, - OUT service_time FLOAT, - OUT departure_time FLOAT - - *********************************************************************/ - - size_t numb = 13; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -315,7 +187,6 @@ _pgr_pickdeliver(PG_FUNCTION_ARGS) { values[11] = Float8GetDatum(result_tuples[call_cntr].serviceTime); values[12] = Float8GetDatum(result_tuples[call_cntr].departureTime); - /*********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/pickDeliver/pgr_pickDeliver.cpp b/src/pickDeliver/pickDeliver.cpp similarity index 73% rename from src/pickDeliver/pgr_pickDeliver.cpp rename to src/pickDeliver/pickDeliver.cpp index 4a30378b678..8872a04f5eb 100644 --- a/src/pickDeliver/pgr_pickDeliver.cpp +++ b/src/pickDeliver/pickDeliver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -FILE: pgr_pickDeliver.cpp +File: pickDeliver.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/pgr_pickDeliver.h" +#include "vrp/pickDeliver.hpp" #include #include @@ -30,19 +30,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "c_types/pickDeliver/schedule_rt.h" +#include "c_types/schedule_rt.h" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" -#include "vrp/initials_code.h" -#include "vrp/vehicle_node.h" -#include "vrp/vehicle_pickDeliver.h" -#include "vrp/order.h" -#include "vrp/pd_orders.h" -#include "vrp/fleet.h" -#include "vrp/solution.h" -#include "vrp/initial_solution.h" -#include "vrp/optimize.h" +#include "vrp/initials_code.hpp" +#include "vrp/vehicle_node.hpp" +#include "vrp/vehicle_pickDeliver.hpp" +#include "vrp/order.hpp" +#include "vrp/pd_orders.hpp" +#include "vrp/fleet.hpp" +#include "vrp/solution.hpp" +#include "vrp/initial_solution.hpp" +#include "vrp/optimize.hpp" namespace pgrouting { namespace vrp { @@ -80,11 +80,7 @@ Pgr_pickDeliver::solve() { return rhs < lhs; }); -#if 1 solutions.push_back(Optimize(initial_sols.back(), m_max_cycles)); -#else - solutions.push_back(initial_sols.back()); -#endif pgassert(!solutions.empty()); msg.log << "best solution duration = " << solutions.back().duration(); @@ -162,30 +158,14 @@ Pgr_pickDeliver::Pgr_pickDeliver( return; } -#if 0 - pgassert(m_trucks.msg().get_error().empty()); - pgassert(msg().get_error().empty()); -#endif msg.log << "\n Checking fleet ..."; if (!m_trucks.is_fleet_ok()) { pgassert(msg.get_error().empty()); -#if 0 - pgassert(!m_trucks.msg.get_error().empty()); - msg.error << m_trucks.msg.get_error(); -#endif return; } msg.log << "fleet OK \n"; -#if 0 - for (const auto t : m_trucks) { - msg.log << t << "\n"; - } - for (const auto &o : m_orders) { - msg.log << o << "\n"; - } -#endif /* * check the (S, P, D, E) order on all vehicles @@ -199,39 +179,12 @@ Pgr_pickDeliver::Pgr_pickDeliver( << o.id() << " is not feasible on any truck"; msg.log << "\n" << o; -#if 0 - double old_speed(0); - for (auto t : m_trucks) { - if (old_speed == t.speed()) continue; - old_speed = t.speed(); - msg.log << "****** With speed: " << t.speed() << "\n"; - msg.log << t.start_site() << "\n"; - msg.log << o.pickup() << "\n"; - msg.log << "travel time to " - << t.start_site().travel_time_to( - o.pickup(), t.speed()) << "\n"; - - msg.log << o.delivery() << "\n"; - msg.log << t.end_site() << "\n"; - msg.log << "travel time to " - << t.start_site().travel_time_to( - o.delivery(), t.speed()) - << "\n"; - t.push_back(o); - } -#endif return; } } msg.log << "orders OK \n"; m_trucks.set_compatibles(m_orders); -#if 0 - msg.error << "foo"; - for (const auto t : m_trucks) { - msg.log << t << "\n"; - } -#endif EXITING(msg); } // constructor diff --git a/src/pickDeliver/pickDeliverEuclidean.c b/src/pickDeliver/pickDeliverEuclidean.c index bd9fb1047f3..f1e41c5b7a4 100644 --- a/src/pickDeliver/pickDeliverEuclidean.c +++ b/src/pickDeliver/pickDeliverEuclidean.c @@ -33,11 +33,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/iid_t_rt.h" -#include "c_types/pickDeliver/orders_t.h" -#include "c_types/pickDeliver/vehicle_t.h" -#include "c_types/pickDeliver/schedule_rt.h" +#include "c_types/schedule_rt.h" #include "drivers/pickDeliver/pickDeliverEuclidean_driver.h" @@ -88,80 +85,10 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - PGR_DBG("Load orders"); - Orders_t *pd_orders_arr = NULL; - size_t total_pd_orders = 0; - pgr_get_orders(pd_orders_sql, &pd_orders_arr, &total_pd_orders, false, &err_msg); - throw_error(err_msg, pd_orders_sql); - - PGR_DBG("Load vehicles"); - Vehicle_t *vehicles_arr = NULL; - size_t total_vehicles = 0; - pgr_get_vehicles(vehicles_sql, &vehicles_arr, &total_vehicles, false, &err_msg); - throw_error(err_msg, vehicles_sql); - PGR_DBG("total vehicles %ld", total_vehicles); - - size_t i; - for (i = 0; i < total_pd_orders; i++) { - PGR_DBG("%ld %f pick %f %f %ld - " - "%f %f %f deliver %f %f %ld - %f %f %f ", - pd_orders_arr[i].id, - pd_orders_arr[i].demand, - - pd_orders_arr[i].pick_x, - pd_orders_arr[i].pick_y, - pd_orders_arr[i].pick_node_id, - - pd_orders_arr[i].pick_open_t, - pd_orders_arr[i].pick_close_t, - pd_orders_arr[i].pick_service_t, - - pd_orders_arr[i].deliver_x, - pd_orders_arr[i].deliver_y, - pd_orders_arr[i].deliver_node_id, - - pd_orders_arr[i].deliver_open_t, - pd_orders_arr[i].deliver_close_t, - pd_orders_arr[i].deliver_service_t); - } - - - - for (i = 0; i < total_vehicles; i++) { - PGR_DBG("%ld %f %f , start %f %f %f %f %f " - "end %f %f %f %f %f number %ld ", - vehicles_arr[i].id, - vehicles_arr[i].capacity, - vehicles_arr[i].speed, - - vehicles_arr[i].start_x, - vehicles_arr[i].start_y, - vehicles_arr[i].start_open_t, - vehicles_arr[i].start_close_t, - vehicles_arr[i].start_service_t, - - vehicles_arr[i].end_x, - vehicles_arr[i].end_y, - vehicles_arr[i].end_open_t, - vehicles_arr[i].end_close_t, - vehicles_arr[i].end_service_t, - - vehicles_arr[i].cant_v); - } - - if (total_pd_orders == 0 || total_vehicles == 0) { - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - PGR_DBG("Total %ld orders in query:", total_pd_orders); - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_pickDeliverEuclidean( - pd_orders_arr, total_pd_orders, - vehicles_arr, total_vehicles, + pgr_do_pickDeliverEuclidean( + pd_orders_sql, + vehicles_sql, factor, max_cycles, @@ -181,46 +108,24 @@ process( (*result_tuples) = NULL; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (pd_orders_arr) pfree(pd_orders_arr); - if (vehicles_arr) pfree(vehicles_arr); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ PGDLLEXPORT Datum _pgr_pickdelivereuclidean(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ - /* MODIFY AS NEEDED */ - /* */ Schedule_rt *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); - /**********************************************************************/ - /* MODIFY AS NEEDED */ - /* - orders_sql TEXT, - vehicles_sql INTEGER, - max_cycles INTEGER, - initial_id INTEGER, - **********************************************************************/ - PGR_DBG("Calling process"); process( text_to_cstring(PG_GETARG_TEXT_P(0)), @@ -231,10 +136,6 @@ _pgr_pickdelivereuclidean(PG_FUNCTION_ARGS) { &result_tuples, &result_count); - /* */ - /*********************************************************************/ - - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -261,19 +162,6 @@ _pgr_pickdelivereuclidean(PG_FUNCTION_ARGS) { bool* nulls; size_t call_cntr = funcctx->call_cntr; - /*********************************************************************/ - /* MODIFY!!!!! */ - /* This has to match you output otherwise the server crashes */ - /* - OUT seq INTEGER, - OUT vehicle_id INTEGER, - OUT vehicle_seq INTEGER, - OUT order_id BIGINT, - OUT cost FLOAT, - OUT agg_cost FLOAT - *********************************************************************/ - - size_t numb = 12; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -284,7 +172,6 @@ _pgr_pickdelivereuclidean(PG_FUNCTION_ARGS) { } - // postgres starts counting from 1 values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); values[1] = Int32GetDatum(result_tuples[call_cntr].vehicle_seq); values[2] = Int64GetDatum(result_tuples[call_cntr].vehicle_id); @@ -298,8 +185,6 @@ _pgr_pickdelivereuclidean(PG_FUNCTION_ARGS) { values[10] = Float8GetDatum(result_tuples[call_cntr].serviceTime); values[11] = Float8GetDatum(result_tuples[call_cntr].departureTime); - /*********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); diff --git a/src/pickDeliver/pickDeliverEuclidean_driver.cpp b/src/pickDeliver/pickDeliverEuclidean_driver.cpp index c82cbaae54e..f21e95d4f45 100644 --- a/src/pickDeliver/pickDeliverEuclidean_driver.cpp +++ b/src/pickDeliver/pickDeliverEuclidean_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pickDeliver_driver.cpp +File: pickDeliverEuclidean_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -37,27 +37,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "c_types/pickDeliver/schedule_rt.h" +#include "c_types/schedule_rt.h" -#include "vrp/pgr_pickDeliver.h" +#include "vrp/pickDeliver.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/alloc.hpp" -/************************************************************ - customers_sql TEXT, - max_vehicles INTEGER, - factor FLOAT, - capacity FLOAT, - max_cycles INTEGER, - ***********************************************************/ void -do_pgr_pickDeliverEuclidean( - Orders_t *customers_arr, - size_t total_customers, - - Vehicle_t *vehicles_arr, - size_t total_vehicles, +pgr_do_pickDeliverEuclidean( + char *customers_sql, + char *vehicles_sql, double factor, int max_cycles, @@ -76,17 +67,29 @@ do_pgr_pickDeliverEuclidean( std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char* hint = nullptr; + try { *return_tuples = nullptr; *return_count = 0; - /* - * transform to C++ containers - */ - std::vector orders( - customers_arr, customers_arr + total_customers); - std::vector vehicles( - vehicles_arr, vehicles_arr + total_vehicles); + hint = customers_sql; + auto orders = pgrouting::pgget::get_orders(std::string(customers_sql), false); + if (orders.size() == 0) { + *notice_msg = pgr_msg("Insufficient data found on inner query"); + *log_msg = hint? pgr_msg(hint) : nullptr; + return; + } + + hint = vehicles_sql; + auto vehicles = pgrouting::pgget::get_vehicles(std::string(vehicles_sql), false); + if (vehicles.size() == 0) { + *notice_msg = pgr_msg("Insufficient data found on inner query"); + *log_msg = hint? pgr_msg(hint) : nullptr; + return; + } + + hint = nullptr; std::map, int64_t> matrix_data; @@ -194,6 +197,9 @@ do_pgr_pickDeliverEuclidean( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (const std::pair& ex) { (*return_count) = 0; err << ex.first; diff --git a/src/pickDeliver/pickDeliver_driver.cpp b/src/pickDeliver/pickDeliver_driver.cpp index b56b82ced02..275f0ff056e 100644 --- a/src/pickDeliver/pickDeliver_driver.cpp +++ b/src/pickDeliver/pickDeliver_driver.cpp @@ -36,28 +36,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "vrp/pgr_pickDeliver.h" -#include "vrp/initials_code.h" -#include "cpp_common/Dmatrix.h" +#include "vrp/pickDeliver.hpp" +#include "vrp/initials_code.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/Dmatrix.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/alloc.hpp" #include "c_types/iid_t_rt.h" -#include "c_types/pickDeliver/orders_t.h" -#include "c_types/pickDeliver/vehicle_t.h" -#include "c_types/pickDeliver/schedule_rt.h" +#include "cpp_common/orders_t.hpp" +#include "cpp_common/vehicle_t.hpp" +#include "c_types/schedule_rt.h" void -do_pgr_pickDeliver( - Orders_t customers_arr[], - size_t total_customers, - - Vehicle_t *vehicles_arr, - size_t total_vehicles, - - IID_t_rt *matrix_cells_arr, - size_t total_cells, +pgr_do_pickDeliver( + char* customers_sql, + char *vehicles_sql, + char *matrix_sql, double factor, int max_cycles, @@ -76,30 +72,40 @@ do_pgr_pickDeliver( std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); - pgassert(total_customers); - pgassert(total_vehicles); - pgassert(total_vehicles); pgassert(*return_count == 0); pgassert(!(*return_tuples)); - log << "do_pgr_pickDeliver\n"; + hint = customers_sql; + auto orders = pgrouting::pgget::get_orders(std::string(customers_sql), true); + if (orders.size() == 0) { + *notice_msg = pgr_msg("Insufficient data found on inner query"); + *log_msg = hint? pgr_msg(hint) : nullptr; + return; + } - /* - * transform to C++ containers - */ - std::vector orders( - customers_arr, customers_arr + total_customers); + hint = vehicles_sql; + auto vehicles = pgrouting::pgget::get_vehicles(std::string(vehicles_sql), true); + if (vehicles.size() == 0) { + *notice_msg = pgr_msg("Insufficient data found on inner query"); + *log_msg = hint? pgr_msg(hint) : nullptr; + return; + } - std::vector vehicles( - vehicles_arr, vehicles_arr + total_vehicles); + hint = matrix_sql; + auto data_costs = pgrouting::pgget::get_matrixRows(std::string(matrix_sql)); - std::vector data_costs( - matrix_cells_arr, - matrix_cells_arr + total_cells); + if (data_costs.size() == 0) { + *notice_msg = pgr_msg("Insufficient data found on inner query"); + *log_msg = hint? pgr_msg(hint) : nullptr; + return; + } + hint = nullptr; pgrouting::tsp::Dmatrix cost_matrix(data_costs); @@ -210,6 +216,9 @@ do_pgr_pickDeliver( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (const std::pair& ex) { (*return_count) = 0; err << ex.first; diff --git a/src/pickDeliver/solution.cpp b/src/pickDeliver/solution.cpp index 3b54fee6eec..c4a8dedaddd 100644 --- a/src/pickDeliver/solution.cpp +++ b/src/pickDeliver/solution.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: solution.cpp +File: solution.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -23,15 +22,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/solution.h" +#include "vrp/solution.hpp" #include #include #include -#include "c_types/pickDeliver/schedule_rt.h" +#include "c_types/schedule_rt.h" -#include "vrp/pgr_pickDeliver.h" +#include "vrp/pickDeliver.hpp" namespace pgrouting { diff --git a/src/pickDeliver/tw_node.cpp b/src/pickDeliver/tw_node.cpp index ef80340e3de..76f6c9d875e 100644 --- a/src/pickDeliver/tw_node.cpp +++ b/src/pickDeliver/tw_node.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: tw_node.cpp +File: tw_node.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -23,13 +22,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/tw_node.h" +#include "vrp/tw_node.hpp" #include #include -#include "cpp_common/pgr_assert.h" -#include "vrp/pgr_pickDeliver.h" +#include "cpp_common/assert.hpp" +#include "vrp/pickDeliver.hpp" namespace pgrouting { diff --git a/src/pickDeliver/vehicle.cpp b/src/pickDeliver/vehicle.cpp index 88162551f9f..6813eff026e 100644 --- a/src/pickDeliver/vehicle.cpp +++ b/src/pickDeliver/vehicle.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: vehicle.cpp +File: vehicle.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -23,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/vehicle.h" +#include "vrp/vehicle.hpp" #include #include @@ -34,11 +33,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "c_types/pickDeliver/schedule_rt.h" +#include "c_types/schedule_rt.h" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" -#include "vrp/pgr_pickDeliver.h" +#include "vrp/pickDeliver.hpp" namespace pgrouting { @@ -430,17 +429,10 @@ Vehicle::Vehicle( m_capacity(p_m_capacity), m_factor(p_factor), m_speed(p_speed) { -#if 0 - ENTERING(); -#endif m_path.clear(); pgassert(starting_site.opens() <= starting_site.closes()); pgassert(ending_site.opens() <= ending_site.closes()); pgassert(capacity() > 0); -#if 0 - msg().log << "p_idx: " << p_idx << "\t idx(): " << idx() << "\n"; - msg().log << "p_id: " << p_id << "\tid(): " << id() << "\n"; -#endif m_path.push_back(starting_site); m_path.push_back(ending_site); @@ -448,9 +440,6 @@ Vehicle::Vehicle( evaluate(0); msg().log << tau() << "\n"; invariant(); -#if 0 - EXITING(); -#endif } diff --git a/src/pickDeliver/vehicle_node.cpp b/src/pickDeliver/vehicle_node.cpp index 44a7daae77f..3fdf584db74 100644 --- a/src/pickDeliver/vehicle_node.cpp +++ b/src/pickDeliver/vehicle_node.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: vehicle_node.cpp +File: vehicle_node.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -24,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/vehicle_node.h" +#include "vrp/vehicle_node.hpp" namespace pgrouting { diff --git a/src/pickDeliver/vehicle_pickDeliver.cpp b/src/pickDeliver/vehicle_pickDeliver.cpp index 1d3d0fdebb5..5aa62b8d42a 100644 --- a/src/pickDeliver/vehicle_pickDeliver.cpp +++ b/src/pickDeliver/vehicle_pickDeliver.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: vehicle_pickDeliver.cpp +File: vehicle_pickDeliver.cpp Copyright (c) 2016 pgRouting developers Mail: project@pgrouting.org @@ -23,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "vrp/vehicle_pickDeliver.h" +#include "vrp/vehicle_pickDeliver.hpp" #include #include @@ -33,10 +32,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include -#include "cpp_common/pgr_assert.h" -#include "vrp/order.h" -#include "vrp/vehicle.h" -#include "vrp/pgr_pickDeliver.h" +#include "cpp_common/assert.hpp" +#include "vrp/order.hpp" +#include "vrp/vehicle.hpp" +#include "vrp/pickDeliver.hpp" @@ -58,13 +57,7 @@ Vehicle_pickDeliver::Vehicle_pickDeliver( m_orders_in_vehicle(), m_orders(), m_feasable_orders() { -#if 0 - ENTERING(); -#endif invariant(); -#if 0 - EXITING(); -#endif } @@ -229,16 +222,9 @@ Vehicle_pickDeliver::do_while_feasable( Identifiers &unassigned, Identifiers &assigned) { pgassert(is_feasable()); -#if 0 - msg.log << "unasigned" << unassigned << "\n"; - msg.log << "m_feasable_orders" << m_feasable_orders << "\n"; -#endif auto current_feasable = m_feasable_orders * unassigned; while (!current_feasable.empty()) { -#if 0 - msg.log << "current_feasable" << current_feasable << "\n"; -#endif auto order = m_orders[current_feasable.front()]; switch (kind) { diff --git a/src/planar/boyerMyrvold.c b/src/planar/boyerMyrvold.c index b8c81821807..30533b0ef0c 100644 --- a/src/planar/boyerMyrvold.c +++ b/src/planar/boyerMyrvold.c @@ -31,13 +31,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" +#include "c_types/iid_t_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - #include "drivers/planar/boyerMyrvold_driver.h" + PGDLLEXPORT Datum _pgr_boyermyrvold(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_boyermyrvold); @@ -52,56 +51,26 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - PGR_DBG("Initializing arrays"); - - (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_boyerMyrvold( - edges, - total_edges, + pgr_do_boyerMyrvold( + edges_sql, - result_tuples, - result_count, + result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg(" processing pgr_boyerMyrvold", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); if (err_msg) { if (*result_tuples) pfree(*result_tuples); } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) - pfree(edges); - if (log_msg) - pfree(log_msg); - if (notice_msg) - pfree(notice_msg); - if (err_msg) - pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } @@ -110,22 +79,14 @@ PGDLLEXPORT Datum _pgr_boyermyrvold(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**************************************************************************/ IID_t_rt *result_tuples = NULL; size_t result_count = 0; - /**************************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - /* - pgr_boyerMyrvold( - edge_sql TEXT) - */ - /**********************************************************************/ PGR_DBG("Calling process"); process( @@ -133,10 +94,7 @@ PGDLLEXPORT Datum _pgr_boyermyrvold(PG_FUNCTION_ARGS) { &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, @@ -159,13 +117,6 @@ PGDLLEXPORT Datum _pgr_boyermyrvold(PG_FUNCTION_ARGS) { Datum *values; bool *nulls; - /**********************************************************************/ - /* - OUT source BIGINT, - OUT target_vid BIGINT, - OUT cost FLOAT, - */ - /**********************************************************************/ size_t numb = 4; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -180,18 +131,10 @@ PGDLLEXPORT Datum _pgr_boyermyrvold(PG_FUNCTION_ARGS) { values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].target); values[3] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); - /**********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); } else { - /**********************************************************************/ - - PGR_DBG("Clean up code"); - - /**********************************************************************/ - SRF_RETURN_DONE(funcctx); } } diff --git a/src/planar/boyerMyrvold_driver.cpp b/src/planar/boyerMyrvold_driver.cpp index 77bd82d1d9c..dea82dfb128 100644 --- a/src/planar/boyerMyrvold_driver.cpp +++ b/src/planar/boyerMyrvold_driver.cpp @@ -34,7 +34,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgr_assert.hpp" +#include "cpp_common/pgdata_getters.hpp" #include "c_types/iid_t_rt.h" #include "planar/pgr_boyerMyrvold.hpp" @@ -43,9 +44,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. void -do_pgr_boyerMyrvold( - Edge_t *data_edges, - size_t total_edges, +pgr_do_boyerMyrvold( + char *edges_sql, IID_t_rt **return_tuples, size_t *return_count, @@ -55,25 +55,35 @@ do_pgr_boyerMyrvold( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char* hint = nullptr; try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - pgassert(total_edges != 0); std::vector results; std::string logstr; graphType gType = UNDIRECTED; + + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, true); + + if (edges.empty()) { + throw std::string("No edges found"); + } + hint = nullptr; + log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph(directed); + undigraph.insert_edges(edges); pgrouting::functions::Pgr_boyerMyrvold fn_boyerMyrvold; results = fn_boyerMyrvold.boyerMyrvold(undigraph); logstr += fn_boyerMyrvold.get_log(); @@ -92,7 +102,6 @@ do_pgr_boyerMyrvold( } (*return_tuples) = pgr_alloc(count, (*return_tuples)); - log << "\nConverting a set of traversals into the tuples"; for (size_t i = 0; i < count; i++) { *((*return_tuples) + i) = results[i]; } @@ -111,6 +120,9 @@ do_pgr_boyerMyrvold( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/planar/isPlanar.c b/src/planar/isPlanar.c index 14586abf547..d8ebad7b9f9 100644 --- a/src/planar/isPlanar.c +++ b/src/planar/isPlanar.c @@ -34,10 +34,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - #include "drivers/planar/isPlanar_driver.h" + PGDLLEXPORT Datum _pgr_isplanar(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_isplanar); @@ -51,39 +49,16 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - pgr_SPI_finish(); - return (false); - } - clock_t start_t = clock(); - - planarity = do_pgr_isPlanar( - edges, - total_edges, + planarity = pgr_do_isPlanar( + edges_sql, &log_msg, ¬ice_msg, &err_msg); - time_msg(" processing pgr_isPlanar", start_t, clock()); - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) - pfree(edges); - if (log_msg) - pfree(log_msg); - if (notice_msg) - pfree(notice_msg); - if (err_msg) - pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); @@ -91,12 +66,5 @@ process( } PGDLLEXPORT Datum _pgr_isplanar(PG_FUNCTION_ARGS) { - /**********************************************************************/ - /* - pgr_isPlanar( - edge_sql TEXT) - */ - /**********************************************************************/ PG_RETURN_BOOL(process(text_to_cstring(PG_GETARG_TEXT_P(0)))); - /**********************************************************************/ } diff --git a/src/planar/isPlanar_driver.cpp b/src/planar/isPlanar_driver.cpp index 11ad825a63d..bc707f98590 100644 --- a/src/planar/isPlanar_driver.cpp +++ b/src/planar/isPlanar_driver.cpp @@ -33,18 +33,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/pgdata_getters.hpp" -#include "planar/pgr_boyerMyrvold.hpp" -#include "cpp_common/pgr_base_graph.hpp" +#include "planar/boyerMyrvold.hpp" +#include "cpp_common/base_graph.hpp" bool -do_pgr_isPlanar( - Edge_t *data_edges, - size_t total_edges, +pgr_do_isPlanar( + char *edges_sql, char ** log_msg, char ** notice_msg, @@ -52,24 +52,31 @@ do_pgr_isPlanar( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_edges; std::ostringstream log; std::ostringstream err; std::ostringstream notice; - bool result = false; + char* hint = nullptr; try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); - pgassert(total_edges != 0); - graphType gType = UNDIRECTED; - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + bool result = false; + + hint = edges_sql; + auto edges = get_edges(std::string(edges_sql), true, true); + + if (edges.empty()) { + return false; + } + hint = nullptr; + + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); pgrouting::functions::Pgr_boyerMyrvold fn_isPlanar; result = fn_isPlanar.isPlanar(undigraph); - return result; pgassert(*err_msg == NULL); *log_msg = log.str().empty()? @@ -78,10 +85,14 @@ do_pgr_isPlanar( *notice_msg = notice.str().empty()? *notice_msg : pgr_msg(notice.str().c_str()); + return result; } catch (AssertFailedException &except) { err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { err << except.what(); *err_msg = pgr_msg(err.str().c_str()); @@ -91,5 +102,5 @@ do_pgr_isPlanar( *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); } - return result; + return false; } diff --git a/src/spanningTree/details.cpp b/src/spanningTree/details.cpp index e6c16569a16..d6b4dd9b7b8 100644 --- a/src/spanningTree/details.cpp +++ b/src/spanningTree/details.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: details.hpp +File: details.cpp Copyright (c) 2018 pgRouting developers Mail: project@pgrouting.org diff --git a/src/spanningTree/kruskal.c b/src/spanningTree/kruskal.c index c56ae8eae46..7e0d11c8880 100644 --- a/src/spanningTree/kruskal.c +++ b/src/spanningTree/kruskal.c @@ -34,14 +34,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/mst_rt.h" #include "drivers/spanningTree/mst_common.h" #include "drivers/spanningTree/kruskal_driver.h" -PGDLLEXPORT Datum _pgr_kruskal(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(_pgr_kruskal); +PGDLLEXPORT Datum _pgr_kruskalv4(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_kruskalv4); static @@ -59,31 +58,27 @@ process( char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; + (*result_tuples) = NULL; + (*result_count) = 0; char * fn_name = get_name(0, fn_suffix, &err_msg); if (err_msg) { - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); return; } - size_t size_rootsArr = 0; - int64_t* rootsArr = pgr_get_bigIntArray(&size_rootsArr, roots, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - - (*result_tuples) = NULL; - (*result_count) = 0; - - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); + /* checks previously done on sql now done here */ + if (strcmp(fn_suffix, "DD") == 0 && distance < 0) { + pgr_throw_error("Negative value found on 'distance'", "Must be positive"); + } else if ((strcmp(fn_suffix, "BFS") == 0 || strcmp(fn_suffix, "DFS") == 0) && max_depth < 0) { + pgr_throw_error("Negative value found on 'max_depth'", "Must be positive"); + } clock_t start_t = clock(); - do_pgr_kruskal( - edges, total_edges, - rootsArr, size_rootsArr, + pgr_do_kruskal( + edges_sql, + roots, fn_suffix, max_depth, distance, @@ -93,22 +88,93 @@ process( &log_msg, ¬ice_msg, &err_msg); - time_msg(fn_name, start_t, clock()); if (err_msg) { if (*result_tuples) pfree(*result_tuples); } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } +PGDLLEXPORT Datum _pgr_kruskalv4(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + + MST_rt *result_tuples = NULL; + 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)), + PG_GETARG_ARRAYTYPE_P(1), + text_to_cstring(PG_GETARG_TEXT_P(2)), + PG_GETARG_INT64(3), + PG_GETARG_FLOAT8(4), + &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 = (MST_rt*) funcctx->user_fctx; + + if (funcctx->call_cntr < funcctx->max_calls) { + HeapTuple tuple; + Datum result; + Datum *values; + bool* nulls; + + size_t num = 8; + values = palloc(num * sizeof(Datum)); + nulls = palloc(num * sizeof(bool)); + + + size_t i; + for (i = 0; i < num; ++i) { + nulls[i] = false; + } + + values[0] = Int64GetDatum((int64_t)funcctx->call_cntr + 1); + values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].depth); + values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].from_v); + values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].pred); + values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); + values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); + values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); + values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); + + tuple = heap_form_tuple(tuple_desc, values, nulls); + result = HeapTupleGetDatum(tuple); + SRF_RETURN_NEXT(funcctx, result); + } else { + SRF_RETURN_DONE(funcctx); + } +} + +/***********************************************************************************/ + +PGDLLEXPORT Datum _pgr_kruskal(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_kruskal); + PGDLLEXPORT Datum _pgr_kruskal(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; @@ -173,7 +239,6 @@ PGDLLEXPORT Datum _pgr_kruskal(PG_FUNCTION_ARGS) { values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/spanningTree/kruskal_driver.cpp b/src/spanningTree/kruskal_driver.cpp index 0bc5c75892c..91d9b2328a2 100644 --- a/src/spanningTree/kruskal_driver.cpp +++ b/src/spanningTree/kruskal_driver.cpp @@ -33,20 +33,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -#include "spanningTree/pgr_kruskal.hpp" +#include "spanningTree/kruskal.hpp" #include "spanningTree/details.hpp" void -do_pgr_kruskal( - Edge_t *data_edges, - size_t total_edges, - - int64_t *rootsArr, - size_t size_rootsArr, +pgr_do_kruskal( + char *edges_sql, + ArrayType* starts, char* fn_suffix, @@ -62,31 +60,41 @@ do_pgr_kruskal( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intArray; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { + // NOLINTBEGIN(clang-analyzer-cplusplus.NewDelete) pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); + // NOLINTEND(clang-analyzer-cplusplus.NewDelete) + + auto roots = get_intArray(starts, false); + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + hint = nullptr; - std::vector roots(rootsArr, rootsArr + size_rootsArr); std::string suffix(fn_suffix); std::vector results; - if (total_edges == 0) { + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); + pgrouting::functions::Pgr_kruskal kruskal; + + if (edges.empty()) { results = pgrouting::details::get_no_edge_graph_result(roots); + *notice_msg = pgr_msg("No edges found"); + *log_msg = pgr_msg(edges_sql); } else { - pgrouting::UndirectedGraph undigraph(UNDIRECTED); - undigraph.insert_edges(data_edges, total_edges); - - pgrouting::functions::Pgr_kruskal - kruskal; - if (suffix == "") { results = kruskal.kruskal(undigraph); } else if (suffix == "BFS") { @@ -104,13 +112,6 @@ do_pgr_kruskal( auto count = results.size(); - if (count == 0) { - (*return_tuples) = NULL; - (*return_count) = 0; - notice << "No spanning tree found"; - return; - } - (*return_tuples) = pgr_alloc(count, (*return_tuples)); for (size_t i = 0; i < count; i++) { *((*return_tuples) + i) = results[i]; @@ -130,6 +131,9 @@ do_pgr_kruskal( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/spanningTree/mst_common.cpp b/src/spanningTree/mst_common.cpp index 795bf9184f1..1f2a4f6818c 100644 --- a/src/spanningTree/mst_common.cpp +++ b/src/spanningTree/mst_common.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: mst_common.c +File: mst_common.cpp Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org @@ -30,8 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/alloc.hpp" int get_order(char * fn_suffix, char ** err_msg) { diff --git a/src/spanningTree/prim.c b/src/spanningTree/prim.c index 53ab94477ab..93071398f3b 100644 --- a/src/spanningTree/prim.c +++ b/src/spanningTree/prim.c @@ -32,15 +32,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/mst_rt.h" #include "drivers/spanningTree/mst_common.h" #include "drivers/spanningTree/prim_driver.h" -PGDLLEXPORT Datum _pgr_prim(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(_pgr_prim); - +PGDLLEXPORT Datum _pgr_primv4(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_primv4); static void @@ -61,28 +59,20 @@ process( char * fn_name = get_name(1, fn_suffix, &err_msg); if (err_msg) { - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); return; } - size_t size_rootsArr = 0; - int64_t* rootsArr = pgr_get_bigIntArray(&size_rootsArr, roots, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - - (*result_tuples) = NULL; - (*result_count) = 0; - - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - + if (strcmp(fn_suffix, "DD") == 0 && distance < 0) { + pgr_throw_error("Negative value found on 'distance'", "Must be positive"); + } else if ((strcmp(fn_suffix, "BFS") == 0 || strcmp(fn_suffix, "DFS") == 0) && max_depth < 0) { + pgr_throw_error("Negative value found on 'max_depth'", "Must be positive"); + } clock_t start_t = clock(); - do_pgr_prim( - edges, total_edges, - rootsArr, size_rootsArr, + pgr_do_prim( + edges_sql, + roots, fn_suffix, @@ -101,18 +91,91 @@ process( if (err_msg) { if (*result_tuples) pfree(*result_tuples); } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ + + +PGDLLEXPORT Datum _pgr_primv4(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + + MST_rt *result_tuples = NULL; + size_t result_count = 0; + + if (SRF_IS_FIRSTCALL()) { + MemoryContext oldcontext; + funcctx = SRF_FIRSTCALL_INIT(); + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + + /* Edge sql, tree roots, fn_suffix, max_depth, distance */ + process( + text_to_cstring(PG_GETARG_TEXT_P(0)), + PG_GETARG_ARRAYTYPE_P(1), + text_to_cstring(PG_GETARG_TEXT_P(2)), + PG_GETARG_INT64(3), + PG_GETARG_FLOAT8(4), + &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 = (MST_rt*) funcctx->user_fctx; + + if (funcctx->call_cntr < funcctx->max_calls) { + HeapTuple tuple; + Datum result; + Datum *values; + bool* nulls; + + size_t num = 8; + values = palloc(num * sizeof(Datum)); + nulls = palloc(num * sizeof(bool)); + + + size_t i; + for (i = 0; i < num; ++i) { + nulls[i] = false; + } + + values[0] = Int64GetDatum((int64_t)funcctx->call_cntr + 1); + values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].depth); + values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].from_v); + values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].pred); + values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); + values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); + values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); + values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); + + tuple = heap_form_tuple(tuple_desc, values, nulls); + result = HeapTupleGetDatum(tuple); + SRF_RETURN_NEXT(funcctx, result); + } else { + SRF_RETURN_DONE(funcctx); + } +} + /******************************************************************************/ +PGDLLEXPORT Datum _pgr_prim(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_prim); + PGDLLEXPORT Datum _pgr_prim(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; @@ -125,7 +188,6 @@ PGDLLEXPORT Datum _pgr_prim(PG_FUNCTION_ARGS) { funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /* Edge sql, tree roots, fn_suffix, max_depth, distance */ process( text_to_cstring(PG_GETARG_TEXT_P(0)), PG_GETARG_ARRAYTYPE_P(1), @@ -178,8 +240,6 @@ PGDLLEXPORT Datum _pgr_prim(PG_FUNCTION_ARGS) { values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); diff --git a/src/spanningTree/prim_driver.cpp b/src/spanningTree/prim_driver.cpp index f99fe5a7c9a..de2f06b5ffc 100644 --- a/src/spanningTree/prim_driver.cpp +++ b/src/spanningTree/prim_driver.cpp @@ -33,22 +33,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "c_types/mst_rt.h" -#include "spanningTree/pgr_prim.hpp" +#include "spanningTree/prim.hpp" #include "spanningTree/details.hpp" void -do_pgr_prim( - Edge_t *data_edges, - size_t total_edges, - - int64_t *rootsArr, - size_t size_rootsArr, +pgr_do_prim( + char *edges_sql, + ArrayType* starts, char* fn_suffix, @@ -64,28 +62,41 @@ do_pgr_prim( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intArray; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { + // NOLINTBEGIN(clang-analyzer-cplusplus.NewDelete) pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); + // NOLINTEND(clang-analyzer-cplusplus.NewDelete) + + auto roots = get_intArray(starts, false); + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + hint = nullptr; - std::vector roots(rootsArr, rootsArr + size_rootsArr); std::string suffix(fn_suffix); std::vector results; - if (total_edges == 0) { + pgrouting::UndirectedGraph undigraph; + undigraph.insert_min_edges_no_parallel(edges); + pgrouting::functions::Pgr_prim prim; + + if (edges.empty()) { results = pgrouting::details::get_no_edge_graph_result(roots); + *notice_msg = pgr_msg("No edges found"); + *log_msg = pgr_msg(edges_sql); } else { - pgrouting::UndirectedGraph undigraph(UNDIRECTED); - undigraph.insert_min_edges_no_parallel(data_edges, total_edges); - pgrouting::functions::Pgr_prim prim; if (suffix == "") { results = prim.prim(undigraph); } else if (suffix == "BFS") { @@ -103,13 +114,6 @@ do_pgr_prim( auto count = results.size(); - if (count == 0) { - (*return_tuples) = NULL; - (*return_count) = 0; - notice << "No spanning tree found"; - return; - } - (*return_tuples) = pgr_alloc(count, (*return_tuples)); for (size_t i = 0; i < count; i++) { *((*return_tuples) + i) = results[i]; @@ -129,6 +133,9 @@ do_pgr_prim( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/spanningTree/randomSpanningTree.c b/src/spanningTree/randomSpanningTree.c index 50f87b3ff01..6fadbff0c25 100644 --- a/src/spanningTree/randomSpanningTree.c +++ b/src/spanningTree/randomSpanningTree.c @@ -33,7 +33,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/spanningTree/randomSpanningTree_driver.h" @@ -48,9 +47,6 @@ process( bool directed, SpanTree_rt **result_tuples, size_t *result_count) { - /* - * https://www.postgresql.org/docs/current/static/spi-spi-connect.html - */ pgr_SPI_connect(); char* log_msg = NULL; char* notice_msg = NULL; @@ -59,23 +55,8 @@ process( (*result_tuples) = NULL; (*result_count) = 0; - PGR_DBG("Load data"); - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - PGR_DBG("Total %ld edges in query:", total_edges); - - if (total_edges == 0) { - PGR_DBG("No edges found"); - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting processing"); clock_t start_t = clock(); - do_pgr_randomSpanningTree( + pgr_do_randomSpanningTree( edges, total_edges, root_vertex, @@ -92,17 +73,11 @@ process( if (err_msg) { if (*result_tuples) pfree(*result_tuples); } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (edges) pfree(edges); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } /* */ -/******************************************************************************/ PGDLLEXPORT Datum randomSpanningTree(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; @@ -158,14 +133,12 @@ PGDLLEXPORT Datum randomSpanningTree(PG_FUNCTION_ARGS) { nulls[i] = false; } - // postgres starts counting from 1 values[0] = Int64GetDatum((int64_t)funcctx->call_cntr + 1); values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].root_vertex); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); values[3] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[4] = Float8GetDatum(result_tuples[funcctx->call_cntr].tree_cost); - /**********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/spanningTree/randomSpanningTree_driver.cpp b/src/spanningTree/randomSpanningTree_driver.cpp index 649b1ce1318..9c5fca85492 100644 --- a/src/spanningTree/randomSpanningTree_driver.cpp +++ b/src/spanningTree/randomSpanningTree_driver.cpp @@ -31,11 +31,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "spanningTree/pgr_randomSpanningTree.hpp" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "spanningTree/randomSpanningTree.hpp" template < class G > static @@ -49,9 +51,8 @@ pgr_randomSpanningTree( void -do_pgr_randomSpanningTree( - Edge_t *data_edges, - size_t total_edges, +pgr_do_randomSpanningTree( + char *edges_sql, int64_t root_vertex, bool directed, SpanTree_rt **return_tuples, @@ -66,6 +67,8 @@ do_pgr_randomSpanningTree( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); @@ -74,20 +77,30 @@ do_pgr_randomSpanningTree( pgassert(*return_count == 0); pgassert(total_edges != 0); - graphType gType = directed? DIRECTED: UNDIRECTED; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + std::vector results; if (directed) { log << "Working with directed Graph\n"; - pgrouting::DirectedGraph digraph(gType); + pgrouting::DirectedGraph digraph(directed); digraph.insert_edges(data_edges, total_edges); results = pgr_randomSpanningTree( digraph, root_vertex); } else { log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(gType); + pgrouting::UndirectedGraph undigraph(directed); undigraph.insert_edges(data_edges, total_edges); results = pgr_randomSpanningTree( undigraph, @@ -99,8 +112,7 @@ do_pgr_randomSpanningTree( if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; - notice << - "No paths found"; + notice << "No paths found"; return; } @@ -123,6 +135,9 @@ do_pgr_randomSpanningTree( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/topologicalSort/topologicalSort.c b/src/topologicalSort/topologicalSort.c index 2b4610aa208..548db8de3dd 100644 --- a/src/topologicalSort/topologicalSort.c +++ b/src/topologicalSort/topologicalSort.c @@ -1,5 +1,4 @@ /*PGR-GNU***************************************************************** - File: topologicalSort.c Generated with Template by: @@ -36,11 +35,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/topologicalSort/topologicalSort_driver.h" -#if 0 -PG_MODULE_MAGIC; -#endif + PGDLLEXPORT Datum _pgr_topologicalsort(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_topologicalsort); @@ -55,15 +51,9 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - Edge_t *edges = NULL; - size_t total_edges = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - do_pgr_topologicalSort( - edges, total_edges, + pgr_do_topologicalSort( + edges_sql, result_tuples, result_count, &log_msg, @@ -72,19 +62,14 @@ process( time_msg("processing pgr_topologicalSort", 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); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); pgr_SPI_finish(); } @@ -93,28 +78,19 @@ _pgr_topologicalsort(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ I_rt *result_tuples = NULL; size_t result_count = 0; - /**********************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - /**********************************************************************/ - // pgr_topologicalSort( - // sql TEXT, - process( text_to_cstring(PG_GETARG_TEXT_P(0)), &result_tuples, &result_count); - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -141,10 +117,6 @@ _pgr_topologicalsort(PG_FUNCTION_ARGS) { bool* nulls; size_t call_cntr = funcctx->call_cntr; - /**********************************************************************/ - // OUT seq INTEGER, - // OUT sorted_v BIGINT) - size_t numb = 2; values = palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -156,7 +128,6 @@ _pgr_topologicalsort(PG_FUNCTION_ARGS) { values[0] = Int32GetDatum((int32_t)call_cntr + 1); values[1] = Int64GetDatum(result_tuples[call_cntr].id); - /**********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/topologicalSort/topologicalSort_driver.cpp b/src/topologicalSort/topologicalSort_driver.cpp index 0f495304315..8e98f706af1 100644 --- a/src/topologicalSort/topologicalSort_driver.cpp +++ b/src/topologicalSort/topologicalSort_driver.cpp @@ -35,11 +35,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "topologicalSort/pgr_topologicalSort.hpp" +#include "topologicalSort/topologicalSort.hpp" #include "c_types/i_rt.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" namespace { @@ -56,10 +57,8 @@ pgr_topologicalSort( // CREATE OR REPLACE FUNCTION pgr_topologicalSort( // sql text, void -do_pgr_topologicalSort( - Edge_t *data_edges, - size_t total_edges, - +pgr_do_topologicalSort( + char *edges_sql, I_rt **return_tuples, size_t *return_count, @@ -73,21 +72,27 @@ do_pgr_topologicalSort( std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - graphType gType = DIRECTED; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; std::vector results; - - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); results = pgr_topologicalSort( digraph); @@ -120,18 +125,15 @@ do_pgr_topologicalSort( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : 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 (const std::string& ex) { - (*return_count) = 0; - err << ex; - log.str(""); - log.clear(); - *err_msg = pgr_msg(err.str().c_str()); } catch(...) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/transitiveClosure/transitiveClosure.c b/src/transitiveClosure/transitiveClosure.c index 22e6510ee23..246ae2b74a7 100644 --- a/src/transitiveClosure/transitiveClosure.c +++ b/src/transitiveClosure/transitiveClosure.c @@ -41,7 +41,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" #include "c_types/transitiveClosure_rt.h" -#include "c_common/pgdata_getters.h" #include "drivers/transitiveClosure/transitiveClosure_driver.h" PGDLLEXPORT Datum _pgr_transitiveclosure(PG_FUNCTION_ARGS); @@ -59,25 +58,14 @@ process(char* edges_sql, char* notice_msg = NULL; char* err_msg = NULL; - size_t total_edges = 0; - Edge_t* edges = NULL; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - do_pgr_transitiveClosure( - edges, total_edges, + pgr_do_transitiveClosure( + edges_sql, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); - time_msg("processing pgr_transitiveClosure()", start_t, clock()); @@ -87,12 +75,8 @@ process(char* edges_sql, (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); pgr_SPI_finish(); } @@ -101,30 +85,20 @@ _pgr_transitiveclosure(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ TransitiveClosure_rt *result_tuples = NULL; size_t result_count = 0; - /**********************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /**********************************************************************/ - /* - edges_sql TEXT, - - **********************************************************************/ process( text_to_cstring(PG_GETARG_TEXT_P(0)), &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) @@ -148,7 +122,6 @@ _pgr_transitiveclosure(PG_FUNCTION_ARGS) { int16 typlen; size_t call_cntr = funcctx->call_cntr; - /**********************************************************************/ size_t numb = 3; values =(Datum *)palloc(numb * sizeof(Datum)); nulls = palloc(numb * sizeof(bool)); @@ -205,7 +178,6 @@ _pgr_transitiveclosure(PG_FUNCTION_ARGS) { values[1] = Int64GetDatum(result_tuples[call_cntr].vid); values[2] = PointerGetDatum(arrayType); - /*********************************************************************/ tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/transitiveClosure/transitiveClosure_driver.cpp b/src/transitiveClosure/transitiveClosure_driver.cpp index 163d3cc913c..d2e0dd9278e 100644 --- a/src/transitiveClosure/transitiveClosure_driver.cpp +++ b/src/transitiveClosure/transitiveClosure_driver.cpp @@ -28,12 +28,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "transitiveClosure/pgr_transitiveClosure.hpp" +#include "transitiveClosure/transitiveClosure.hpp" +#include "cpp_common/pgdata_getters.hpp" #include "cpp_common/identifiers.hpp" -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/alloc.hpp" #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_base_graph.hpp" +#include "cpp_common/base_graph.hpp" #include "c_types/transitiveClosure_rt.h" @@ -93,9 +94,9 @@ void get_postgres_result( edges_sql TEXT ***********************************************************/ void -do_pgr_transitiveClosure( - Edge_t *data_edges, - size_t total_edges, +pgr_do_transitiveClosure( + char *edges_sql, + TransitiveClosure_rt **return_tuples, size_t *return_count, char **log_msg, @@ -107,23 +108,26 @@ do_pgr_transitiveClosure( std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; + try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - /* - * Converting to C++ structures - */ - std::vector edges(data_edges, data_edges + total_edges); - + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; - graphType gType = DIRECTED; - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); get_postgres_result( digraph, @@ -142,6 +146,9 @@ do_pgr_transitiveClosure( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/traversal/depthFirstSearch.c b/src/traversal/depthFirstSearch.c index 68d3b17f9bb..e3d70f4f211 100644 --- a/src/traversal/depthFirstSearch.c +++ b/src/traversal/depthFirstSearch.c @@ -26,20 +26,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -/** @file depthFirstSearch.c - * @brief Connecting code with postgres. - * - */ - #include #include "c_common/postgres_connection.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - #include "c_types/mst_rt.h" #include "drivers/traversal/depthFirstSearch_driver.h" @@ -47,21 +39,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. PGDLLEXPORT Datum _pgr_depthfirstsearch(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_pgr_depthfirstsearch); -/** @brief Static function, loads the data from postgres to C types for further processing. - * - * It first connects the C function to the SPI manager. Then converts - * the postgres array to C array and loads the edges belonging to the graph - * in C types. Then it calls the function `do_pgr_depthFirstSearch` defined - * in the `depthFirstSearch_driver.h` file for further processing. - * Finally, it frees the memory and disconnects the C function to the SPI manager. - * - * @param edges_sql the edges of the SQL query - * @param roots the root vertices - * @param directed whether the graph is directed or undirected - * @param max_depth the maximum depth of traversal - * @param result_tuples the rows in the result - * @param result_count the count of rows in the result - */ static void process( @@ -76,25 +53,13 @@ process( char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - - size_t size_rootsArr = 0; - - int64_t* rootsArr = pgr_get_bigIntArray(&size_rootsArr, roots, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - (*result_tuples) = NULL; (*result_count) = 0; - Edge_t *edges = NULL; - size_t total_edges = 0; - - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - clock_t start_t = clock(); - do_pgr_depthFirstSearch( - edges, total_edges, - rootsArr, size_rootsArr, + pgr_do_depthFirstSearch( + edges_sql, + roots, directed, max_depth, @@ -104,7 +69,6 @@ process( &log_msg, ¬ice_msg, &err_msg); - time_msg("processing pgr_depthFirstSearch", start_t, clock()); if (err_msg && (*result_tuples)) { @@ -113,48 +77,23 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (rootsArr) pfree(rootsArr); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } -/* */ -/******************************************************************************/ - -/** @brief Helps in converting postgres variables to C variables, and returns the result. - * - */ PGDLLEXPORT Datum _pgr_depthfirstsearch(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ MST_rt *result_tuples = NULL; size_t result_count = 0; - /**********************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - /*********************************************************************** - * - * pgr_depthFirstSearch( - * edges_sql TEXT, - * root_vids ANYARRAY, - * directed BOOLEAN DEFAULT true - * max_depth BIGINT DEFAULT 9223372036854775807, - * ); - * - **********************************************************************/ - process( text_to_cstring(PG_GETARG_TEXT_P(0)), PG_GETARG_ARRAYTYPE_P(1), @@ -163,12 +102,7 @@ PGDLLEXPORT Datum _pgr_depthfirstsearch(PG_FUNCTION_ARGS) { &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) { @@ -192,18 +126,6 @@ PGDLLEXPORT Datum _pgr_depthfirstsearch(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - /*********************************************************************** - * - * OUT seq BIGINT, - * OUT depth BIGINT, - * OUT start_vid BIGINT, - * OUT node BIGINT, - * OUT edge BIGINT, - * OUT cost FLOAT, - * OUT agg_cost FLOAT - * - **********************************************************************/ - size_t num = 7; values = palloc(num * sizeof(Datum)); nulls = palloc(num * sizeof(bool)); @@ -222,8 +144,6 @@ PGDLLEXPORT Datum _pgr_depthfirstsearch(PG_FUNCTION_ARGS) { values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ - tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); diff --git a/src/traversal/depthFirstSearch_driver.cpp b/src/traversal/depthFirstSearch_driver.cpp index 547a102e904..7f23c2c17f8 100644 --- a/src/traversal/depthFirstSearch_driver.cpp +++ b/src/traversal/depthFirstSearch_driver.cpp @@ -32,10 +32,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -#include "traversal/pgr_depthFirstSearch.hpp" +#include "spanningTree/details.hpp" +#include "traversal/depthFirstSearch.hpp" /** @file depthFirstSearch_driver.cpp * @brief Handles actual calling of function in the `pgr_depthFirstSearch.hpp` file. @@ -77,40 +79,10 @@ pgr_depthFirstSearch( } // namespace -/** @brief Performs exception handling and converts the results to postgres. - * - * @pre log_msg is empty - * @pre notice_msg is empty - * @pre err_msg is empty - * @pre return_tuples is empty - * @pre return_count is 0 - * - * It builds the graph using the `data_edges`, depending on whether - * the graph is directed or undirected. It also converts the C types - * to the C++ types, such as the `rootsArr` to `roots` vector and - * passes these variables to the template function `pgr_depthFirstSearch` - * which calls the main function defined in the C++ Header file. It also does - * exception handling. - * - * @param data_edges the set of edges from the SQL query - * @param total_edges the total number of edges in the SQL query - * @param rootsArr the array containing the root vertices - * @param size_rootsArr the size of the array containing the root vertices - * @param directed whether the graph is directed or undirected - * @param max_depth the maximum depth of traversal - * @param return_tuples the rows in the result - * @param return_count the count of rows in the result - * @param log_msg stores the log message - * @param notice_msg stores the notice message - * @param err_msg stores the error message - */ void -do_pgr_depthFirstSearch( - Edge_t *data_edges, - size_t total_edges, - - int64_t *rootsArr, - size_t size_rootsArr, +pgr_do_depthFirstSearch( + char *edges_sql, + ArrayType* starts, bool directed, int64_t max_depth, @@ -124,10 +96,13 @@ do_pgr_depthFirstSearch( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intArray; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); @@ -135,30 +110,37 @@ do_pgr_depthFirstSearch( pgassert(!(*return_tuples)); pgassert(*return_count == 0); - std::vector < int64_t > roots(rootsArr, rootsArr + size_rootsArr); - - std::vector < MST_rt > results; + auto roots = get_intArray(starts, false); + std::vector results; - graphType gType = directed ? DIRECTED : UNDIRECTED; + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + hint = nullptr; - if (directed) { - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); - - results = pgr_depthFirstSearch( - digraph, - roots, - directed, - max_depth); + if (edges.empty()) { + results = pgrouting::details::get_no_edge_graph_result(roots); + *notice_msg = pgr_msg("No edges found"); + *log_msg = pgr_msg(edges_sql); } else { - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + if (directed) { + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); results = pgr_depthFirstSearch( - undigraph, + digraph, roots, directed, max_depth); + } else { + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); + + results = pgr_depthFirstSearch( + undigraph, + roots, + directed, + max_depth); + } } auto count = results.size(); @@ -190,6 +172,9 @@ do_pgr_depthFirstSearch( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/trsp/CMakeLists.txt b/src/trsp/CMakeLists.txt index 533f3e2ed6f..981520e675e 100644 --- a/src/trsp/CMakeLists.txt +++ b/src/trsp/CMakeLists.txt @@ -1,14 +1,14 @@ add_library(trsp OBJECT # keeping these for backwards compatibility - trsp.c - trsp_core.cpp + trsp_deprecated.c + trsp_deprecated_driver.cpp GraphDefinition.cpp - - - new_trsp.c edgeInfo.cpp - pgr_trspHandler.cpp + trspHandler.cpp + + trsp.c trsp_driver.cpp + trsp_withPoints.c trsp_withPoints_driver.cpp diff --git a/src/trsp/GraphDefinition.cpp b/src/trsp/GraphDefinition.cpp index c29bc2932c2..8c3847ac3e7 100644 --- a/src/trsp/GraphDefinition.cpp +++ b/src/trsp/GraphDefinition.cpp @@ -1,5 +1,4 @@ /*PGR-GNU***************************************************************** - File: GraphDefinition.cpp Copyright (c) 2015 pgRouting developers @@ -23,14 +22,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "trsp/GraphDefinition.h" +#include "trsp/GraphDefinition.hpp" #include #include #include #include -#include "c_types/edge_t.h" +#include "c_types/edge_rt.h" // ------------------------------------------------------------------------- GraphDefinition::GraphDefinition(void) { diff --git a/src/trsp/edgeInfo.cpp b/src/trsp/edgeInfo.cpp index 1249ea36fe8..2ac944fe8ca 100644 --- a/src/trsp/edgeInfo.cpp +++ b/src/trsp/edgeInfo.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: edgeInfo.cpp +File: edgeInfo.cpp Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org @@ -23,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "trsp/edgeInfo.h" +#include "trsp/edgeInfo.hpp" namespace pgrouting { diff --git a/src/trsp/new_trsp.c b/src/trsp/new_trsp.c deleted file mode 100644 index 096e7059910..00000000000 --- a/src/trsp/new_trsp.c +++ /dev/null @@ -1,416 +0,0 @@ -/*PGR-GNU***************************************************************** - -File: new_trsp.c - -Copyright (c) 2017 pgRouting developers -Mail: project@pgrouting.org -Copyright (c) 2017 Vicky Vergara -Mail: vicky at georepublic.de - - ------- - -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 "drivers/trsp/trsp_driver.h" - -#include "c_common/debug_macro.h" -#include "c_common/e_report.h" -#include "c_common/time_msg.h" - -#include "c_types/edge_t.h" -#include "c_types/restriction_t.h" -#include "c_types/path_rt.h" - -#include "c_common/pgdata_getters.h" - -PGDLLEXPORT Datum _pgr_trspv4(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(_pgr_trspv4); - -PGDLLEXPORT Datum _trsp(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(_trsp); - -PGDLLEXPORT Datum _v4trsp(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(_v4trsp); - - -static -void process( - char* edges_sql, - char* restrictions_sql, - char* combinations_sql, - - ArrayType *starts, - ArrayType *ends, - - bool directed, - - Path_rt **result_tuples, - size_t *result_count) { - pgr_SPI_connect(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; - - size_t size_start_vidsArr = 0; - int64_t* start_vidsArr = NULL; - - size_t size_end_vidsArr = 0; - int64_t* end_vidsArr = NULL; - - II_t_rt *combinations = NULL; - size_t total_combinations = 0; - - Edge_t *edges = NULL; - size_t total_edges = 0; - - Restriction_t * restrictions = NULL; - size_t total_restrictions = 0; - pgr_get_edges(edges_sql, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (total_edges == 0) { - pgr_SPI_finish(); - return; - } - pgr_get_restrictions(restrictions_sql, &restrictions, &total_restrictions, &err_msg); - throw_error(err_msg, restrictions_sql); - - if (starts && ends) { - start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_vidsArr = pgr_get_bigIntArray(&size_end_vidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - } - - clock_t start_t = clock(); - - do_trsp( - edges, total_edges, - restrictions, total_restrictions, - - combinations, total_combinations, - start_vidsArr, size_start_vidsArr, - end_vidsArr, size_end_vidsArr, - - directed, - - result_tuples, result_count, - &log_msg, - ¬ice_msg, - &err_msg); - time_msg("processing pgr_trsp", 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 (edges) {pfree(edges); edges=NULL;} - if (restrictions) {pfree(restrictions); restrictions=NULL;} - if (combinations) {pfree(combinations); combinations=NULL;} - if (start_vidsArr) {pfree(start_vidsArr); start_vidsArr=NULL;} - if (end_vidsArr) {pfree(end_vidsArr); end_vidsArr=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_trspv4(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tuple_desc; - - size_t result_count = 0; - Path_rt *result_tuples = NULL; - - if (SRF_IS_FIRSTCALL()) { - MemoryContext oldcontext; - funcctx = SRF_FIRSTCALL_INIT(); - oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - if (PG_NARGS() == 5) { - process( - text_to_cstring(PG_GETARG_TEXT_P(0)), - text_to_cstring(PG_GETARG_TEXT_P(1)), - NULL, - PG_GETARG_ARRAYTYPE_P(2), - PG_GETARG_ARRAYTYPE_P(3), - PG_GETARG_BOOL(4), - &result_tuples, &result_count); - } else /* (PG_NARGS() == 4) */ { - process( - text_to_cstring(PG_GETARG_TEXT_P(0)), - text_to_cstring(PG_GETARG_TEXT_P(1)), - text_to_cstring(PG_GETARG_TEXT_P(2)), - NULL, - NULL, - PG_GETARG_BOOL(3), - &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 = (Path_rt *) 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 = 8; - values = palloc(numb * sizeof(Datum)); - nulls = palloc(numb * sizeof(bool)); - - size_t i; - for (i = 0; i < numb; ++i) { - nulls[i] = false; - } - - int path_id = call_cntr == 0? 0 : result_tuples[call_cntr - 1].seq; - path_id += result_tuples[call_cntr].seq == 1? 1 : 0; - - values[0] = Int32GetDatum((int32_t)call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[call_cntr].seq); - values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); - values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); - values[4] = Int64GetDatum(result_tuples[call_cntr].node); - values[5] = Int64GetDatum(result_tuples[call_cntr].edge); - values[6] = Float8GetDatum(result_tuples[call_cntr].cost); - values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); - - result_tuples[call_cntr].seq = path_id; - - tuple = heap_form_tuple(tuple_desc, values, nulls); - - result = HeapTupleGetDatum(tuple); - - pfree(values); - pfree(nulls); - - SRF_RETURN_NEXT(funcctx, result); - } else { - SRF_RETURN_DONE(funcctx); - } -} - - -PGDLLEXPORT Datum -_v4trsp(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tuple_desc; - - size_t result_count = 0; - Path_rt *result_tuples = NULL; - - if (SRF_IS_FIRSTCALL()) { - MemoryContext oldcontext; - funcctx = SRF_FIRSTCALL_INIT(); - oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - if (PG_NARGS() == 5) { - process( - text_to_cstring(PG_GETARG_TEXT_P(0)), - text_to_cstring(PG_GETARG_TEXT_P(1)), - NULL, - PG_GETARG_ARRAYTYPE_P(2), - PG_GETARG_ARRAYTYPE_P(3), - PG_GETARG_BOOL(4), - &result_tuples, &result_count); - } else /* (PG_NARGS() == 4) */ { - process( - text_to_cstring(PG_GETARG_TEXT_P(0)), - text_to_cstring(PG_GETARG_TEXT_P(1)), - text_to_cstring(PG_GETARG_TEXT_P(2)), - NULL, - NULL, - PG_GETARG_BOOL(3), - &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 = (Path_rt *) 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 = 8; - values = palloc(numb * sizeof(Datum)); - nulls = palloc(numb * sizeof(bool)); - - size_t i; - for (i = 0; i < numb; ++i) { - nulls[i] = false; - } - - int path_id = call_cntr == 0? 0 : result_tuples[call_cntr - 1].seq; - path_id += result_tuples[call_cntr].seq == 1? 1 : 0; - - values[0] = Int32GetDatum((int32_t)call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[call_cntr].seq); - values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); - values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); - values[4] = Int64GetDatum(result_tuples[call_cntr].node); - values[5] = Int64GetDatum(result_tuples[call_cntr].edge); - values[6] = Float8GetDatum(result_tuples[call_cntr].cost); - values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); - - result_tuples[call_cntr].seq = path_id; - - tuple = heap_form_tuple(tuple_desc, values, nulls); - - result = HeapTupleGetDatum(tuple); - - pfree(values); - pfree(nulls); - - SRF_RETURN_NEXT(funcctx, result); - } else { - SRF_RETURN_DONE(funcctx); - } -} - -PGDLLEXPORT Datum -_trsp(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tuple_desc; - - size_t result_count = 0; - Path_rt *result_tuples = NULL; - - 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)), - NULL, - PG_GETARG_ARRAYTYPE_P(2), - PG_GETARG_ARRAYTYPE_P(3), - PG_GETARG_BOOL(4), - &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 = (Path_rt *) 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 = 8; - values = palloc(numb * sizeof(Datum)); - nulls = palloc(numb * sizeof(bool)); - - size_t i; - for (i = 0; i < numb; ++i) { - nulls[i] = false; - } - - values[0] = Int64GetDatum((int64_t)call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[call_cntr].seq); - values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); - values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); - values[4] = Int64GetDatum(result_tuples[call_cntr].node); - values[5] = Int64GetDatum(result_tuples[call_cntr].edge); - values[6] = Float8GetDatum(result_tuples[call_cntr].cost); - values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); - - tuple = heap_form_tuple(tuple_desc, values, nulls); - - result = HeapTupleGetDatum(tuple); - - pfree(values); - pfree(nulls); - - SRF_RETURN_NEXT(funcctx, result); - } else { - SRF_RETURN_DONE(funcctx); - } -} diff --git a/src/trsp/trsp.c b/src/trsp/trsp.c index ebcfb6860f6..8a221bd575a 100644 --- a/src/trsp/trsp.c +++ b/src/trsp/trsp.c @@ -1,10 +1,11 @@ /*PGR-GNU***************************************************************** +File: new_trsp.c -File: trsp.c - -Generated with Template by: -Copyright (c) 2013 pgRouting developers +Copyright (c) 2017 pgRouting developers Mail: project@pgrouting.org +Copyright (c) 2017 Vicky Vergara +Mail: vicky at georepublic.de + ------ @@ -24,382 +25,202 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ - +#include #include "c_common/postgres_connection.h" -#include "catalog/pg_type.h" + +#include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" +#include "c_common/time_msg.h" +#include "drivers/trsp/trsp_driver.h" +PGDLLEXPORT Datum _pgr_trspv4(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_trspv4); -#include "c_types/trsp/trsp.h" -#include "c_types/edge_t.h" - -#include "c_common/pgdata_getters.h" - -#include "trsp/trsp_core.h" -typedef struct restrict_t restrict_t; -typedef struct Edge_t Edge_t; -typedef struct path_element_tt path_element_tt; - -PGDLLEXPORT Datum _pgr_trsp(PG_FUNCTION_ARGS); - - -typedef struct edge_columns { - int id; - int source; - int target; - int cost; - int reverse_cost; -} edge_columns_t; - -typedef struct restrict_columns { - int target_id; - int via_path; - int to_cost; -} restrict_columns_t; - - -/* - * This function fetches the resturction columns from an SPITupleTable.. - * -*/ -static int -fetch_restrict_columns(SPITupleTable *tuptable, - restrict_columns_t *restrict_columns) { - restrict_columns->target_id = SPI_fnumber(tuptable->tupdesc, "target_id"); - restrict_columns->via_path = SPI_fnumber(tuptable->tupdesc, "via_path"); - restrict_columns->to_cost = SPI_fnumber(tuptable->tupdesc, "to_cost"); - if (restrict_columns->target_id == SPI_ERROR_NOATTRIBUTE || - restrict_columns->via_path == SPI_ERROR_NOATTRIBUTE || - restrict_columns->to_cost == SPI_ERROR_NOATTRIBUTE) { - elog(ERROR, "Error, restriction query must return columns " - "'target_id', 'via_path' and 'to_cost'"); - return -1; - } - - if (SPI_gettypeid(tuptable->tupdesc, - restrict_columns->target_id) != INT4OID || - SPI_gettypeid(tuptable->tupdesc, restrict_columns->via_path) != TEXTOID || - SPI_gettypeid(tuptable->tupdesc, restrict_columns->to_cost) != FLOAT8OID) { - elog(ERROR, "Error, restriction columns 'target_id' must be of type int4," - "'via_path' must be of type text, 'to_cost' must be of type float8"); - return -1; - } - - return 0; -} +PGDLLEXPORT Datum _trsp(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_trsp); +PGDLLEXPORT Datum _v4trsp(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_v4trsp); -/* - * To fetch a edge from Tuple. - * - */ - -static void -fetch_restrict(HeapTuple *tuple, TupleDesc *tupdesc, - restrict_columns_t *restrict_columns, restrict_t *rest) { - Datum binval; - bool isnull; - int t; - - for (t = 0; t < MAX_RULE_LENGTH; ++t) - rest->via[t] = -1; - - binval = SPI_getbinval(*tuple, *tupdesc, restrict_columns->target_id, - &isnull); - if (isnull) - elog(ERROR, "target_id contains a null value"); - rest->target_id = DatumGetInt32(binval); - - binval = SPI_getbinval(*tuple, *tupdesc, restrict_columns->to_cost, &isnull); - if (isnull) - elog(ERROR, "to_cost contains a null value"); - rest->to_cost = DatumGetFloat8(binval); - char *str = SPI_getvalue(*tuple, *tupdesc, restrict_columns->via_path); - - // PGR_DBG("restriction: %f, %i, %s", rest->to_cost, rest->target_id, str); - - if (str != NULL) { - int ci = 0; - char* pch = (char *)strtok(str, " ,"); - - while (pch != NULL && ci < MAX_RULE_LENGTH) { - rest->via[ci] = atoi(pch); - // PGR_DBG(" rest->via[%i]=%i", ci, rest->via[ci]); - ci++; - pch = (char *)strtok(NULL, " ,"); - } - } -} +static +void process( + char* edges_sql, + char* restrictions_sql, + char* combinations_sql, + ArrayType *starts, + ArrayType *ends, -static int compute_trsp( - char* edges_sql, - int dovertex, - int64_t start_id, - double start_pos, - int64_t end_id, - double end_pos, bool directed, - bool has_reverse_cost, - char* restrict_sql, - path_element_tt **path, - size_t *path_count) { - pgr_SPI_connect(); + + Path_rt **result_tuples, + size_t *result_count) { + pgr_SPI_connect(); + char* log_msg = NULL; + char* notice_msg = NULL; char* err_msg = NULL; - SPIPlanPtr SPIplan; - Portal SPIportal; - - Edge_t *edges = NULL; - size_t total_tuples = 0; - pgr_get_edges(edges_sql, &edges, &total_tuples, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - // defining min and max vertex id - int64_t v_max_id = 0; - int64_t v_min_id = INT_MAX; - - size_t z; - for (z = 0; z < total_tuples; z++) { - PGR_DBG("id %ld source %ld target %ld cost %f rev %f", - edges[z].id, edges[z].source, edges[z].target, edges[z].cost, edges[z].reverse_cost); - if (edges[z].source < v_min_id) - v_min_id = edges[z].source; - - if (edges[z].source > v_max_id) - v_max_id = edges[z].source; - - if (edges[z].target < v_min_id) - v_min_id = edges[z].target; - - if (edges[z].target > v_max_id) - v_max_id = edges[z].target; - } - - // :::::::::::::::::::::::::::::::::::: - // :: reducing vertex id (renumbering) - // :::::::::::::::::::::::::::::::::::: - /* track if start and end are both in edge tuples */ - int s_count = 0; - int t_count = 0; - for (z = 0; z < total_tuples; z++) { - // check if edges[] contains source and target - if (dovertex) { - if (edges[z].source == start_id || edges[z].target == start_id) - ++s_count; - if (edges[z].source == end_id || edges[z].target == end_id) - ++t_count; - } else { - if (edges[z].id == start_id) - ++s_count; - if (edges[z].id == end_id) - ++t_count; + clock_t start_t = clock(); + pgr_do_trsp( + edges_sql, + restrictions_sql, + combinations_sql, + starts, ends, + + directed, + + result_tuples, result_count, + &log_msg, + ¬ice_msg, + &err_msg); + time_msg("processing pgr_trsp", start_t, clock()); + + if (err_msg && (*result_tuples)) { + pfree(*result_tuples); + (*result_tuples) = NULL; + (*result_count) = 0; } - edges[z].source -= v_min_id; - edges[z].target -= v_min_id; - } - - PGR_DBG("Min vertex id: %ld , Max vid: %ld", v_min_id, v_max_id); - PGR_DBG("Total %ld edge tuples", total_tuples); - - if (s_count == 0) { - elog(ERROR, "Start id was not found."); - return -1; - } - - if (t_count == 0) { - elog(ERROR, "Target id was not found."); - return -1; - } - - if (dovertex) { - start_id -= v_min_id; - end_id -= v_min_id; - } - - PGR_DBG("Fetching restriction tuples\n"); - restrict_t *restricts = NULL; - uint64_t total_restrict_tuples = 0; - restrict_columns_t restrict_columns = {.target_id = -1, .via_path = -1, - .to_cost = -1}; - - int ret = -1; - - if (restrict_sql == NULL) { - PGR_DBG("Sql for restrictions is null."); - } else { - int64 TUPLIMIT = 1000; - - SPIplan = SPI_prepare(restrict_sql, 0, NULL); - if (SPIplan == NULL) { - elog(ERROR, "turn_restrict_shortest_path: " - "couldn't create query plan via SPI"); - return -1; - } - - if ((SPIportal = SPI_cursor_open(NULL, SPIplan, NULL, NULL, true)) \ - == NULL) { - elog(ERROR, "turn_restrict_shortest_path:" - " SPI_cursor_open('%s') returns NULL", restrict_sql); - return -1; - } - - bool moredata = true; - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, TUPLIMIT); - - if (restrict_columns.target_id == -1) { - if (fetch_restrict_columns(SPI_tuptable, &restrict_columns) \ - == -1) { - PGR_DBG("fetch_restrict_columns failed!"); - pgr_SPI_finish(); - return -1; - } - } - - /* Suppress the -Wconversion warning temporarily */ - uint64_t ntuples = SPI_processed; - - total_restrict_tuples += ntuples; - - if (ntuples > 0) { - if (!restricts) - restricts = palloc(total_restrict_tuples * sizeof(restrict_t)); - else - restricts = repalloc(restricts, - total_restrict_tuples * sizeof(restrict_t)); - - if (restricts == NULL) { - pgr_SPI_finish(); - elog(ERROR, "Out of memory"); - return -1; - } - - uint32_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_restrict(&tuple, &tupdesc, &restrict_columns, - &restricts[total_restrict_tuples - ntuples + t]); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - SPI_cursor_close(SPIportal); - } - - PGR_DBG("Total %ld restriction tuples", total_restrict_tuples); - - PGR_DBG("Calling trsp_edge_wrapper\n"); - ret = trsp_edge_wrapper(edges, total_tuples, - restricts, total_restrict_tuples, - start_id, start_pos, end_id, end_pos, - directed, has_reverse_cost, - path, path_count, &err_msg); - - PGR_DBG("Message received from inside:"); - PGR_DBG("%s", err_msg); - - - // :::::::::::::::::::::::::::::::: - // :: restoring original vertex id - // :::::::::::::::::::::::::::::::: - for (z = 0; z < *path_count; z++) { - if (z || (*path)[z].vertex_id != -1) - (*path)[z].vertex_id += v_min_id; - } - - PGR_DBG("ret = %i\n", ret); - - PGR_DBG("*path_count = %ld\n", *path_count); - - if (ret < 0) { - ereport(ERROR, (errcode(ERRCODE_E_R_E_CONTAINING_SQL_NOT_PERMITTED), - errmsg("Error computing path: %s", err_msg))); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); + + pgr_SPI_finish(); +} + + +PGDLLEXPORT Datum +_pgr_trspv4(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + + size_t result_count = 0; + Path_rt *result_tuples = NULL; + + if (SRF_IS_FIRSTCALL()) { + MemoryContext oldcontext; + funcctx = SRF_FIRSTCALL_INIT(); + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + + if (PG_NARGS() == 5) { + process( + text_to_cstring(PG_GETARG_TEXT_P(0)), + text_to_cstring(PG_GETARG_TEXT_P(1)), + NULL, + PG_GETARG_ARRAYTYPE_P(2), + PG_GETARG_ARRAYTYPE_P(3), + PG_GETARG_BOOL(4), + &result_tuples, &result_count); + } else /* (PG_NARGS() == 4) */ { + process( + text_to_cstring(PG_GETARG_TEXT_P(0)), + text_to_cstring(PG_GETARG_TEXT_P(1)), + text_to_cstring(PG_GETARG_TEXT_P(2)), + NULL, + NULL, + PG_GETARG_BOOL(3), + &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); } - pgr_SPI_finish(); - return 0; + funcctx = SRF_PERCALL_SETUP(); + + tuple_desc = funcctx->tuple_desc; + result_tuples = (Path_rt *) 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 = 8; + values = palloc(numb * sizeof(Datum)); + nulls = palloc(numb * sizeof(bool)); + + size_t i; + for (i = 0; i < numb; ++i) { + nulls[i] = false; + } + + int64_t path_seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; + + values[0] = Int32GetDatum((int32_t)call_cntr + 1); + values[1] = Int32GetDatum((int32_t)path_seq); + values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); + values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); + values[4] = Int64GetDatum(result_tuples[call_cntr].node); + values[5] = Int64GetDatum(result_tuples[call_cntr].edge); + values[6] = Float8GetDatum(result_tuples[call_cntr].cost); + values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); + + result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : path_seq + 1; + + tuple = heap_form_tuple(tuple_desc, values, nulls); + + result = HeapTupleGetDatum(tuple); + + pfree(values); + pfree(nulls); + + SRF_RETURN_NEXT(funcctx, result); + } else { + SRF_RETURN_DONE(funcctx); + } } -PG_FUNCTION_INFO_V1(_pgr_trsp); PGDLLEXPORT Datum -_pgr_trsp(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tuple_desc; - path_element_tt *path; - - // stuff done only on the first call of the function - if (SRF_IS_FIRSTCALL()) { - MemoryContext oldcontext; - size_t path_count = 0; - int i; - double s_pos; - double e_pos; - char * sql; - - // create a function context for cross-call persistence - funcctx = SRF_FIRSTCALL_INIT(); - - // switch to memory context appropriate for multiple function calls - oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - // verify that the first 5 args are not NULL - for (i = 0; i < 7; i++) { - if (i == 2 || i == 4) continue; - if (PG_ARGISNULL(i)) { - elog(ERROR, "turn_restrict_shortest_path(): " - "Argument %i may not be NULL", i+1); +_v4trsp(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + + size_t result_count = 0; + Path_rt *result_tuples = NULL; + + if (SRF_IS_FIRSTCALL()) { + MemoryContext oldcontext; + funcctx = SRF_FIRSTCALL_INIT(); + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + + if (PG_NARGS() == 5) { + process( + text_to_cstring(PG_GETARG_TEXT_P(0)), + text_to_cstring(PG_GETARG_TEXT_P(1)), + NULL, + PG_GETARG_ARRAYTYPE_P(2), + PG_GETARG_ARRAYTYPE_P(3), + PG_GETARG_BOOL(4), + &result_tuples, &result_count); + } else /* (PG_NARGS() == 4) */ { + process( + text_to_cstring(PG_GETARG_TEXT_P(0)), + text_to_cstring(PG_GETARG_TEXT_P(1)), + text_to_cstring(PG_GETARG_TEXT_P(2)), + NULL, + NULL, + PG_GETARG_BOOL(3), + &result_tuples, &result_count); } - } - - if (PG_ARGISNULL(2)) { - s_pos = 0.5; - } else { - s_pos = PG_GETARG_FLOAT8(2); - if (s_pos < 0.0) s_pos = 0.5; - if (s_pos > 1.0) s_pos = 0.5; - } - - if (PG_ARGISNULL(4)) { - e_pos = 0.5; - } else { - e_pos = PG_GETARG_FLOAT8(4); - if (e_pos < 0.0) e_pos = 0.5; - if (e_pos > 1.0) e_pos = 0.5; - } - - if (PG_ARGISNULL(7)) { - sql = NULL; - } else { - sql = text_to_cstring(PG_GETARG_TEXT_P(7)); - } - - PGR_DBG("Calling compute_trsp"); - - compute_trsp(text_to_cstring(PG_GETARG_TEXT_P(0)), - 0, // sdo edge - PG_GETARG_INT32(1), - s_pos, - PG_GETARG_INT32(3), - e_pos, - PG_GETARG_BOOL(5), - PG_GETARG_BOOL(6), - sql, - &path, &path_count); - - // total number of tuples to be returned - funcctx->max_calls = path_count; - - funcctx->user_fctx = path; + + funcctx->max_calls = result_count; + funcctx->user_fctx = result_tuples; + if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) { ereport(ERROR, @@ -408,49 +229,137 @@ _pgr_trsp(PG_FUNCTION_ARGS) { "that cannot accept type record"))); } - funcctx->tuple_desc = tuple_desc; + funcctx->tuple_desc = tuple_desc; + MemoryContextSwitchTo(oldcontext); + } + + funcctx = SRF_PERCALL_SETUP(); + + tuple_desc = funcctx->tuple_desc; + result_tuples = (Path_rt *) 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 = 8; + values = palloc(numb * sizeof(Datum)); + nulls = palloc(numb * sizeof(bool)); + + size_t i; + for (i = 0; i < numb; ++i) { + nulls[i] = false; + } + + int64_t path_seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; + + values[0] = Int32GetDatum((int32_t)call_cntr + 1); + values[1] = Int32GetDatum((int32_t)path_seq); + values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); + values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); + values[4] = Int64GetDatum(result_tuples[call_cntr].node); + values[5] = Int64GetDatum(result_tuples[call_cntr].edge); + values[6] = Float8GetDatum(result_tuples[call_cntr].cost); + values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); + + result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : path_seq + 1; - MemoryContextSwitchTo(oldcontext); + tuple = heap_form_tuple(tuple_desc, values, nulls); + + result = HeapTupleGetDatum(tuple); + + pfree(values); + pfree(nulls); + + SRF_RETURN_NEXT(funcctx, result); + } else { + SRF_RETURN_DONE(funcctx); } +} - // stuff done on every call of the function - funcctx = SRF_PERCALL_SETUP(); - - tuple_desc = funcctx->tuple_desc; - path = (path_element_tt*) funcctx->user_fctx; - - if (funcctx->call_cntr < funcctx->max_calls) { - // do when there is more left to send - HeapTuple tuple; - Datum result; - Datum *values; - bool* nulls; - - values = palloc(4 * sizeof(Datum)); - nulls = palloc(4 * sizeof(char)); - - values[0] = Int64GetDatum((int64_t)funcctx->call_cntr); - nulls[0] = false; - values[1] = Int32GetDatum((int32_t)path[funcctx->call_cntr].vertex_id); - nulls[1] = false; - values[2] = Int32GetDatum((int32_t)path[funcctx->call_cntr].edge_id); - nulls[2] = false; - values[3] = Float8GetDatum(path[funcctx->call_cntr].cost); - nulls[3] = false; - - tuple = heap_form_tuple(tuple_desc, values, nulls); - - // make the tuple into a datum - result = HeapTupleGetDatum(tuple); - - // clean up (this is not really necessary) - pfree(values); - pfree(nulls); - - SRF_RETURN_NEXT(funcctx, result); - } else { // do when there is no more left - PGR_DBG("Going to free path"); - if (path) free(path); - SRF_RETURN_DONE(funcctx); +PGDLLEXPORT Datum +_trsp(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + + size_t result_count = 0; + Path_rt *result_tuples = NULL; + + 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)), + NULL, + PG_GETARG_ARRAYTYPE_P(2), + PG_GETARG_ARRAYTYPE_P(3), + PG_GETARG_BOOL(4), + &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 = (Path_rt *) 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 = 8; + values = palloc(numb * sizeof(Datum)); + nulls = palloc(numb * sizeof(bool)); + + size_t i; + for (i = 0; i < numb; ++i) { + nulls[i] = false; + } + + int64_t path_seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; + + values[0] = Int32GetDatum((int32_t)call_cntr + 1); + values[1] = Int32GetDatum((int32_t)path_seq); + values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); + values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); + values[4] = Int64GetDatum(result_tuples[call_cntr].node); + values[5] = Int64GetDatum(result_tuples[call_cntr].edge); + values[6] = Float8GetDatum(result_tuples[call_cntr].cost); + values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); + + result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : path_seq + 1; + + tuple = heap_form_tuple(tuple_desc, values, nulls); + result = HeapTupleGetDatum(tuple); + + pfree(values); + pfree(nulls); + + SRF_RETURN_NEXT(funcctx, result); + } else { + SRF_RETURN_DONE(funcctx); } } diff --git a/src/trsp/pgr_trspHandler.cpp b/src/trsp/trspHandler.cpp similarity index 87% rename from src/trsp/pgr_trspHandler.cpp rename to src/trsp/trspHandler.cpp index f4c6085739f..29963e5407b 100644 --- a/src/trsp/pgr_trspHandler.cpp +++ b/src/trsp/trspHandler.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -File: pgr_trspHandler.cpp +File: trspHandler.cpp Copyright (c) 2011 pgRouting developers Mail: project@pgrouting.org @@ -25,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "trsp/pgr_trspHandler.h" +#include "trsp/trspHandler.hpp" #include #include @@ -38,12 +37,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "cpp_common/basePath_SSEC.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" namespace pgrouting { namespace trsp { // ------------------------------------------------------------------------- +Pgr_trspHandler::Pgr_trspHandler( + std::vector &edges, + const bool directed, + const std::vector &ruleList) : + m_ruleTable() { + initialize_restrictions(ruleList); + + renumber_edges(edges); + for (const auto& id : m_id_to_idx) { + m_idx_to_id[id.second] = id.first; + } + + construct_graph(edges, directed); +} + Pgr_trspHandler::Pgr_trspHandler( Edge_t *edges, const size_t edge_count, @@ -63,6 +77,29 @@ Pgr_trspHandler::Pgr_trspHandler( directed); } +Pgr_trspHandler::Pgr_trspHandler( + std::vector &edges, + const std::vector &new_edges, + const bool directed, + const std::vector &ruleList) : + m_ruleTable() { + initialize_restrictions(ruleList); + + auto point_edges = new_edges; + renumber_edges(edges, point_edges); + + for (const auto& id : m_id_to_idx) { + m_idx_to_id[id.second] = id.first; + } + + construct_graph( + edges, + directed); + add_point_edges( + point_edges, + directed); +} + Pgr_trspHandler::Pgr_trspHandler( Edge_t *edges, const size_t edge_count, @@ -91,6 +128,23 @@ Pgr_trspHandler::Pgr_trspHandler( // ------------------------------------------------------------------------- +void +Pgr_trspHandler::renumber_edges(std::vector &edges) { + int64_t idx(0); + for (auto &e : edges) { + if (m_id_to_idx.find(e.source) == m_id_to_idx.end()) { + m_id_to_idx[e.source] = idx; + ++idx; + } + if (m_id_to_idx.find(e.target) == m_id_to_idx.end()) { + m_id_to_idx[e.target] = idx; + ++idx; + } + e.source = m_id_to_idx.at(e.source); + e.target = m_id_to_idx.at(e.target); + } +} + void Pgr_trspHandler::renumber_edges( Edge_t *edges, @@ -110,6 +164,37 @@ Pgr_trspHandler::renumber_edges( } } +void +Pgr_trspHandler::renumber_edges( + std::vector &edges, + std::vector &new_edges) { + int64_t idx(0); + for (auto &e : edges) { + if (m_id_to_idx.find(e.source) == m_id_to_idx.end()) { + m_id_to_idx[e.source] = idx; + ++idx; + } + if (m_id_to_idx.find(e.target) == m_id_to_idx.end()) { + m_id_to_idx[e.target] = idx; + ++idx; + } + e.source = m_id_to_idx.at(e.source); + e.target = m_id_to_idx.at(e.target); + } + for (auto &e : new_edges) { + if (m_id_to_idx.find(e.source) == m_id_to_idx.end()) { + m_id_to_idx[e.source] = idx; + ++idx; + } + if (m_id_to_idx.find(e.target) == m_id_to_idx.end()) { + m_id_to_idx[e.target] = idx; + ++idx; + } + e.source = m_id_to_idx.at(e.source); + e.target = m_id_to_idx.at(e.target); + } +} + void Pgr_trspHandler::renumber_edges( Edge_t *edges, @@ -158,7 +243,7 @@ double Pgr_trspHandler::construct_path(int64_t ed_id, Position pos) { pgassert(pos != ILLEGAL); if (m_parent[static_cast(ed_id)].isIllegal(pos)) { - Path_t pelement; + Path_t pelement = {}; auto cur_edge = &m_edges[static_cast(ed_id)]; if (pos == RC_EDGE) { pelement.node = cur_edge->startNode(); @@ -177,7 +262,7 @@ double Pgr_trspHandler::construct_path(int64_t ed_id, Position pos) { double ret = construct_path( static_cast(m_parent[static_cast(ed_id)].e_idx[static_cast(pos)]), static_cast(m_parent[static_cast(ed_id)].v_pos[static_cast(pos)])); - Path_t pelement; + Path_t pelement = {}; auto cur_edge = &m_edges[static_cast(ed_id)]; if (pos == RC_EDGE) { pelement.node = cur_edge->startNode(); @@ -497,7 +582,7 @@ Pgr_trspHandler::process_trsp( construct_path(static_cast(cur_edge.idx()), RC_EDGE); } - Path_t pelement; + Path_t pelement = {}; pelement.node = m_end_vertex; pelement.edge = -1; pelement.cost = 0.0; @@ -512,6 +597,15 @@ Pgr_trspHandler::process_trsp( // ------------------------------------------------------------------------- +void Pgr_trspHandler::construct_graph( + const std::vector &edges, + const bool directed) { + for (const auto &e : edges) { + addEdge(e, directed); + } + m_mapEdgeId2Index.clear(); +} + void Pgr_trspHandler::construct_graph( Edge_t* edges, const size_t edge_count, @@ -594,19 +688,6 @@ bool Pgr_trspHandler::addEdge(Edge_t edgeIn, bool directed) { } } -#if 0 - /* - * The edge was already inserted - * - * If the user has rows with repeated edge id, the subsequent edges will be ignored - * - * When changing to boost graph, the additional edges are to be added - */ - - if (m_mapEdgeId2Index.find(edgeIn.id) != m_mapEdgeId2Index.end()) { - return false; - } -#endif /* * the index of this new edge in the edges container is @@ -614,13 +695,6 @@ bool Pgr_trspHandler::addEdge(Edge_t edgeIn, bool directed) { */ EdgeInfo edge(edgeIn, m_edges.size()); -#if 0 - // Adding edge to the list - m_mapEdgeId2Index.insert( - std::make_pair( - edge.edgeID(), - m_edges.size())); -#endif m_edges.push_back(edge); diff --git a/src/trsp/trspVia.c b/src/trsp/trspVia.c index cd00eb5d009..c451474565e 100644 --- a/src/trsp/trspVia.c +++ b/src/trsp/trspVia.c @@ -31,7 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/trsp/trspVia_driver.h" PGDLLEXPORT Datum _pgr_trspvia(PG_FUNCTION_ARGS); @@ -42,7 +41,7 @@ void process( char* edges_sql, char* restrictions_sql, - ArrayType *via_arr, + ArrayType *vias, bool directed, bool strict, bool U_turn_on_edge, @@ -53,32 +52,11 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - size_t size_via = 0; - int64_t* via = pgr_get_bigIntArray(&size_via, via_arr, false, &err_msg); - throw_error(err_msg, "While getting via vertices"); - - Edge_t* edges = NULL; - size_t size_edges = 0; - pgr_get_edges(edges_sql, &edges, &size_edges, true, false, &err_msg); - throw_error(err_msg, edges_sql); - - if (size_edges == 0) { - if (via) pfree(via); - pgr_SPI_finish(); - return; - } - - Restriction_t * restrictions = NULL; - size_t size_restrictions = 0; - - pgr_get_restrictions(restrictions_sql, &restrictions, &size_restrictions, &err_msg); - throw_error(err_msg, restrictions_sql); - clock_t start_t = clock(); - do_trspVia( - edges, size_edges, - restrictions, size_restrictions, - via, size_via, + pgr_do_trspVia( + edges_sql, + restrictions_sql, + vias, directed, strict, U_turn_on_edge, @@ -95,14 +73,8 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - 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;} - if (edges) {pfree(edges); edges = NULL;} - if (via) {pfree(via); via = NULL;} - if (restrictions) {pfree(restrictions); restrictions = NULL;} pgr_SPI_finish(); } @@ -112,25 +84,14 @@ _pgr_trspvia(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); - - /********************************************************************** - * pgr_trspVia(edges_sql text, - * vertices anyarray, - * directed boolean default true, - * strict boolean default false, - * U_turn_on_edge boolean default false, - **********************************************************************/ - process( text_to_cstring(PG_GETARG_TEXT_P(0)), text_to_cstring(PG_GETARG_TEXT_P(1)), @@ -141,8 +102,6 @@ _pgr_trspvia(PG_FUNCTION_ARGS) { &result_tuples, &result_count); - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -168,20 +127,6 @@ _pgr_trspvia(PG_FUNCTION_ARGS) { bool* nulls; size_t call_cntr = funcctx->call_cntr; - /**********************************************************************/ - /* - 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 - */ - size_t numb_out = 10; values = palloc(numb_out * sizeof(Datum)); nulls = palloc(numb_out * sizeof(bool)); @@ -190,7 +135,6 @@ _pgr_trspvia(PG_FUNCTION_ARGS) { nulls[i] = false; } - // postgres starts counting from 1 values[0] = Int32GetDatum((int32_t)call_cntr + 1); values[1] = Int32GetDatum(result_tuples[call_cntr].path_id); values[2] = Int32GetDatum(result_tuples[call_cntr].path_seq + 1); @@ -202,8 +146,6 @@ _pgr_trspvia(PG_FUNCTION_ARGS) { 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); diff --git a/src/trsp/trspVia_driver.cpp b/src/trsp/trspVia_driver.cpp index 7fdd628df50..9c5a0cf39b2 100644 --- a/src/trsp/trspVia_driver.cpp +++ b/src/trsp/trspVia_driver.cpp @@ -31,16 +31,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "dijkstra/pgr_dijkstraVia.hpp" +#include "dijkstra/dijkstraVia.hpp" #include "c_types/routes_t.h" -#include "c_types/restriction_t.h" +#include "cpp_common/restriction_t.hpp" +#include "cpp_common/pgdata_getters.hpp" #include "cpp_common/rule.hpp" -#include "cpp_common/combinations.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/combinations.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" -#include "trsp/pgr_trspHandler.h" +#include "trsp/trspHandler.hpp" namespace { @@ -131,10 +133,10 @@ get_route( } // namespace void -do_trspVia( - Edge_t* data_edges, size_t total_edges, - Restriction_t *restrictions, size_t restrictions_size, - int64_t* via_vidsArr, size_t size_via_vidsArr, +pgr_do_trspVia( + char *edges_sql, + char *restrictions_sql, + ArrayType* viaArr, bool directed, bool strict, @@ -148,41 +150,53 @@ do_trspVia( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intArray; std::ostringstream log; std::ostringstream err; std::ostringstream notice; + char *hint = nullptr; try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); + if (!edges_sql) return; + + auto via = get_intArray(viaArr, false); + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = pgr_msg(edges_sql); + return; + } + hint = nullptr; + - graphType gType = directed? DIRECTED: UNDIRECTED; - std::deque paths; - std::vector via_vertices( - via_vidsArr, via_vidsArr + size_via_vidsArr); + std::deque paths; if (directed) { - pgrouting::DirectedGraph digraph(gType); - digraph.insert_edges(data_edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); pgrouting::pgr_dijkstraVia( digraph, - via_vertices, + via, paths, strict, U_turn_on_edge, log); } else { - pgrouting::UndirectedGraph undigraph(gType); - undigraph.insert_edges(data_edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); pgrouting::pgr_dijkstraVia( undigraph, - via_vertices, + via, paths, strict, U_turn_on_edge, @@ -197,7 +211,7 @@ do_trspVia( return; } - if (restrictions_size == 0) { + if (!restrictions_sql) { (*return_tuples) = pgr_alloc(count, (*return_tuples)); (*return_count) = (get_route(return_tuples, paths)); (*return_tuples)[count - 1].edge = -2; @@ -207,24 +221,29 @@ do_trspVia( /* * When there are turn restrictions */ + hint = restrictions_sql; + auto restrictions = pgrouting::pgget::get_restrictions(std::string(restrictions_sql)); + if (restrictions.empty()) { + (*return_tuples) = pgr_alloc(count, (*return_tuples)); + (*return_count) = (get_route(return_tuples, paths)); + (*return_tuples)[count - 1].edge = -2; + return; + } + std::vector ruleList; - for (size_t i = 0; i < restrictions_size; ++i) { - if (restrictions[i].via_size == 0) continue; - ruleList.push_back(pgrouting::trsp::Rule(*(restrictions + i))); + for (const auto &r : restrictions) { + if (r.via) ruleList.push_back(pgrouting::trsp::Rule(r)); } + hint = nullptr; auto new_combinations = pgrouting::utilities::get_combinations(paths, ruleList); if (!new_combinations.empty()) { - pgrouting::trsp::Pgr_trspHandler gdef( - data_edges, - total_edges, - directed, - ruleList); + pgrouting::trsp::Pgr_trspHandler gdef(edges, directed, ruleList); auto new_paths = gdef.process(new_combinations); paths.insert(paths.end(), new_paths.begin(), new_paths.end()); } - post_process_trspvia(paths, via_vertices); + post_process_trspvia(paths, via); count = count_tuples(paths); @@ -250,6 +269,9 @@ do_trspVia( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/trsp/trspVia_withPoints.c b/src/trsp/trspVia_withPoints.c index 74b838a0530..f73b97a7816 100644 --- a/src/trsp/trspVia_withPoints.c +++ b/src/trsp/trspVia_withPoints.c @@ -31,7 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/withPoints/get_new_queries.h" #include "drivers/trsp/trspVia_withPoints_driver.h" @@ -44,7 +43,7 @@ process( char* edges_sql, char* restrictions_sql, char* points_sql, - ArrayType *viasArr, + ArrayType *vias, bool directed, bool strict, @@ -60,73 +59,26 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - /* - * Processing Via - */ - size_t size_via = 0; - int64_t* via = pgr_get_bigIntArray(&size_via, viasArr, false, &err_msg); - throw_error(err_msg, "While getting via vertices"); - - // TODO(vicky) figure out what happens when one point or 0 points are given /* - * Processing Points + * Estimate driving side */ driving_side[0] = estimate_drivingSide(driving_side[0]); if (driving_side[0] != 'r' && driving_side[0] != 'l') { - driving_side[0] = 'l'; + driving_side[0] = 'r'; } - Point_on_edge_t *points = NULL; - size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points, &err_msg); - throw_error(err_msg, points_sql); - 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); - /* - * Processing Edges - */ - 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, true, false, &err_msg); - throw_error(err_msg, edges_no_points_query); - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); - throw_error(err_msg, edges_of_points_query); - - {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 (via) {pfree(via); via = NULL;} - pgr_SPI_finish(); - return; - } - - /* - * Processing restrictions - */ - Restriction_t * restrictions = NULL; - size_t size_restrictions = 0; - - pgr_get_restrictions(restrictions_sql, &restrictions, &size_restrictions, &err_msg); - throw_error(err_msg, restrictions_sql); - clock_t start_t = clock(); - do_trspVia_withPoints( - edges, total_edges, - restrictions, size_restrictions, - points, total_points, - edges_of_points, total_edges_of_points, - via, size_via, + pgr_do_trspVia_withPoints( + edges_no_points_query, + restrictions_sql, + points_sql, + edges_of_points_query, + vias, directed, @@ -146,16 +98,15 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); + + if (edges_of_points_query) { + pfree(edges_of_points_query); edges_of_points_query = NULL; + } + if (edges_no_points_query) { + pfree(edges_no_points_query); edges_no_points_query = 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;} - if (edges) {pfree(edges); edges = NULL;} - if (via) {pfree(via); via = NULL;} - if (restrictions) {pfree(restrictions); restrictions = NULL;} - if (edges_of_points) {pfree(edges_of_points); edges_of_points = NULL;} - if (points) {pfree(points); points = NULL;} pgr_SPI_finish(); } diff --git a/src/trsp/trspVia_withPoints_driver.cpp b/src/trsp/trspVia_withPoints_driver.cpp index 59ec3c1adfe..5c057cb13f7 100644 --- a/src/trsp/trspVia_withPoints_driver.cpp +++ b/src/trsp/trspVia_withPoints_driver.cpp @@ -28,17 +28,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include + -#include "dijkstra/pgr_dijkstraVia.hpp" -#include "withPoints/pgr_withPoints.hpp" #include "c_types/routes_t.h" -#include "c_types/restriction_t.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "cpp_common/rule.hpp" -#include "cpp_common/combinations.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/combinations.hpp" -#include "trsp/pgr_trspHandler.h" +#include "dijkstra/dijkstraVia.hpp" +#include "withPoints/withPoints.hpp" +#include "trsp/trspHandler.hpp" namespace { @@ -129,22 +131,20 @@ get_route( } // namespace void -do_trspVia_withPoints( - Edge_t* edges, size_t total_edges, - Restriction_t *restrictions, size_t restrictions_size, - 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, +pgr_do_trspVia_withPoints( + char *edges_sql, + char *restrictions_sql, + char *points_sql, + char *edges_of_points_sql, + ArrayType* viaArr, bool directed, - char driving_side, bool details, - bool strict, bool U_turn_on_edge, - Routes_t** return_tuples, size_t* return_count, + Routes_t** return_tuples, size_t *return_count, char** log_msg, char** notice_msg, @@ -153,41 +153,48 @@ do_trspVia_withPoints( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intArray; std::ostringstream log; - std::ostringstream err; std::ostringstream notice; + std::ostringstream err; + char *hint = nullptr; try { - pgassert((total_edges + total_edges_of_points) != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - std::dequepaths; + auto via = get_intArray(viaArr, false); - graphType gType = directed? DIRECTED: UNDIRECTED; + hint = points_sql; + auto points = pgrouting::pgget::get_points(std::string(points_sql)); - /* - * processing via - */ - std::vector via_vertices(via_vidsArr, via_vidsArr + size_via_vidsArr); + hint = edges_of_points_sql; + auto edges_of_points = pgrouting::pgget::get_edges(std::string(edges_of_points_sql), true, false); - /* - * processing points - */ + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + + if (edges.size() + edges_of_points.size() == 0) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + + hint = restrictions_sql; + auto restrictions = restrictions_sql? + pgrouting::pgget::get_restrictions(std::string(restrictions_sql)) : std::vector(); + + /* Dealing with 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), + points, edges_of_points, true, driving_side, directed); + log << pg_graph.get_log(); if (pg_graph.has_error()) { log << pg_graph.get_log(); @@ -197,27 +204,28 @@ do_trspVia_withPoints( return; } - auto vertices(pgrouting::extract_vertices(edges, total_edges)); + auto vertices(pgrouting::extract_vertices(edges)); vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges()); + std::deque paths; if (directed) { - pgrouting::DirectedGraph digraph(vertices, gType); - digraph.insert_edges(edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); digraph.insert_edges(pg_graph.new_edges()); pgrouting::pgr_dijkstraVia( digraph, - via_vertices, + via, paths, strict, U_turn_on_edge, log); } else { - pgrouting::UndirectedGraph undigraph(vertices, gType); - undigraph.insert_edges(edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); undigraph.insert_edges(pg_graph.new_edges()); pgrouting::pgr_dijkstraVia( undigraph, - via_vertices, + via, paths, strict, U_turn_on_edge, @@ -236,35 +244,32 @@ do_trspVia_withPoints( return; } - if (restrictions_size == 0) { + if (!restrictions_sql || restrictions.empty()) { (*return_tuples) = pgr_alloc(count, (*return_tuples)); (*return_count) = (get_route(return_tuples, paths)); (*return_tuples)[count - 1].edge = -2; return; } - /* - * When there are turn restrictions - */ + std::vector ruleList; - for (size_t i = 0; i < restrictions_size; ++i) { - if (restrictions[i].via_size == 0) continue; - ruleList.push_back(pgrouting::trsp::Rule(*(restrictions + i))); + for (const auto &r : restrictions) { + if (r.via) ruleList.push_back(pgrouting::trsp::Rule(r)); } + hint = nullptr; auto new_combinations = pgrouting::utilities::get_combinations(paths, ruleList); if (!new_combinations.empty()) { pgrouting::trsp::Pgr_trspHandler gdef( edges, - total_edges, pg_graph.new_edges(), directed, ruleList); auto new_paths = gdef.process(new_combinations); paths.insert(paths.end(), new_paths.begin(), new_paths.end()); } - post_process_trspvia(paths, via_vertices); + post_process_trspvia(paths, via); if (!details) { for (auto &path : paths) path = pg_graph.eliminate_details(path); } @@ -294,6 +299,9 @@ do_trspVia_withPoints( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/trsp/trsp_deprecated.c b/src/trsp/trsp_deprecated.c new file mode 100644 index 00000000000..00f450914ca --- /dev/null +++ b/src/trsp/trsp_deprecated.c @@ -0,0 +1,453 @@ +/*PGR-GNU***************************************************************** +File: trsp_deprecated.c + +Generated with Template by: +Copyright (c) 2013 pgRouting developers +Mail: project@pgrouting.org + +------ + +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 "c_common/postgres_connection.h" +#include "catalog/pg_type.h" + +#include "c_common/debug_macro.h" +#include "c_common/e_report.h" +#include "c_types/trsp/trsp.h" +#include "c_types/edge_rt.h" +#include "c_common/trsp_pgget.h" +#include "drivers/trsp/trsp_deprecated_driver.h" + +typedef struct restrict_t restrict_t; +typedef struct Edge_rt Edge_t; +typedef struct path_element_tt path_element_tt; + +PGDLLEXPORT Datum _pgr_trsp(PG_FUNCTION_ARGS); + + +typedef struct edge_columns { + int id; + int source; + int target; + int cost; + int reverse_cost; +} edge_columns_t; + +typedef struct restrict_columns { + int target_id; + int via_path; + int to_cost; +} restrict_columns_t; + + +/* + * This function fetches the resturction columns from an SPITupleTable.. + * +*/ +static int +fetch_restrict_columns(SPITupleTable *tuptable, + restrict_columns_t *restrict_columns) { + restrict_columns->target_id = SPI_fnumber(tuptable->tupdesc, "target_id"); + restrict_columns->via_path = SPI_fnumber(tuptable->tupdesc, "via_path"); + restrict_columns->to_cost = SPI_fnumber(tuptable->tupdesc, "to_cost"); + if (restrict_columns->target_id == SPI_ERROR_NOATTRIBUTE || + restrict_columns->via_path == SPI_ERROR_NOATTRIBUTE || + restrict_columns->to_cost == SPI_ERROR_NOATTRIBUTE) { + elog(ERROR, "Error, restriction query must return columns " + "'target_id', 'via_path' and 'to_cost'"); + return -1; + } + + if (SPI_gettypeid(tuptable->tupdesc, + restrict_columns->target_id) != INT4OID || + SPI_gettypeid(tuptable->tupdesc, restrict_columns->via_path) != TEXTOID || + SPI_gettypeid(tuptable->tupdesc, restrict_columns->to_cost) != FLOAT8OID) { + elog(ERROR, "Error, restriction columns 'target_id' must be of type int4," + "'via_path' must be of type text, 'to_cost' must be of type float8"); + return -1; + } + + return 0; +} + + +/* + * To fetch a edge from Tuple. + * + */ + +static void +fetch_restrict(HeapTuple *tuple, TupleDesc *tupdesc, + restrict_columns_t *restrict_columns, restrict_t *rest) { + Datum binval; + bool isnull; + int t; + + for (t = 0; t < MAX_RULE_LENGTH; ++t) + rest->via[t] = -1; + + binval = SPI_getbinval(*tuple, *tupdesc, restrict_columns->target_id, + &isnull); + if (isnull) + elog(ERROR, "target_id contains a null value"); + rest->target_id = DatumGetInt32(binval); + + binval = SPI_getbinval(*tuple, *tupdesc, restrict_columns->to_cost, &isnull); + if (isnull) + elog(ERROR, "to_cost contains a null value"); + rest->to_cost = DatumGetFloat8(binval); + char *str = SPI_getvalue(*tuple, *tupdesc, restrict_columns->via_path); + + // PGR_DBG("restriction: %f, %i, %s", rest->to_cost, rest->target_id, str); + + if (str != NULL) { + int ci = 0; + char* pch = (char *)strtok(str, " ,"); + + while (pch != NULL && ci < MAX_RULE_LENGTH) { + rest->via[ci] = atoi(pch); + // PGR_DBG(" rest->via[%i]=%i", ci, rest->via[ci]); + ci++; + pch = (char *)strtok(NULL, " ,"); + } + } +} + + + +static int compute_trsp( + char* edges_sql, + int dovertex, + int64_t start_id, + double start_pos, + int64_t end_id, + double end_pos, + bool directed, + bool has_reverse_cost, + char* restrict_sql, + path_element_tt **path, + size_t *path_count) { + pgr_SPI_connect(); + char* err_msg = NULL; + + SPIPlanPtr SPIplan; + Portal SPIportal; + + Edge_t *edges = NULL; + size_t total_tuples = 0; + pgr_get_edges(edges_sql, &edges, &total_tuples, true, false, &err_msg); + pgr_throw_error(err_msg, edges_sql); + + // defining min and max vertex id + int64_t v_max_id = 0; + int64_t v_min_id = INT_MAX; + + size_t z; + for (z = 0; z < total_tuples; z++) { + PGR_DBG("id %ld source %ld target %ld cost %f rev %f", + edges[z].id, edges[z].source, edges[z].target, edges[z].cost, edges[z].reverse_cost); + if (edges[z].source < v_min_id) + v_min_id = edges[z].source; + + if (edges[z].source > v_max_id) + v_max_id = edges[z].source; + + if (edges[z].target < v_min_id) + v_min_id = edges[z].target; + + if (edges[z].target > v_max_id) + v_max_id = edges[z].target; + } + + // :::::::::::::::::::::::::::::::::::: + // :: reducing vertex id (renumbering) + // :::::::::::::::::::::::::::::::::::: + /* track if start and end are both in edge tuples */ + int s_count = 0; + int t_count = 0; + for (z = 0; z < total_tuples; z++) { + // check if edges[] contains source and target + if (dovertex) { + if (edges[z].source == start_id || edges[z].target == start_id) + ++s_count; + if (edges[z].source == end_id || edges[z].target == end_id) + ++t_count; + } else { + if (edges[z].id == start_id) + ++s_count; + if (edges[z].id == end_id) + ++t_count; + } + + edges[z].source -= v_min_id; + edges[z].target -= v_min_id; + } + + PGR_DBG("Min vertex id: %ld , Max vid: %ld", v_min_id, v_max_id); + PGR_DBG("Total %ld edge tuples", total_tuples); + + if (s_count == 0) { + elog(ERROR, "Start id was not found."); + return -1; + } + + if (t_count == 0) { + elog(ERROR, "Target id was not found."); + return -1; + } + + if (dovertex) { + start_id -= v_min_id; + end_id -= v_min_id; + } + + PGR_DBG("Fetching restriction tuples\n"); + restrict_t *restricts = NULL; + uint64_t total_restrict_tuples = 0; + restrict_columns_t restrict_columns = {.target_id = -1, .via_path = -1, + .to_cost = -1}; + + int ret = -1; + + if (restrict_sql == NULL) { + PGR_DBG("Sql for restrictions is null."); + } else { + int64 TUPLIMIT = 1000; + + SPIplan = SPI_prepare(restrict_sql, 0, NULL); + if (SPIplan == NULL) { + elog(ERROR, "turn_restrict_shortest_path: " + "couldn't create query plan via SPI"); + return -1; + } + + if ((SPIportal = SPI_cursor_open(NULL, SPIplan, NULL, NULL, true)) \ + == NULL) { + elog(ERROR, "turn_restrict_shortest_path:" + " SPI_cursor_open('%s') returns NULL", restrict_sql); + return -1; + } + + bool moredata = true; + while (moredata == true) { + SPI_cursor_fetch(SPIportal, true, TUPLIMIT); + + if (restrict_columns.target_id == -1) { + if (fetch_restrict_columns(SPI_tuptable, &restrict_columns) \ + == -1) { + PGR_DBG("fetch_restrict_columns failed!"); + pgr_SPI_finish(); + return -1; + } + } + + /* Suppress the -Wconversion warning temporarily */ + uint64_t ntuples = SPI_processed; + + total_restrict_tuples += ntuples; + + if (ntuples > 0) { + if (!restricts) + restricts = palloc(total_restrict_tuples * sizeof(restrict_t)); + else + restricts = repalloc(restricts, + total_restrict_tuples * sizeof(restrict_t)); + + if (restricts == NULL) { + pgr_SPI_finish(); + elog(ERROR, "Out of memory"); + return -1; + } + + uint32_t t; + SPITupleTable *tuptable = SPI_tuptable; + TupleDesc tupdesc = SPI_tuptable->tupdesc; + + for (t = 0; t < ntuples; t++) { + HeapTuple tuple = tuptable->vals[t]; + fetch_restrict(&tuple, &tupdesc, &restrict_columns, + &restricts[total_restrict_tuples - ntuples + t]); + } + SPI_freetuptable(tuptable); + } else { + moredata = false; + } + } + SPI_cursor_close(SPIportal); + } + + PGR_DBG("Total %ld restriction tuples", total_restrict_tuples); + + PGR_DBG("Calling trsp_edge_wrapper\n"); + ret = trsp_edge_wrapper(edges, total_tuples, + restricts, total_restrict_tuples, + start_id, start_pos, end_id, end_pos, + directed, has_reverse_cost, + path, path_count, &err_msg); + + PGR_DBG("Message received from inside:"); + PGR_DBG("%s", err_msg); + + + // :::::::::::::::::::::::::::::::: + // :: restoring original vertex id + // :::::::::::::::::::::::::::::::: + for (z = 0; z < *path_count; z++) { + if (z || (*path)[z].vertex_id != -1) + (*path)[z].vertex_id += v_min_id; + } + + PGR_DBG("ret = %i\n", ret); + + PGR_DBG("*path_count = %ld\n", *path_count); + + if (ret < 0) { + ereport(ERROR, (errcode(ERRCODE_E_R_E_CONTAINING_SQL_NOT_PERMITTED), + errmsg("Error computing path: %s", err_msg))); + } + + pgr_SPI_finish(); + return 0; +} + + +PG_FUNCTION_INFO_V1(_pgr_trsp); +PGDLLEXPORT Datum +_pgr_trsp(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + path_element_tt *path; + + // stuff done only on the first call of the function + if (SRF_IS_FIRSTCALL()) { + MemoryContext oldcontext; + size_t path_count = 0; + int i; + double s_pos; + double e_pos; + char * sql; + + // create a function context for cross-call persistence + funcctx = SRF_FIRSTCALL_INIT(); + + // switch to memory context appropriate for multiple function calls + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + + // verify that the first 5 args are not NULL + for (i = 0; i < 7; i++) { + if (i == 2 || i == 4) continue; + if (PG_ARGISNULL(i)) { + elog(ERROR, "turn_restrict_shortest_path(): " + "Argument %i may not be NULL", i+1); + } + } + + if (PG_ARGISNULL(2)) { + s_pos = 0.5; + } else { + s_pos = PG_GETARG_FLOAT8(2); + if (s_pos < 0.0) s_pos = 0.5; + if (s_pos > 1.0) s_pos = 0.5; + } + + if (PG_ARGISNULL(4)) { + e_pos = 0.5; + } else { + e_pos = PG_GETARG_FLOAT8(4); + if (e_pos < 0.0) e_pos = 0.5; + if (e_pos > 1.0) e_pos = 0.5; + } + + if (PG_ARGISNULL(7)) { + sql = NULL; + } else { + sql = text_to_cstring(PG_GETARG_TEXT_P(7)); + } + + PGR_DBG("Calling compute_trsp"); + + compute_trsp(text_to_cstring(PG_GETARG_TEXT_P(0)), + 0, // sdo edge + PG_GETARG_INT32(1), + s_pos, + PG_GETARG_INT32(3), + e_pos, + PG_GETARG_BOOL(5), + PG_GETARG_BOOL(6), + sql, + &path, &path_count); + + // total number of tuples to be returned + funcctx->max_calls = path_count; + + funcctx->user_fctx = path; + 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); + } + + // stuff done on every call of the function + funcctx = SRF_PERCALL_SETUP(); + + tuple_desc = funcctx->tuple_desc; + path = (path_element_tt*) funcctx->user_fctx; + + if (funcctx->call_cntr < funcctx->max_calls) { + // do when there is more left to send + HeapTuple tuple; + Datum result; + Datum *values; + bool* nulls; + + values = palloc(4 * sizeof(Datum)); + nulls = palloc(4 * sizeof(char)); + + values[0] = Int64GetDatum((int64_t)funcctx->call_cntr); + nulls[0] = false; + values[1] = Int32GetDatum((int32_t)path[funcctx->call_cntr].vertex_id); + nulls[1] = false; + values[2] = Int32GetDatum((int32_t)path[funcctx->call_cntr].edge_id); + nulls[2] = false; + values[3] = Float8GetDatum(path[funcctx->call_cntr].cost); + nulls[3] = false; + + tuple = heap_form_tuple(tuple_desc, values, nulls); + + // make the tuple into a datum + result = HeapTupleGetDatum(tuple); + + // clean up (this is not really necessary) + pfree(values); + pfree(nulls); + + SRF_RETURN_NEXT(funcctx, result); + } else { // do when there is no more left + PGR_DBG("Going to free path"); + if (path) free(path); + SRF_RETURN_DONE(funcctx); + } +} diff --git a/src/trsp/trsp_core.cpp b/src/trsp/trsp_deprecated_driver.cpp similarity index 95% rename from src/trsp/trsp_core.cpp rename to src/trsp/trsp_deprecated_driver.cpp index 61fd6f2c513..342a5cf2f04 100644 --- a/src/trsp/trsp_core.cpp +++ b/src/trsp/trsp_deprecated_driver.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -File: trsp_core.cpp +File: trsp_deprecated_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -24,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "trsp/trsp_core.h" +#include "drivers/trsp/trsp_deprecated_driver.h" #ifdef __MINGW32__ #include @@ -33,7 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "trsp/GraphDefinition.h" +#include "trsp/GraphDefinition.hpp" int trsp_edge_wrapper( diff --git a/src/trsp/trsp_driver.cpp b/src/trsp/trsp_driver.cpp index c80360275a7..c9b289565cc 100644 --- a/src/trsp/trsp_driver.cpp +++ b/src/trsp/trsp_driver.cpp @@ -38,17 +38,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "trsp/pgr_trspHandler.h" +#include "trsp/trspHandler.hpp" +#include "cpp_common/pgdata_getters.hpp" #include "cpp_common/rule.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/combinations.h" -#include "c_types/restriction_t.h" +#include "cpp_common/assert.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/restriction_t.hpp" #include "c_types/ii_t_rt.h" -#include "dijkstra/dijkstra.hpp" -#include "withPoints/pgr_withPoints.hpp" +#include "withPoints/withPoints.hpp" +#include "dijkstra/dijkstra.hpp" namespace { @@ -93,13 +95,12 @@ pgr_dijkstra( } // namespace void -do_trsp( - Edge_t *edges, size_t total_edges, - Restriction_t *restrictions, size_t restrictions_size, - - II_t_rt *combinations_arr, size_t total_combinations, - int64_t *starts_arr, size_t size_starts_arr, - int64_t *ends_arr, size_t size_ends_arr, +pgr_do_trsp( + char *edges_sql, + char *restrictions_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, bool directed, @@ -112,37 +113,53 @@ do_trsp( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; + try { - pgassert(edges); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - graphType gType = directed? DIRECTED: UNDIRECTED; + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + hint = nullptr; + + if (edges.empty()) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = pgr_msg(edges_sql); + return; + } - auto vertices(pgrouting::extract_vertices(edges, total_edges)); - auto combinations = total_combinations? - pgrouting::utilities::get_combinations(combinations_arr, total_combinations) - : pgrouting::utilities::get_combinations(starts_arr, size_starts_arr, ends_arr, size_ends_arr); std::deque paths; if (directed) { - pgrouting::DirectedGraph digraph(vertices, gType); - digraph.insert_edges(edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); paths = pgr_dijkstra( digraph, combinations); } else { - pgrouting::UndirectedGraph undigraph(vertices, gType); - undigraph.insert_edges(edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); paths = pgr_dijkstra( undigraph, @@ -159,7 +176,7 @@ do_trsp( return; } - if (restrictions_size == 0) { + if (!restrictions_sql) { (*return_tuples) = pgr_alloc(count, (*return_tuples)); (*return_count) = (collapse_paths(return_tuples, paths)); return; @@ -168,18 +185,25 @@ do_trsp( /* * When there are turn restrictions */ + hint = restrictions_sql; + auto restrictions = pgrouting::pgget::get_restrictions(std::string(restrictions_sql)); + if (restrictions.empty()) { + (*return_tuples) = pgr_alloc(count, (*return_tuples)); + (*return_count) = (collapse_paths(return_tuples, paths)); + return; + } + std::vector ruleList; - for (size_t i = 0; i < restrictions_size; ++i) { - if (restrictions[i].via_size == 0) continue; - ruleList.push_back(pgrouting::trsp::Rule(*(restrictions + i))); + for (const auto &r : restrictions) { + if (r.via) ruleList.push_back(pgrouting::trsp::Rule(r)); } + hint = nullptr; auto new_combinations = pgrouting::utilities::get_combinations(paths, ruleList); if (!new_combinations.empty()) { pgrouting::trsp::Pgr_trspHandler gdef( edges, - total_edges, directed, ruleList); auto new_paths = gdef.process(new_combinations); @@ -216,6 +240,9 @@ do_trsp( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch(...) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/trsp/trsp_withPoints.c b/src/trsp/trsp_withPoints.c index 5a945b894e8..87052fd311b 100644 --- a/src/trsp/trsp_withPoints.c +++ b/src/trsp/trsp_withPoints.c @@ -29,18 +29,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" -#include "c_types/point_on_edge_t.h" -#include "c_types/restriction_t.h" - #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" - #include "drivers/withPoints/get_new_queries.h" #include "drivers/trsp/trsp_withPoints_driver.h" @@ -65,26 +58,20 @@ process( Path_rt **result_tuples, size_t *result_count) { - driving_side[0] = estimate_drivingSide(driving_side[0]); - if (driving_side[0] != 'r' && driving_side[0] != 'l') { - driving_side[0] = 'l'; - } - pgr_SPI_connect(); char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - size_t size_start_pidsArr = 0; - int64_t* start_pidsArr = NULL; - - size_t size_end_pidsArr = 0; - int64_t* end_pidsArr = NULL; - II_t_rt *combinations = NULL; - size_t total_combinations = 0; + /* + * Estimate driving side + */ + driving_side[0] = estimate_drivingSide(driving_side[0]); + if (driving_side[0] != 'r' && driving_side[0] != 'l') { + driving_side[0] = 'l'; + } - /* managing edges */ char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; get_new_queries( @@ -92,65 +79,18 @@ process( &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_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); - throw_error(err_msg, edges_of_points_query); - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_no_points_query); - - pfree(edges_of_points_query); - pfree(edges_no_points_query); - edges_of_points_query = NULL; - edges_no_points_query = NULL; - - if ((total_edges + total_edges_of_points) == 0) { - pgr_SPI_finish(); - return; - } - - /* Managing departure & destination */ - if (starts && ends) { - start_pidsArr = (int64_t*) pgr_get_bigIntArray(&size_start_pidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_pidsArr = (int64_t*) pgr_get_bigIntArray(&size_end_pidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - } - - /* Managing Points */ - Point_on_edge_t *points = NULL; - size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points, &err_msg); - throw_error(err_msg, points_sql); - - /* Managing restrictions */ - Restriction_t *restrictions = NULL; - size_t restrictions_size = 0; - pgr_get_restrictions(restrictions_sql, &restrictions, &restrictions_size, &err_msg); - throw_error(err_msg, restrictions_sql); - clock_t start_t = clock(); - - do_trsp_withPoints( - edges, total_edges, - restrictions, restrictions_size, - points, total_points, - edges_of_points, total_edges_of_points, - - combinations, total_combinations, - - start_pidsArr, size_start_pidsArr, - end_pidsArr, size_end_pidsArr, + pgr_do_trsp_withPoints( + edges_no_points_query, + restrictions_sql, + points_sql, + edges_of_points_query, + combinations_sql, + starts, ends, directed, + driving_side[0], details, @@ -163,21 +103,18 @@ process( if (err_msg && (*result_tuples)) { pfree(*result_tuples); - (*result_count) = 0; (*result_tuples) = NULL; + (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) {pfree(edges); edges = NULL;} - if (edges_of_points) {pfree(edges_of_points); edges_of_points = NULL;} - if (edges_of_points) {pfree(edges_of_points); edges_of_points = NULL;} - if (start_pidsArr) {pfree(start_pidsArr); start_pidsArr = NULL;} - if (end_pidsArr) {pfree(end_pidsArr); end_pidsArr = NULL;} - if (combinations) {pfree(combinations); combinations = NULL;} + if (edges_of_points_query) { + pfree(edges_of_points_query); edges_of_points_query = NULL; + } + if (edges_no_points_query) { + pfree(edges_no_points_query); edges_no_points_query = NULL; + } pgr_SPI_finish(); } @@ -236,7 +173,6 @@ _pgr_trsp_withpoints(PG_FUNCTION_ARGS) { } funcctx->max_calls = result_count; - funcctx->user_fctx = result_tuples; if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) @@ -269,11 +205,9 @@ _pgr_trsp_withpoints(PG_FUNCTION_ARGS) { nulls[i] = false; } - int path_id = call_cntr == 0? 0 : result_tuples[call_cntr - 1].seq; - path_id += result_tuples[call_cntr].seq == 1? 1 : 0; - + int64_t seq = call_cntr == 0? 1 : result_tuples[call_cntr - 1].start_id; values[0] = Int32GetDatum((int32_t)call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[call_cntr].seq); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[call_cntr].start_id); values[3] = Int64GetDatum(result_tuples[call_cntr].end_id); values[4] = Int64GetDatum(result_tuples[call_cntr].node); @@ -281,7 +215,7 @@ _pgr_trsp_withpoints(PG_FUNCTION_ARGS) { values[6] = Float8GetDatum(result_tuples[call_cntr].cost); values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost); - result_tuples[call_cntr].seq = path_id; + result_tuples[call_cntr].start_id = result_tuples[call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); @@ -290,4 +224,3 @@ _pgr_trsp_withpoints(PG_FUNCTION_ARGS) { SRF_RETURN_DONE(funcctx); } } - diff --git a/src/trsp/trsp_withPoints_driver.cpp b/src/trsp/trsp_withPoints_driver.cpp index c5688e86039..0bcc7453b55 100644 --- a/src/trsp/trsp_withPoints_driver.cpp +++ b/src/trsp/trsp_withPoints_driver.cpp @@ -38,17 +38,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include -#include "trsp/pgr_trspHandler.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "cpp_common/rule.hpp" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/combinations.h" -#include "c_types/restriction_t.h" -#include "c_types/ii_t_rt.h" -#include "dijkstra/dijkstra.hpp" -#include "withPoints/pgr_withPoints.hpp" +#include "cpp_common/combinations.hpp" +#include "withPoints/withPoints.hpp" +#include "trsp/trspHandler.hpp" +#include "dijkstra/dijkstra.hpp" namespace { @@ -73,33 +73,17 @@ post_process_trsp(std::deque &paths) { return e1.start_id() < e2.start_id(); }); } - -template -std::deque -pgr_dijkstra( - G &graph, - std::map> &combinations - ) { - auto paths = pgrouting::algorithms::dijkstra( - graph, - combinations, - false, (std::numeric_limits::max)()); - - return paths; -} - } // namespace void -do_trsp_withPoints( - Edge_t *edges, size_t total_edges, - Restriction_t *restrictions, size_t restrictions_size, - Point_on_edge_t *points_p, size_t total_points, - Edge_t *edges_of_points, size_t total_edges_of_points, - - II_t_rt *combinations_arr, size_t total_combinations, - int64_t *starts_arr, size_t size_starts_arr, - int64_t *ends_arr, size_t size_ends_arr, +pgr_do_trsp_withPoints( + char *edges_sql, + char *restrictions_sql, + char *points_sql, + char *edges_of_points_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, bool directed, char driving_side, @@ -114,28 +98,55 @@ do_trsp_withPoints( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; + try { - pgassert(edges || edges_of_points); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - graphType gType = directed? DIRECTED: UNDIRECTED; + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, true); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + hint = points_sql; + auto points = pgrouting::pgget::get_points(std::string(points_sql)); + + hint = edges_of_points_sql; + auto edges_of_points = pgrouting::pgget::get_edges(std::string(edges_of_points_sql), true, false); + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + + if (edges.size() + edges_of_points.size() == 0) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + + hint = restrictions_sql; + auto restrictions = restrictions_sql? + pgrouting::pgget::get_restrictions(std::string(restrictions_sql)) : std::vector(); + + + /* Dealing with 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), + points, edges_of_points, true, driving_side, directed); @@ -149,39 +160,37 @@ do_trsp_withPoints( return; } - auto vertices(pgrouting::extract_vertices(edges, total_edges)); + auto vertices(pgrouting::extract_vertices(edges)); vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges()); - auto combinations = total_combinations? - pgrouting::utilities::get_combinations(combinations_arr, total_combinations) - : pgrouting::utilities::get_combinations(starts_arr, size_starts_arr, ends_arr, size_ends_arr); - std::deque paths; if (directed) { - pgrouting::DirectedGraph digraph(vertices, gType); - digraph.insert_edges(edges, total_edges); + pgrouting::DirectedGraph digraph; + digraph.insert_edges(edges); digraph.insert_edges(pg_graph.new_edges()); - paths = pgr_dijkstra( + paths = pgrouting::algorithms::dijkstra( digraph, - combinations); + combinations, + false, (std::numeric_limits::max)()); } else { - pgrouting::UndirectedGraph undigraph(vertices, gType); - undigraph.insert_edges(edges, total_edges); + pgrouting::UndirectedGraph undigraph; + undigraph.insert_edges(edges); undigraph.insert_edges(pg_graph.new_edges()); - paths = pgr_dijkstra( + paths = pgrouting::algorithms::dijkstra( undigraph, - combinations); + combinations, + false, (std::numeric_limits::max)()); } post_process_trsp(paths); + if (!details) { for (auto &path : paths) path = pg_graph.eliminate_details(path); } - size_t count(0); - count = count_tuples(paths); + size_t count(count_tuples(paths)); if (count == 0) { notice << "No paths found"; @@ -189,7 +198,7 @@ do_trsp_withPoints( return; } - if (restrictions_size == 0) { + if (!restrictions_sql || restrictions.empty()) { if (!details) { for (auto &path : paths) { path = pg_graph.eliminate_details(path); @@ -213,17 +222,16 @@ do_trsp_withPoints( * When there are turn restrictions */ std::vector ruleList; - for (size_t i = 0; i < restrictions_size; ++i) { - if (restrictions[i].via_size == 0) continue; - ruleList.push_back(pgrouting::trsp::Rule(*(restrictions + i))); + for (const auto &r : restrictions) { + if (r.via) ruleList.push_back(pgrouting::trsp::Rule(r)); } + hint = nullptr; auto new_combinations = pgrouting::utilities::get_combinations(paths, ruleList); if (!new_combinations.empty()) { pgrouting::trsp::Pgr_trspHandler gdef( edges, - total_edges, pg_graph.new_edges(), directed, ruleList); @@ -265,6 +273,9 @@ do_trsp_withPoints( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch(...) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/tsp/TSP.c b/src/tsp/TSP.c index 92f28e40d69..b795116419c 100644 --- a/src/tsp/TSP.c +++ b/src/tsp/TSP.c @@ -36,7 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/tsp_tour_rt.h" #include "drivers/tsp/TSP_driver.h" @@ -58,26 +57,9 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - IID_t_rt *distances = NULL; - size_t total_distances = 0; - pgr_get_matrixRows(matrix_sql, &distances, &total_distances, &err_msg); - throw_error(err_msg, matrix_sql); - if (total_distances == 0) { - ereport(WARNING, - (errmsg("Insufficient data found on inner query."), - errhint("%s", matrix_sql))); - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - - do_pgr_tsp( - distances, total_distances, + pgr_do_tsp( + matrix_sql, start_vid, end_vid, max_cycles, @@ -87,7 +69,6 @@ process( &log_msg, ¬ice_msg, &err_msg); - time_msg("TSP", start_t, clock()); if (err_msg && (*result_tuples)) { @@ -96,12 +77,7 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (distances) pfree(distances); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } diff --git a/src/tsp/TSP_driver.cpp b/src/tsp/TSP_driver.cpp index cc43a358ffb..8c5c19d70a9 100644 --- a/src/tsp/TSP_driver.cpp +++ b/src/tsp/TSP_driver.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: TSP_driver.cpp +File: TSP_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -36,18 +35,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "tsp/tsp.hpp" #include "c_types/tsp_tour_rt.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" #include "c_types/ii_t_rt.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" + +#include "tsp/tsp.hpp" void -do_pgr_tsp( - IID_t_rt *distances, - size_t total_distances, +pgr_do_tsp( + char *matrix_sql, int64_t start_vid, int64_t end_vid, bool max_cycles, @@ -64,8 +64,20 @@ do_pgr_tsp( std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; + try { - pgrouting::algorithm::TSP fn_tsp{distances, total_distances, true}; + hint = matrix_sql; + auto distances = pgrouting::pgget::get_matrixRows(std::string(matrix_sql)); + + if (distances.size() == 0) { + *notice_msg = pgr_msg("Insufficient data found on inner query"); + *log_msg = hint? pgr_msg(hint) : nullptr; + return; + } + hint = nullptr; + + pgrouting::algorithm::TSP fn_tsp{distances}; if (start_vid != 0 && !fn_tsp.has_vertex(start_vid)) { err << "Parameter 'start_id' do not exist on the data"; @@ -111,6 +123,9 @@ do_pgr_tsp( (*return_count) = 0; *err_msg = pgr_msg(ex.first.c_str()); *log_msg = pgr_msg(ex.second.c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/tsp/euclideanTSP.c b/src/tsp/euclideanTSP.c index 1f24ced1ed3..c0274e4e125 100644 --- a/src/tsp/euclideanTSP.c +++ b/src/tsp/euclideanTSP.c @@ -29,14 +29,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ #include "c_common/postgres_connection.h" -#include "utils/array.h" #include "c_types/path_rt.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "c_types/tsp_tour_rt.h" #include "drivers/tsp/euclideanTSP_driver.h" @@ -59,26 +57,9 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - Coordinate_t *coordinates = NULL; - size_t total_coordinates = 0; - pgr_get_coordinates(coordinates_sql, &coordinates, &total_coordinates, &err_msg); - throw_error(err_msg, coordinates_sql); - - if (total_coordinates == 0) { - ereport(WARNING, - (errmsg("Insufficient data found on inner query."), - errhint("%s", coordinates_sql))); - (*result_count) = 0; - (*result_tuples) = NULL; - pgr_SPI_finish(); - return; - } - - PGR_DBG("Starting timer"); clock_t start_t = clock(); - - do_pgr_euclideanTSP( - coordinates, total_coordinates, + pgr_do_euclideanTSP( + coordinates_sql, start_vid, end_vid, max_cycles, @@ -88,7 +69,6 @@ process( &log_msg, ¬ice_msg, &err_msg); - time_msg("euclideanTSP", start_t, clock()); if (err_msg && (*result_tuples)) { @@ -97,12 +77,7 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); - - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (coordinates) pfree(coordinates); + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); pgr_SPI_finish(); } diff --git a/src/tsp/euclideanTSP_driver.cpp b/src/tsp/euclideanTSP_driver.cpp index b4b67b9041b..5d03b48257c 100644 --- a/src/tsp/euclideanTSP_driver.cpp +++ b/src/tsp/euclideanTSP_driver.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -FILE: euclideanTSP_driver.cpp +File: euclideanTSP_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -39,13 +38,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "tsp/tsp.hpp" #include "c_types/tsp_tour_rt.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" void -do_pgr_euclideanTSP( - Coordinate_t *coordinates, - size_t total_coordinates, +pgr_do_euclideanTSP( + char *coordinates_sql, int64_t start_vid, int64_t end_vid, bool max_cycles, @@ -62,9 +61,20 @@ do_pgr_euclideanTSP( std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; try { - pgrouting::algorithm::TSP fn_tsp{coordinates, total_coordinates, true}; + hint = coordinates_sql; + auto coordinates = pgrouting::pgget::get_coordinates(std::string(coordinates_sql)); + + if (coordinates.size() == 0) { + *notice_msg = pgr_msg("No coordinates found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + pgrouting::algorithm::TSP fn_tsp{coordinates}; if (start_vid != 0 && !fn_tsp.has_vertex(start_vid)) { err << "Parameter 'start_id' do not exist on the data"; @@ -110,6 +120,9 @@ do_pgr_euclideanTSP( (*return_count) = 0; *err_msg = pgr_msg(ex.first.c_str()); *log_msg = pgr_msg(ex.second.c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/tsp/tsp.cpp b/src/tsp/tsp.cpp index 90a96a707dd..80239058612 100644 --- a/src/tsp/tsp.cpp +++ b/src/tsp/tsp.cpp @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -File: tsp.cc +File: tsp.cpp Copyright (c) 2021 pgRouting developers Mail: project@pgrouting.org @@ -41,9 +40,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "cpp_common/identifiers.hpp" -#include "cpp_common/pgr_messages.h" -#include "cpp_common/pgr_assert.h" -#include "cpp_common/interruption.h" +#include "cpp_common/messages.hpp" +#include "cpp_common/assert.hpp" +#include "cpp_common/interruption.hpp" #include "visitors/dijkstra_visitors.hpp" @@ -231,7 +230,7 @@ TSP::tsp( auto u = get_boost_vertex(start_vid); auto v = get_boost_vertex(end_vid); - auto dummy_node = add_vertex(num_vertices(graph), graph); + auto dummy_node = add_vertex(static_cast(num_vertices(graph)), graph); id_to_V.insert(std::make_pair(0, dummy_node)); V_to_id.insert(std::make_pair(dummy_node, 0)); boost::add_edge(u, dummy_node, 0, graph); @@ -283,27 +282,25 @@ TSP::crossover_optimize(std::deque> result, size_t li -TSP::TSP( - IID_t_rt *distances, - size_t total_distances, bool) { +TSP::TSP(std::vector &distances) { /* * Inserting vertices */ Identifiers ids; - for (size_t i = 0; i < total_distances; ++i) { - ids += distances[i].from_vid; - ids += distances[i].to_vid; + for (auto &d : distances) { + ids += d.from_vid; + ids += d.to_vid; /* * Its undirected graph: * keeping from_vid < to_vid */ - if (distances[i].to_vid > distances[i].from_vid) { - std::swap(distances[i].to_vid, distances[i].from_vid); + if (d.to_vid > d.from_vid) { + std::swap(d.to_vid, d.from_vid); } } - size_t i {0}; - for (const auto id : ids) { + int i {0}; + for (const auto &id : ids) { auto v = add_vertex(i, graph); id_to_V.insert(std::make_pair(id, v)); V_to_id.insert(std::make_pair(v, id)); @@ -313,8 +310,7 @@ TSP::TSP( /* * Inserting edges */ - for (size_t i = 0; i < total_distances; ++i) { - auto edge = distances[i]; + for (const auto &edge : distances) { /* * skip loops */ @@ -374,24 +370,22 @@ TSP::TSP( * 2 , 3.6 1 * but when the remove_duplicates flag is on, keep only the first row that has the same id */ -TSP::TSP(Coordinate_t *coordinates, - size_t total_coordinates, - bool ) { - log << "before total_coordinates" << total_coordinates; +TSP::TSP(const std::vector &coordinates) { + log << "before total_coordinates" << coordinates.size(); /* * keeping the vertex identifiers */ Identifiers ids; - for (size_t i = 0; i < total_coordinates; ++i) { - ids += coordinates[i].id; + for (const auto c : coordinates) { + ids += c.id; } /* * Inserting vertices */ - size_t i{0}; - for (const auto id : ids) { + int i{0}; + for (const auto &id : ids) { auto v = add_vertex(i, graph); id_to_V.insert(std::make_pair(id, v)); V_to_id.insert(std::make_pair(v, id)); @@ -401,7 +395,7 @@ TSP::TSP(Coordinate_t *coordinates, /* * Inserting edges */ - for (size_t i = 0; i < total_coordinates; ++i) { + for (size_t i = 0; i < coordinates.size(); ++i) { auto u = get_boost_vertex(coordinates[i].id); auto ux = coordinates[i].x; auto uy = coordinates[i].y; @@ -409,7 +403,7 @@ TSP::TSP(Coordinate_t *coordinates, /* * undirected, so only need traverse higher coordinates for connections */ - for (size_t j = i + 1; j < total_coordinates; ++j) { + for (size_t j = i + 1; j < coordinates.size(); ++j) { auto v = get_boost_vertex(coordinates[j].id); /* @@ -438,7 +432,6 @@ TSP::TSP(Coordinate_t *coordinates, - std::deque> TSP::eval_tour(const std::vector &tsp_tour) { std::deque> results; @@ -517,14 +510,6 @@ std::ostream& operator<<(std::ostream &log, const TSP& data) { log << "Number of Edges is:" << num_edges(data.graph) << "\n"; log << "\n the print_graph\n"; boost::print_graph(data.graph, boost::get(boost::vertex_index, data.graph), log); -#if 0 - // to print with edge weights: - for (auto v : boost::make_iterator_range(boost::vertices(data.graph))) { - for (auto oe : boost::make_iterator_range(boost::out_edges(v, data.graph))) { - log << "Edge " << oe << " weight " << get(boost::edge_weight, data.graph)[oe] << "\n"; - } - } -#endif return log; } #endif diff --git a/src/version/version.c b/src/version/version.c index a6dba0580b0..54a69d12200 100644 --- a/src/version/version.c +++ b/src/version/version.c @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -File: _version.c +File: version.c Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org diff --git a/src/version/version.h.in b/src/version/version.h.in index c023cf01d48..52044cb7a7a 100644 --- a/src/version/version.h.in +++ b/src/version/version.h.in @@ -1,6 +1,5 @@ /*PGR-GNU***************************************************************** - -File: _version.h.in +File: version.h.in Function's developer: Copyright (c) 2015 Celia Virginia Vergara Castillo diff --git a/src/withPoints/CMakeLists.txt b/src/withPoints/CMakeLists.txt index a9f5435a692..d5fe066cb57 100644 --- a/src/withPoints/CMakeLists.txt +++ b/src/withPoints/CMakeLists.txt @@ -3,7 +3,7 @@ ADD_LIBRARY(withPoints OBJECT get_new_queries.cpp withPoints_driver.cpp - pgr_withPoints.cpp + withPoints.cpp withPointsVia.c withPointsVia_driver.cpp diff --git a/src/withPoints/get_new_queries.cpp b/src/withPoints/get_new_queries.cpp index e7d55fceba8..0aa4b4cd71a 100644 --- a/src/withPoints/get_new_queries.cpp +++ b/src/withPoints/get_new_queries.cpp @@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "drivers/withPoints/get_new_queries.h" #include #include -#include "cpp_common/pgr_alloc.hpp" +#include "cpp_common/alloc.hpp" char estimate_drivingSide(char driving_side) { diff --git a/src/withPoints/withPoints.c b/src/withPoints/withPoints.c index c9f6b517784..6a2036bab80 100644 --- a/src/withPoints/withPoints.c +++ b/src/withPoints/withPoints.c @@ -31,12 +31,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/postgres_connection.h" #include "c_types/path_rt.h" -#include "c_types/point_on_edge_t.h" #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" - -#include "c_common/pgdata_getters.h" #include "drivers/withPoints/get_new_queries.h" #include "drivers/withPoints/withPoints_driver.h" @@ -69,26 +66,6 @@ process( char* notice_msg = NULL; char* err_msg = NULL; - size_t size_start_pidsArr = 0; - int64_t* start_pidsArr = NULL; - - size_t size_end_pidsArr = 0; - int64_t* end_pidsArr = NULL; - - II_t_rt *combinations = NULL; - size_t total_combinations = 0; - - Point_on_edge_t *points = NULL; - size_t total_points = 0; - pgr_get_points(points_sql, &points, &total_points, &err_msg); - throw_error(err_msg, points_sql); - -#ifndef NDEBUG - size_t i; - for (i = 0; i< total_points; i++) { - PGR_DBG("%ld ", points[i].pid); - } -#endif char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; get_new_queries( @@ -97,61 +74,13 @@ process( &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; - - if (normal) { - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); - throw_error(err_msg, edges_of_points_query); - pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg); - throw_error(err_msg, edges_no_points_query); - - if (starts && ends) { - start_pidsArr = pgr_get_bigIntArray(&size_start_pidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - end_pidsArr = pgr_get_bigIntArray(&size_end_pidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } else if (combinations_sql) { - pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg); - throw_error(err_msg, combinations_sql); - } - } else { - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, false, false, &err_msg); - throw_error(err_msg, edges_of_points_query); - pgr_get_edges(edges_no_points_query, &edges, &total_edges, false, false, &err_msg); - throw_error(err_msg, edges_no_points_query); - - end_pidsArr = pgr_get_bigIntArray(&size_end_pidsArr, starts, false, &err_msg); - throw_error(err_msg, "While getting start vids"); - start_pidsArr = pgr_get_bigIntArray(&size_start_pidsArr, ends, false, &err_msg); - throw_error(err_msg, "While getting end vids"); - } - - - pfree(edges_of_points_query); - pfree(edges_no_points_query); - edges_of_points_query = NULL; - edges_no_points_query = NULL; - - if ((total_edges + total_edges_of_points) == 0) { - pgr_SPI_finish(); - return; - } - clock_t start_t = clock(); - - do_pgr_withPoints( - edges, total_edges, - points, total_points, - edges_of_points, total_edges_of_points, - - combinations, total_combinations, - - start_pidsArr, size_start_pidsArr, - end_pidsArr, size_end_pidsArr, + pgr_do_withPoints( + edges_no_points_query, + points_sql, + edges_of_points_query, + combinations_sql, + starts, ends, driving_side[0], details, @@ -176,18 +105,8 @@ process( (*result_tuples) = NULL; } - pgr_global_report(log_msg, notice_msg, err_msg); - -#if 0 - if (log_msg) pfree(log_msg); - if (notice_msg) pfree(notice_msg); - if (err_msg) pfree(err_msg); - if (edges) pfree(edges); - if (points) pfree(points); - if (edges_of_points) pfree(edges_of_points); - if (start_pidsArr) pfree(start_pidsArr); - if (end_pidsArr) pfree(end_pidsArr); -#endif + pgr_global_report(&log_msg, ¬ice_msg, &err_msg); + pgr_SPI_finish(); } @@ -199,10 +118,8 @@ _pgr_withpoints(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; - /**********************************************************************/ Path_rt *result_tuples = 0; size_t result_count = 0; - /**********************************************************************/ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; @@ -249,8 +166,6 @@ _pgr_withpoints(PG_FUNCTION_ARGS) { &result_count); } - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -275,15 +190,6 @@ _pgr_withpoints(PG_FUNCTION_ARGS) { Datum *values; bool* nulls; - /**********************************************************************/ - // OUT seq BIGINT, - // OUT path_seq, - // OUT node BIGINT, - // OUT edge BIGINT, - // OUT cost FLOAT, - // OUT agg_cost FLOAT) - - values = palloc(8 * sizeof(Datum)); nulls = palloc(8 * sizeof(bool)); @@ -292,16 +198,18 @@ _pgr_withpoints(PG_FUNCTION_ARGS) { nulls[i] = false; } + int64_t seq = funcctx->call_cntr == 0? 1 : result_tuples[funcctx->call_cntr - 1].start_id; values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); - values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq); + values[1] = Int32GetDatum((int32_t)seq); values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id); values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id); values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); - /**********************************************************************/ + + result_tuples[funcctx->call_cntr].start_id = result_tuples[funcctx->call_cntr].edge < 0? 1 : seq + 1; tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); @@ -310,4 +218,3 @@ _pgr_withpoints(PG_FUNCTION_ARGS) { SRF_RETURN_DONE(funcctx); } } - diff --git a/src/withPoints/pgr_withPoints.cpp b/src/withPoints/withPoints.cpp similarity index 99% rename from src/withPoints/pgr_withPoints.cpp rename to src/withPoints/withPoints.cpp index 6443697d9ab..9123fed8de4 100644 --- a/src/withPoints/pgr_withPoints.cpp +++ b/src/withPoints/withPoints.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: pgr_withPoints.cpp +File: withPoints.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "withPoints/pgr_withPoints.hpp" +#include "withPoints/withPoints.hpp" #include #include @@ -38,7 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "cpp_common/pgr_assert.h" +#include "cpp_common/assert.hpp" namespace pgrouting { diff --git a/src/withPoints/withPointsVia.c b/src/withPoints/withPointsVia.c index 6cb4793e6e4..fa4cdef2075 100644 --- a/src/withPoints/withPointsVia.c +++ b/src/withPoints/withPointsVia.c @@ -32,7 +32,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/debug_macro.h" #include "c_common/e_report.h" #include "c_common/time_msg.h" -#include "c_common/pgdata_getters.h" #include "drivers/withPoints/get_new_queries.h" #include "drivers/withPoints/withPointsVia_driver.h" @@ -44,7 +43,7 @@ void process( char* edges_sql, char* points_sql, - ArrayType *viasArr, + ArrayType *vias, bool directed, bool strict, bool U_turn_on_edge, @@ -59,55 +58,16 @@ process( driving_side[0] = estimate_drivingSide(driving_side[0]); - /* - * Processing Via - */ - size_t size_vias = 0; - int64_t* vias = pgr_get_bigIntArray(&size_vias, viasArr, false, &err_msg); - throw_error(err_msg, "While getting via vertices"); - - // 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, &err_msg); - throw_error(err_msg, points_sql); - 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, true, false, &err_msg); - throw_error(err_msg, edges_no_points_query); - pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg); - throw_error(err_msg, edges_of_points_query); - - {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(); - do_withPointsVia( - edges, total_edges, - points, total_points, - edges_of_points, total_edges_of_points, - vias, size_vias, + pgr_do_withPointsVia( + edges_no_points_query, + points_sql, + edges_of_points_query, + vias, directed, @@ -127,15 +87,8 @@ process( (*result_count) = 0; } - pgr_global_report(log_msg, notice_msg, err_msg); + pgr_global_report(&log_msg, ¬ice_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(); } @@ -145,10 +98,8 @@ _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; @@ -171,8 +122,6 @@ _pgr_withpointsvia(PG_FUNCTION_ARGS) { &result_tuples, &result_count); - /**********************************************************************/ - funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; @@ -206,7 +155,6 @@ _pgr_withpointsvia(PG_FUNCTION_ARGS) { nulls[i] = false; } - // postgres starts counting from 1 values[0] = Int32GetDatum((int32_t)call_cntr + 1); values[1] = Int32GetDatum(result_tuples[call_cntr].path_id); values[2] = Int32GetDatum(result_tuples[call_cntr].path_seq + 1); @@ -218,8 +166,6 @@ _pgr_withpointsvia(PG_FUNCTION_ARGS) { 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); diff --git a/src/withPoints/withPointsVia_driver.cpp b/src/withPoints/withPointsVia_driver.cpp index fe7a438e0de..9551c5a9bd7 100644 --- a/src/withPoints/withPointsVia_driver.cpp +++ b/src/withPoints/withPointsVia_driver.cpp @@ -30,13 +30,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #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" +#include "c_types/routes_t.h" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" +#include "dijkstra/dijkstraVia.hpp" +#include "withPoints/withPoints.hpp" namespace { @@ -90,21 +92,19 @@ get_route( } // namespace 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, +pgr_do_withPointsVia( + char *edges_sql, + char *points_sql, + char *edges_of_points_sql, + ArrayType* starts, bool directed, - char driving_side, bool details, - bool strict, bool U_turn_on_edge, - Routes_t** return_tuples, size_t* return_count, + Routes_t** return_tuples, size_t *return_count, char** log_msg, char** notice_msg, @@ -113,38 +113,45 @@ do_withPointsVia( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::pgget::get_intArray; std::ostringstream log; - std::ostringstream err; std::ostringstream notice; + std::ostringstream err; + char *hint = nullptr; try { - pgassert(total_edges != 0); pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert(*return_count == 0); - std::dequepaths; + auto via_vertices = get_intArray(starts, false); - graphType gType = directed? DIRECTED: UNDIRECTED; - /* - * processing via - */ - std::vector via_vertices(via_vidsArr, via_vidsArr + size_via_vidsArr); + + hint = points_sql; + auto points = pgrouting::pgget::get_points(std::string(points_sql)); + + hint = edges_of_points_sql; + auto edges_of_points = pgrouting::pgget::get_edges(std::string(edges_of_points_sql), true, false); + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); + + if (edges.size() + edges_of_points.size() == 0) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + /* * 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), + pgrouting::Pg_points_graph pg_graph(points, edges_of_points, true, driving_side, directed); @@ -157,12 +164,13 @@ do_withPointsVia( return; } - auto vertices(pgrouting::extract_vertices(edges, total_edges)); + auto vertices(pgrouting::extract_vertices(edges)); vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges()); + std::deque paths; if (directed) { - pgrouting::DirectedGraph digraph(vertices, gType); - digraph.insert_edges(edges, total_edges); + pgrouting::DirectedGraph digraph(vertices); + digraph.insert_edges(edges); digraph.insert_edges(pg_graph.new_edges()); pgrouting::pgr_dijkstraVia( digraph, @@ -172,8 +180,8 @@ do_withPointsVia( U_turn_on_edge, log); } else { - pgrouting::UndirectedGraph undigraph(vertices, gType); - undigraph.insert_edges(edges, total_edges); + pgrouting::UndirectedGraph undigraph(vertices); + undigraph.insert_edges(edges); undigraph.insert_edges(pg_graph.new_edges()); pgrouting::pgr_dijkstraVia( undigraph, @@ -215,6 +223,9 @@ do_withPointsVia( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/src/withPoints/withPoints_driver.cpp b/src/withPoints/withPoints_driver.cpp index 76e4c621524..914a258474b 100644 --- a/src/withPoints/withPoints_driver.cpp +++ b/src/withPoints/withPoints_driver.cpp @@ -35,16 +35,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include #include #include +#include "withPoints/withPoints.hpp" +#include "cpp_common/pgdata_getters.hpp" +#include "cpp_common/combinations.hpp" +#include "cpp_common/alloc.hpp" +#include "cpp_common/assert.hpp" #include "dijkstra/dijkstra.hpp" -#include "withPoints/pgr_withPoints.hpp" - -#include "cpp_common/combinations.h" -#include "cpp_common/pgr_alloc.hpp" -#include "cpp_common/pgr_assert.h" namespace { @@ -73,23 +74,16 @@ pgr_dijkstra( } // namespace -// CREATE OR REPLACE FUNCTION pgr_withPoint( -// edges_sql TEXT, -// points_sql TEXT, -// start_pid ANYARRAY, -// end_pid BIGINT, -// directed BOOLEAN DEFAULT true - -void -do_pgr_withPoints( - 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, - II_t_rt *combinationsArr, size_t total_combinations, - int64_t *start_vidsArr, size_t size_start_vidsArr, - int64_t *end_vidsArr, size_t size_end_vidsArr, +void +pgr_do_withPoints( + char *edges_sql, + char *points_sql, + char *edges_of_points_sql, + char *combinations_sql, + ArrayType *starts, + ArrayType *ends, char driving_side, bool details, @@ -106,25 +100,53 @@ do_pgr_withPoints( using pgrouting::pgr_alloc; using pgrouting::pgr_msg; using pgrouting::pgr_free; + using pgrouting::utilities::get_combinations; std::ostringstream log; std::ostringstream notice; std::ostringstream err; + char *hint = nullptr; + try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); - pgassert((*return_count) == 0); - pgassert(edges || edges_of_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), + pgassert(*return_count == 0); + + + + hint = combinations_sql; + auto combinations = get_combinations(combinations_sql, starts, ends, normal); + hint = nullptr; + + if (combinations.empty() && combinations_sql) { + *notice_msg = pgr_msg("No (source, target) pairs found"); + *log_msg = pgr_msg(combinations_sql); + return; + } + + + hint = points_sql; + auto points = pgrouting::pgget::get_points(std::string(points_sql)); + + hint = edges_of_points_sql; + auto edges_of_points = pgrouting::pgget::get_edges(std::string(edges_of_points_sql), normal, false); + + hint = edges_sql; + auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), normal, false); + + if (edges.size() + edges_of_points.size() == 0) { + *notice_msg = pgr_msg("No edges found"); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); + return; + } + hint = nullptr; + + /* + * processing points + */ + pgrouting::Pg_points_graph pg_graph(points, edges_of_points, normal, driving_side, directed); @@ -137,21 +159,13 @@ do_pgr_withPoints( return; } - auto combinations = total_combinations? - pgrouting::utilities::get_combinations(combinationsArr, total_combinations) - : pgrouting::utilities::get_combinations(start_vidsArr, size_start_vidsArr, end_vidsArr, size_end_vidsArr); - - auto vertices(pgrouting::extract_vertices(edges, total_edges)); + auto vertices(pgrouting::extract_vertices(edges)); vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges()); - graphType gType = directed? DIRECTED: UNDIRECTED; - - std::deque< Path > paths; - + std::deque paths; if (directed) { - log << "Working with directed Graph\n"; - pgrouting::DirectedGraph digraph(vertices, gType); - digraph.insert_edges(edges, total_edges); + pgrouting::DirectedGraph digraph(vertices); + digraph.insert_edges(edges); digraph.insert_edges(pg_graph.new_edges()); paths = pgr_dijkstra( @@ -159,9 +173,8 @@ do_pgr_withPoints( combinations, only_cost, normal); } else { - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(vertices, gType); - undigraph.insert_edges(edges, total_edges); + pgrouting::UndirectedGraph undigraph(vertices); + undigraph.insert_edges(edges); undigraph.insert_edges(pg_graph.new_edges()); paths = pgr_dijkstra( undigraph, @@ -170,9 +183,7 @@ do_pgr_withPoints( } if (!details) { - for (auto &path : paths) { - path = pg_graph.eliminate_details(path); - } + for (auto &path : paths) path = pg_graph.eliminate_details(path); } /* @@ -187,24 +198,20 @@ do_pgr_withPoints( return a.end_id() < b.end_id(); }); - size_t count(0); - count = count_tuples(paths); + auto 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)); - log << "Converting a set of paths into the tuples\n"; (*return_count) = (collapse_paths(return_tuples, paths)); - log << "************************************************"; - log << pg_graph.get_log(); - log << "************************************************"; - *log_msg = log.str().empty()? *log_msg : pgr_msg(log.str().c_str()); @@ -217,6 +224,9 @@ do_pgr_withPoints( err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); + } catch (const std::string &ex) { + *err_msg = pgr_msg(ex.c_str()); + *log_msg = hint? pgr_msg(hint) : pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; diff --git a/tools/developer/pumpup_version.sh b/tools/developer/pumpup_version.sh index fefdd62d851..92bb3abd2ce 100755 --- a/tools/developer/pumpup_version.sh +++ b/tools/developer/pumpup_version.sh @@ -26,36 +26,12 @@ IFS='\. ' read -r -a a <<< "${OLD_VERSION}" MAYOR="${a[0]}" MINOR="${a[1]}" -function pumpup_doc { - echo "pump up doc" - OLDSTR='^ \(`'"${1}"' (.*)\/'"${1}"'(.*)\)$' - NEWSTR=' \(`'"${2}"' $1\/'"${2}"'$2\)\n `'"${1}"' $1\/'"${1}"'$2' - for f in $(git ls-files './*.rst') - do - perl -pi -e 's/'"$OLDSTR"'/'"${NEWSTR}"'/' "$f" - done - WEBLINK=' /dev/null || exit 1 - #rm -rf doc/* + #rm -rf doc/* ; rm -rf locale/*/*/*.mo + rm -rf doc/* make doc + #example on how to only build spanish html + #make html-es + + # developers documentation #rm -rf doxygen/* make doxy popd > /dev/null || exit 1 } - -function test_compile { - - set_compiler "${GCC}" - - +function build { pushd build > /dev/null || exit 1 set_cmake - make -j 4 + #make -j 16 VERBOSE=1 + make -j 16 + #make sudo make install popd > /dev/null || exit 1 +} + +function test_compile { + + set_compiler "${GCC}" + + build echo -------------------------------------------- echo Execute tap_directories echo -------------------------------------------- for d in ${TAP_DIRS} do - bash taptest.sh "${d}" "-p ${PGPORT}" + time bash taptest.sh "${d}" "-p ${PGPORT}" done echo -------------------------------------------- @@ -133,10 +153,13 @@ function test_compile { echo -------------------------------------------- for d in ${QUERIES_DIRS} do - #tools/testers/doc_queries_generator.pl -alg "${d}" -documentation -pgport "${PGPORT}" - tools/testers/doc_queries_generator.pl -alg "${d}" -pgport "${PGPORT}" + #tools/testers/doc_queries_generator.pl -alg "docqueries/${d}" -documentation -pgport "${PGPORT}" + #tools/testers/doc_queries_generator.pl -alg "docqueries/${d}" -debug1 -pgport "${PGPORT}" + tools/testers/doc_queries_generator.pl -alg "docqueries/${d}" -pgport "${PGPORT}" done + build_doc + #exit 0 tap_test action_tests } diff --git a/tools/developer/taptest.sh b/tools/developer/taptest.sh index 539477d1b35..25777967ecc 100755 --- a/tools/developer/taptest.sh +++ b/tools/developer/taptest.sh @@ -37,7 +37,8 @@ QUIET="-v" QUIET="-q" PGDATABASE="___pgr___test___" -PGRVERSION="3.4.0 3.3.0 3.2.0 3.1.0 3.0.0" +PGRVERSION="3.6.1 3.6.0 3.5.1 3.5.0 3.2.0 3.1.3 3.0.6" +PGRVERSION="3.7.0" for v in ${PGRVERSION} @@ -53,11 +54,18 @@ do psql "$PGFLAGS" -d "$PGDATABASE" -X -q --set client_min_messages=WARNING --set ON_ERROR_STOP=1 --pset pager=off \ -c "CREATE EXTENSION IF NOT EXISTS pgtap; CREATE EXTENSION IF NOT EXISTS pgrouting WITH VERSION '${v}' CASCADE;" + echo "--------------------------" + echo " Installed version" + echo "--------------------------" + psql "${PGFLAGS}" -d "$PGDATABASE" -c "SELECT * FROM pgr_full_version();" + #psql "${PGFLAGS}" -d "$PGDATABASE" -c "SET client_min_messages TO DEBUG3; ALTER EXTENSION pgrouting UPDATE TO '3.7.0';" + echo "--------------------------" + echo " update version" + echo "--------------------------" psql "${PGFLAGS}" -d "$PGDATABASE" -c "SELECT * FROM pgr_full_version();" psql "${PGFLAGS}" -d "$PGDATABASE" -X -q --set client_min_messages=WARNING --set ON_ERROR_STOP=1 --pset pager=off \ -f sampledata.sql \ - -f vrppdtw_data.sql \ -f solomon_100_rc101.data.sql \ -f innerQuery.sql \ -f innerQuery_old.sql \ @@ -74,11 +82,13 @@ do -f types_check.sql \ -f via_compare.sql \ -f astar_pgtap_tests.sql \ + -f compare_dijkstra.sql \ + -f allpairs_tests.sql \ + -f contraction_tapfuncs.sql\ -f tsp_pgtap_tests.sql popd pg_prove "$QUIET" --normalize --directives --recurse "${PGFLAGS}" -d "${PGDATABASE}" "pgtap/${DIR}" - #pg_prove "$QUIET" --normalize --directive --recurse "${PGFLAGS}" -d "${PGDATABASE}" "../../pgtap/" #dropdb --if-exists "${PGFLAGS}" "${PGDATABASE}" done diff --git a/tools/release-scripts/notes2news.pl b/tools/release-scripts/notes2news.pl index 8789dc3539b..b02d084ff02 100755 --- a/tools/release-scripts/notes2news.pl +++ b/tools/release-scripts/notes2news.pl @@ -143,7 +143,7 @@ sub find_stuff { next if $line =~ /$mstart/; $line =~ s/[\|]+//g; $line =~ s/($check)/$conversions{$1}/go; - print $ofh " $line" if $line !~ /$mend/; + print $ofh " $line" if $line !~ /$mend/ && $line ne "\n"; last if $line =~ /$mend/; } close($fh); diff --git a/tools/scripts/code_checker.sh b/tools/scripts/code_checker.sh index 65384675137..a7ef24cf22c 100755 --- a/tools/scripts/code_checker.sh +++ b/tools/scripts/code_checker.sh @@ -43,23 +43,25 @@ if ! test -d code_linter; then fi DIRECTORY="$1" +INCLUDE_ORDER="-build/include_order:src/cpp_common/pgdata_getters.cpp,-build/include_order:include/cpp_common/get_data.hpp" if test -z "$DIRECTORY"; then echo "--------------------" echo "------ *.c ------" echo "--------------------" - code_linter/cpplint/cpplint.py --extensions=c --linelength=120 --filter=-readability/casting,-whitespace/newline src/*/*.c + code_linter/cpplint/cpplint.py --extensions=c --linelength=120 --filter=-readability/casting src/*/*.c echo "--------------------" echo "------ *.cpp ------" echo "--------------------" code_linter/cpplint/cpplint.py --linelength=120 \ - --filter=-runtime/references,-whitespace/indent_namespace \ - src/*/*.cpp + --filter=-readability/nolint,-runtime/references,-whitespace/indent_namespace,"${INCLUDE_ORDER}" \ + --linelength=120 src/*/*.cpp + echo "--------------------" echo "------ HEADERS ------" echo "--------------------" code_linter/cpplint/cpplint.py --extensions=hpp,h --headers=hpp,h --linelength=120 \ - --filter=-runtime/references,-whitespace/indent_namespace \ + --filter=-runtime/references,-whitespace/indent_namespace,"${INCLUDE_ORDER}" \ include/*/*.h* \ include/*/*/*.h* @@ -70,7 +72,7 @@ else echo "------ IN PLACE HEADERS ------" echo "--------------------" code_linter/cpplint/cpplint.py --extensions=hpp,h --headers=hpp,h --linelength=120 \ - --filter=-runtime/references \ + --filter=-runtime/references,-whitespace/indent_namespace,"${INCLUDE_ORDER}" \ include/*/*.h* \ include/*/*/*.h* @@ -86,8 +88,9 @@ else echo "------ *.cpp ------" echo "--------------------" code_linter/cpplint/cpplint.py --linelength=120 \ - --filter=-runtime/references \ + --filter=-runtime/references,-whitespace/indent_namespace,"${INCLUDE_ORDER}" \ src/"$DIRECTORY"/*.cpp + echo "--------------------" echo "------ C HEADER ------" echo "--------------------" @@ -99,7 +102,7 @@ else echo "------ C++ HEADER ------" echo "--------------------" code_linter/cpplint/cpplint.py --extensions=hpp,h --headers=hpp,h --linelength=120 \ - --filter=-runtime/references \ + --filter=-runtime/references,-whitespace/indent_namespace,"${INCLUDE_ORDER}" \ include/"$DIRECTORY"/*.h* fi fi diff --git a/tools/scripts/test_license.sh b/tools/scripts/test_license.sh index 0bb937e1a6c..c4c0e7553f4 100755 --- a/tools/scripts/test_license.sh +++ b/tools/scripts/test_license.sh @@ -30,7 +30,7 @@ pushd "${DIR}" > /dev/null || exit missing1=$(mylicensecheck doc | grep "No copyright") missing2=$(grep --files-without-match 'Creative Commons' doc/*/*.rst) missing3=$(mylicensecheck docqueries | grep "No copyright") -missing4=$(grep --files-without-match 'Creative Commons' docqueries/*/*.sql) +missing4=$(grep --files-without-match 'Creative Commons' docqueries/*/*.pg) popd > /dev/null || exit #mylicensecheck doc diff --git a/tools/testers/doc_queries_generator.pl b/tools/testers/doc_queries_generator.pl index f145aef0d79..34cb9b5628a 100755 --- a/tools/testers/doc_queries_generator.pl +++ b/tools/testers/doc_queries_generator.pl @@ -1,7 +1,7 @@ #! /usr/bin/perl -w =pod -File: aplgorithm testes +File: doc_queries_generator.pl Copyright (c) 2013 pgRouting developers @@ -48,13 +48,11 @@ *dir = *File::Find::dir; *prune = *File::Find::prune; -my $POSGRESQL_MIN_VERSION = '9.2'; +my $POSGRESQL_MIN_VERSION = '12'; my $DOCUMENTATION = 0; -my $INTERNAL_TESTS = 0; +my $DATA = 0; my $VERBOSE = 0; -my $DRYRUN = 0; -my $DEBUG = 0; -my $DEBUG1 = 0; +my $LEVEL = "NOTICE"; my $FORCE = 0; my $DBNAME = "pgr_test__db__test"; @@ -64,35 +62,30 @@ sub Usage { die "Usage: doc_queries_generator.pl -pgver vpg -pgisver vpgis -psql /path/to/psql\n" . - " -pgver vpg - postgresql version\n" . + " -alg 'dir' - directory to select which algorithm subdirs to test\n" . + " -pgver version - postgresql version\n" . " -pghost host - postgresql host or socket directory to use\n" . " -pgport port - postgresql port to use\n" . " -pguser username - postgresql user role to use\n" . - " -pgisver vpgis - postgis version\n" . - " -pgrver vpgr - pgrouting version\n" . + " -dbname name - Database name defaults to $DBNAME\n" . + " -pgrver version - pgrouting version. (Not all compares will pass)\n" . " -psql /path/to/psql - optional path to psql\n" . - " -v - verbose messages for small debuging\n" . - " -dbg - use when CMAKE_BUILD_TYPE = DEBUG\n" . - " -debug - verbose messages for debuging(enter twice for more)\n" . - " -debug1 - DEBUG1 messages (for timing reports)\n" . - " -clean - dropdb pgr_test__db__test\n" . - " -ignorenotice - ignore NOTICE statements when reporting failures\n" . - " -alg 'dir' - directory to select which algorithm subdirs to test\n" . - " -documentation - ONLY generate documentation examples\n" . - " -force - Force tests for unsupported versions >= 9.1 of postgreSQL \n" . - " -h - help\n"; + " -data - only install the sampledata.\n" . + " -l(evel) NOTICE - client_min_messages value. Defaults to $LEVEL. other values can be WARNING, DEBUG3, etc\n" . + " -c(lean) - dropdb before running.\n" . + " -doc(umentation) - ONLY generate documentation examples. LEVEL is set to NOTICE\n" . + " -v(erbose) - verbose messages of the execution\n" . + " -h(elp) - help\n"; } print "RUNNING: doc_queries_generator.pl " . join(" ", @ARGV) . "\n"; -my ($vpg, $postgis_ver, $vpgr, $psql); +my ($vpg, $vpgr, $psql); my $alg = ''; my @testpath = ("docqueries/"); my @test_direcotry = (); my $clean; -my $ignore; -$postgis_ver = ''; while (my $a = shift @ARGV) { if ( $a eq '-pgver') { @@ -107,37 +100,32 @@ sub Usage { elsif ($a eq '-pguser') { $DBUSER = shift @ARGV || Usage(); } - elsif ($a eq '-pgisver') { - $postgis_ver = shift @ARGV || Usage(); - $postgis_ver = " VERSION '$postgis_ver'"; - } elsif ($a eq '-pgrver') { $vpgr = shift @ARGV || Usage(); } elsif ($a eq '-alg') { $alg = shift @ARGV || Usage(); - @testpath = ("docqueries/$alg"); + @testpath = ("$alg"); + } + elsif ($a eq '-dbname') { + $DBNAME = shift @ARGV || Usage(); } elsif ($a eq '-psql') { $psql = shift @ARGV || Usage(); die "'$psql' is not executable!\n" unless -x $psql; } + elsif ($a eq '-data') { + $DATA = 1; + } elsif ($a =~ /^-h/) { Usage(); } - elsif ($a =~ /^-clean/) { - $clean = 1;; - } - elsif ($a =~ /^-ignoren/i) { - $ignore = 1;; + elsif ($a =~ /^-c/i) { + $clean = 1; } - elsif ($a =~ /^-debug1$/i) { - $DEBUG1 = 1 unless $DOCUMENTATION; - } - elsif ($a =~ /^-debug$/i) { - $DEBUG++; - $VERBOSE = 1; + elsif ($a =~ /^-l$/i) { + $LEVEL = $psql = shift @ARGV || Usage(); } elsif ($a =~ /^-v/i) { $VERBOSE = 1; @@ -147,10 +135,6 @@ sub Usage { } elsif ($a =~ /^-doc(umentation)?/i) { $DOCUMENTATION = 1; - $DEBUG1 = 0; # disbale timing reports during documentation generation - } - elsif ($a =~ /^-dbg/i) { - $INTERNAL_TESTS = 1; #directory internalQueryTests is also tested } else { warn "Error: unknown option '$a'\n"; @@ -158,16 +142,18 @@ sub Usage { } } +# documentation gets NOTICE +$LEVEL = "NOTICE" if $DOCUMENTATION; + my $connopts = ""; $connopts .= " -U $DBUSER" if defined $DBUSER; $connopts .= " -h $DBHOST" if defined $DBHOST; $connopts .= " -p $DBPORT" if defined $DBPORT; - -mysystem("dropdb $connopts $DBNAME") if $clean; +print "connoptions '$connopts'\n" if $VERBOSE; %main::tests = (); my @cfgs = (); -my %stats = (z_pass=>0, z_fail=>0, z_crash=>0); +my %stats = (z_pass=>0, z_fail=>0, z_crash=>0,RunTimeTotal=>0); my $TMP = "/tmp/pgr-test-runner-$$"; my $TMP2 = "/tmp/pgr-test-runner-$$-2"; my $TMP3 = "/tmp/pgr-test-runner-$$-3"; @@ -186,15 +172,19 @@ sub Usage { print "Operative system found: $OS\n"; +createTestDB($DBNAME); + +# Load the sample data & any other relevant data files +mysystem("$psql $connopts -A -t -q -f tools/testers/sampledata.sql $DBNAME >> $TMP2 2>\&1 "); + +if ($DATA) {exit 0;}; + # Traverse desired filesystems File::Find::find({wanted => \&want_tests}, @testpath); -die "Error: no test files found. Run this command from the top level pgRouting directory!\n" unless @cfgs; - -createTestDB($DBNAME); +die "Error: no queries files found. Run this command from the top path of pgRouting repository!\n" unless @cfgs; $vpg = '' if ! $vpg; -$postgis_ver = '' if ! $postgis_ver; # cfgs = SET of configuration file names # c one file in cfgs @@ -209,22 +199,14 @@ sub Usage { print Data::Dumper->Dump([\%main::tests],['test']) if $VERBOSE; - if ($main::tests{any} && !$DOCUMENTATION) { - push @{$stats{$c}}, run_test($c, $main::tests{any}); - $found++; - } - elsif ($main::tests{any}{documentation} && $DOCUMENTATION) { - push @{$stats{$c}}, run_test($c, $main::tests{any}); - $found++; - } + run_test($c, $main::tests{any}); + $found++; if (! $found) { - $stats{$c} = "No tests were found for '$vpg-$postgis_ver'!"; + $stats{$c} = "No files found for '$c'!"; } } -dropTestDB(); - print Data::Dumper->Dump([\%stats], ['stats']); unlink $TMP; @@ -238,237 +220,197 @@ sub Usage { exit 0; # signal we passed all the tests -# c one file in cfgs +# file one file in cfgs # t contents of array that has keys comment, data and test sub run_test { - my $c = shift; + my $confFile = shift; my $t = shift; - my %res = (); - - my $dir = dirname($c); - $res{comment} = $t->{comment} if $t->{comment}; - #t->{data} referencing the key data of the data files + my $dir = dirname($confFile); - my $singleDB = "____pgr___single_test___"; - for my $testName (@{$t->{singleTest}}) { - createTestDB($singleDB); - mysystem("$psql $connopts -A -t -q -f tools/testers/sampledata.sql' $singleDB >> $TMP2 2>\&1 "); - for my $x (@{$t->{data}}) { - mysystem("$psql $connopts -A -t -q -f '$dir/$x' $singleDB >> $TMP2 2>\&1 "); - } - process_single_test($testName, $dir, $singleDB,\%res); - mysystem("dropdb $connopts $singleDB"); + # There is data to load relative to the directory + for my $datafile (@{$t->{data}}) { + mysystem("$psql $connopts -A -t -q -f '$dir/$datafile' $DBNAME >> $TMP2 2>\&1 "); } - mysystem("$psql $connopts -A -t -q -f tools/testers/sampledata.sql $DBNAME >> $TMP2 2>\&1 "); - for my $x (@{$t->{data}}) { - mysystem("$psql $connopts -A -t -q -f '$dir/$x' $DBNAME >> $TMP2 2>\&1 "); + for my $file (@{$t->{files}}) { + process_single_test($file, $dir, $DBNAME); } - if ($INTERNAL_TESTS) { - for my $x (@{$t->{debugtests}}) { - process_single_test($x, $dir,, $DBNAME, \%res) + # Just in case but its not used + if ($OS =~/msys/ || $OS=~/MSW/ || $OS =~/cygwin/) { + for my $x (@{$t->{windows}}) { + process_single_test($x, $dir, $DBNAME) } - } - if ($DOCUMENTATION) { - for my $x (@{$t->{documentation}}) { - process_single_test($x, $dir,, $DBNAME, \%res); - my $cmd = q(perl -pi -e 's/[ \t]+$//'); - $cmd .= " $dir/$x.result"; - mysystem( $cmd ); + } elsif ($OS=~/Mac/ || $OS=~/dar/) { + for my $x (@{$t->{macos}}) { + process_single_test($x, $dir, $DBNAME) } - } - else { - for my $x (@{$t->{tests}}) { - process_single_test($x, $dir,, $DBNAME, \%res) - } - if ($OS =~/msys/ || $OS=~/MSW/ || $OS =~/cygwin/) { - for my $x (@{$t->{windows}}) { - process_single_test($x, $dir,, $DBNAME, \%res) - } - } elsif ($OS=~/Mac/ || $OS=~/dar/) { - for my $x (@{$t->{macos}}) { - process_single_test($x, $dir,, $DBNAME, \%res) - } - } else { - for my $x (@{$t->{linux}}) { - process_single_test($x, $dir,, $DBNAME, \%res) - } + } else { + for my $x (@{$t->{linux}}) { + process_single_test($x, $dir, $DBNAME) } } - - return \%res; } +# file: file to be processed. Example: johnson.pg +# dir: apth of the file. Example: docqueries/allpairs/ +# database: the database name: Example: pgr_test__db__test +# each tests will use clean data + sub process_single_test{ - my $x = shift; + my $file = shift; my $dir = shift; my $database = shift; - my $res = shift; - #each tests will use clean data - print "Processing queries $dir/$x"; + (my $filename = $file) =~ s/((\.[^.\s]+)+)$//; + my $inputFile = "$dir/$file"; + my $resultsFile = "$dir/$filename.result"; + + print "Processing $inputFile"; my $t0 = [gettimeofday]; - #TIN = test_input_file - open(TIN, "$dir/$x.test.sql") || do { - $res->{"$dir/$x.test.sql"} = "FAILED: could not open '$dir/$x.test.sql' : $!"; + + # Load the sample data & any other relevant data files + mysystem("$psql $connopts -A -t -q -f tools/testers/sampledata.sql $DBNAME >> $TMP2 2>\&1 "); + + # TIN = test input file + open(TIN, "$inputFile") || do { + print "\tFAILED: could not open '$inputFile \n"; + $stats{"$inputFile"} = "FAILED: could not open '$inputFile' : $!"; $stats{z_fail}++; - next; + return; }; - my $level = "NOTICE"; - $level = "WARNING" if $ignore; - $level = "DEBUG3" if $DEBUG1; + # Processing is handled kinda like a file + # Where the commands are stored on PSQL file + # When the PSQL is closed is when everything gets executed + # Connect to the database with PSQL if ($DOCUMENTATION) { - open(PSQL, "|$psql $connopts --set='VERBOSITY terse' -e $database > $dir/$x.result 2>\&1 ") || do { - $res->{"$dir/$x.test.sql"} = "FAILED: could not open connection to db : $!"; + # For rewriting the results files + # Do the rewrite or store FAILURE + open(PSQL, "|$psql $connopts --set='VERBOSITY terse' -e $database > $resultsFile 2>\&1 ") || do { + $stats{"$inputFile"} = "FAILED: could not open connection to db : $!"; + $stats{z_fail}++; next; }; - } - else { - #open(PSQL, "|$psql $connopts --set='VERBOSITY terse' -e $database > $dir/$x.result 2>\&1 ") || do { - # $res->{"$dir/$x.test.sql"} = "FAILED: could not open connection to db : $!"; - # $stats{z_fail}++; - # next; - #}; - + } else { + # For comparing the result + # Create temp file with current results open(PSQL, "|$psql $connopts --set='VERBOSITY terse' -e $database > $TMP 2>\&1 ") || do { - $res->{"$dir/$x.test.sql"} = "FAILED: could not open connection to db : $!"; - if (!$INTERNAL_TESTS) { - $stats{z_fail}++; - } + $stats{"$inputFile"} = "FAILED: could not open connection to db : $!"; + $stats{z_fail}++; next; }; } - - my @d = (); - @d = ; #reads the whole file into the array @d + # Read the whole (input) file into the array @d + my @queries = (); + @queries = ; print PSQL "BEGIN;\n"; - print PSQL "SET client_min_messages TO $level;\n"; - #prints the whole fle stored in @d - print PSQL @d; + print PSQL "SET client_min_messages TO $LEVEL;\n"; + # prints the whole fle stored in @queries + print PSQL @queries; print PSQL "\nROLLBACK;"; # executes everything close(PSQL); + #closes the input file /TIN = test input close(TIN); + my $runTime = tv_interval($t0, [gettimeofday]); + print "\tRun time: $runTime"; + $stats{RunTimeTotal} += $runTime; + if ($DOCUMENTATION) { + # convert tabs to spaces print "\n"; + my $cmd = q(perl -pi -e 's/[ \t]+$//'); + $cmd .= " $resultsFile"; + mysystem( $cmd ); return; } - my $dfile; - my $dfile2; - if ($ignore) { #decide how to compare results, if ignoring or not ignoring - $dfile2 = $TMP2; - mysystem("grep -v NOTICE '$TMP' | grep -v '^CONTEXT:' | grep -v '^PL/pgSQL function' | grep -v '^COPY' > $dfile2"); - $dfile = $TMP3; - mysystem("grep -v NOTICE '$dir/$x.result' | grep -v '^CONTEXT:' | grep -v '^PL/pgSQL function' | grep -v '^COPY' > $dfile"); - } - elsif ($DEBUG1) { #to delete CONTEXT lines - $dfile2 = $TMP2; - mysystem("grep -v '^CONTEXT:' '$TMP' | grep -v '^PL/pgSQL function' | grep -v '^COPY' > $dfile2"); - $dfile = $TMP3; - mysystem("grep -v '^CONTEXT:' '$dir/$x.result' | grep -v '^PL/pgSQL function' | grep -v '^COPY' > $dfile"); - } - else { - $dfile2 = $TMP2; - mysystem("grep -v '^COPY' '$TMP' | grep -v 'psql:tools' > $dfile2"); - $dfile = $TMP3; - mysystem("grep -v '^COPY' '$dir/$x.result' | grep -v 'psql:tools' > $dfile"); - } - if (! -f "$dir/$x.result") { - $res->{"$dir/$x.test.sql"} = "\nFAILED: result file missing : $!"; + if (! -f "$resultsFile") { + $stats{"$inputFile"} = "\nFAILED: '$resultsFile` file missing : $!"; $stats{z_fail}++; next; } - # use diff -w to ignore white space differences like \r vs \r\n - #ignore white spaces when comparing - #dfile is expected results - #dfile2 is the actual results - my $r = `diff -w '$dfile' '$dfile2' `; + # diff ignore white spaces when comparing + my $originalDiff = `diff -w '$resultsFile' '$TMP' `; + #looks for removing leading blanks and trailing blanks - $r =~ s/^\s*|\s*$//g; - if ($r =~ /connection to server was lost/) { - $res->{"$dir/$x.test.sql"} = "CRASHED SERVER: $r"; + $originalDiff =~ s/^\s*|\s*$//g; + if ($originalDiff =~ /connection to server was lost/) { + # when the server crashed + $stats{"$inputFile"} = "CRASHED SERVER: $originalDiff"; $stats{z_crash}++; # allow the server some time to recover from the crash - warn "CRASHED SERVER: '$dir/$x.test.sql', sleeping 5 ...\n"; + warn "CRASHED SERVER: '$inputFile', sleeping 5 ...\n"; sleep 20; - } - #if the diff has 0 length then everything was the same, so here we detect changes - elsif (length($r)) { - $res->{"$dir/$x.test.sql"} = "FAILED: $r"; - $stats{z_fail}++ unless $DEBUG1; + } elsif (length($originalDiff)) { + # Things changed print the diff + $stats{"$inputFile"} = "FAILED: $originalDiff"; + $stats{z_fail}++ unless $LEVEL ne "NOTICE"; print "\t FAIL\n"; - } - else { - $res->{"$dir/$x.test.sql"} = "Passed"; + } else { $stats{z_pass}++; print "\t PASS\n"; } - print " test run time: " . tv_interval($t0, [gettimeofday]) . "\n"; } sub createTestDB { + print "-> createTestDB\n" if $VERBOSE; my $databaseName = shift; - dropTestDB() if dbExists($databaseName); + dropTestDB() if $clean && dbExists($databaseName); my $template; my $dbver = getServerVersion(); my $dbshare = getSharePath($dbver); - if ($DEBUG) { - print "-- DBVERSION: $dbver\n"; - print "-- DBSHARE: $dbshare\n"; + if ($VERBOSE) { + print "\tDBVERSION: $dbver\n"; + print "\tDBSHARE: $dbshare\n"; } die " Unsupported postgreSQL version $dbver Minimum requierment is $POSGRESQL_MIN_VERSION version Use -force to force the tests\n" - unless version_greater_eq($dbver, $POSGRESQL_MIN_VERSION) or ($FORCE and version_greater_eq($dbver, '9.1')); - - die "postGIS extension $postgis_ver not found\n" - unless -f "$dbshare/extension/postgis.control"; - + unless version_greater_eq($dbver, $POSGRESQL_MIN_VERSION); # Create a database with postgis installed in it - mysystem("createdb $connopts $databaseName"); - die "ERROR: Failed to create database '$databaseName'!\n" - unless dbExists($databaseName); + mysystem("createdb $connopts $databaseName") if !dbExists($databaseName); + die "ERROR: Failed to create database '$databaseName'!\n" unless dbExists($databaseName); my $encoding = ''; if ($OS =~ /msys/ || $OS =~ /MSWin/) { $encoding = "SET client_encoding TO 'UTF8';"; } - print "-- Installing postgis extension $postgis_ver\n" if $DEBUG; - mysystem("$psql $connopts -c \"$encoding CREATE EXTENSION postgis $postgis_ver \" $databaseName"); # Install pgrouting into the database my $myver = ''; if ($vpgr) { $myver = " VERSION '$vpgr'"; } - print "Installing pgrouting extension $myver\n" if $DEBUG; - mysystem("$psql $connopts -c \"CREATE EXTENSION pgrouting $myver\" $databaseName"); + + + mysystem("$psql $connopts -c \"DROP EXTENSION IF EXISTS pgrouting $myver\" $databaseName "); + + print "Installing pgrouting extension $myver\n" if $VERBOSE; + mysystem("$psql $connopts -c \"CREATE EXTENSION pgrouting $myver CASCADE\" $databaseName"); # Verify pgrouting was installed my $pgrv = `$psql $connopts -c "select pgr_version()" $databaseName`; - die "ERROR: failed to install pgrouting into the database!\n" - unless $pgrv; + die "ERROR: failed to install pgrouting into the database!\n" unless $pgrv; - print `$psql $connopts -c "select version();" postgres `, "\n"; + print `$psql $connopts -c "select version();" $databaseName `, "\n"; print `$psql $connopts -c "select postgis_full_version();" $databaseName `, "\n"; print `$psql $connopts -c "select pgr_full_version();" $databaseName `, "\n"; } @@ -501,13 +443,14 @@ sub version_greater_eq { sub getServerVersion { + print "-> getServerVersion\n" if $VERBOSE; my $v = `$psql $connopts -q -t -c "select version()" postgres`; - print "$psql $connopts -q -t -c \"select version()\" postgres\n # RETURNED: $v\n" if $VERBOSE; + print "\t$psql $connopts -q -t -c \"select version()\" postgres\n # RETURNED: $v\n" if $VERBOSE; if ($v =~ m/PostgreSQL (\d+(\.\d+)?)/) { my $version = $1 + 0; - print " Got: $version\n" if $VERBOSE; + print "\tGot: $version\n" if $VERBOSE; $version = int($version) if $version >= 10; - print " Got: $version\n" if $VERBOSE; + print "\tGot: $version\n" if $VERBOSE; return $version; } return undef; @@ -565,17 +508,13 @@ sub getSharePath { sub mysystem { my $cmd = shift; - print "$cmd\n" if $VERBOSE || $DRYRUN; - system($cmd) unless $DRYRUN; + print "$cmd\n" if $VERBOSE; + system($cmd); } sub want_tests { -# /^bd_d.*\z/s && -# ($File::Find::prune = 1) -# || /^test\.conf\z/s && push @cfgs, $name; - #print join("\n",@cfgs),"\n"; } diff --git a/tools/testers/no_crash_test.sql b/tools/testers/no_crash_test.sql index f8a4c1ed6d1..fb30370f131 100644 --- a/tools/testers/no_crash_test.sql +++ b/tools/testers/no_crash_test.sql @@ -35,7 +35,7 @@ BEGIN IF i = 0 THEN RETURN query SELECT * FROM isnt_empty(q1, 'isnt_empty ' || q1); ELSE - IF func='pgr_alphashape' THEN + IF func='pgr_alphashape' OR func='pgr_isplanar' THEN RETURN query SELECT * FROM isnt_empty(q1, 'isnt_empty' || q1); ELSIF func='pgr_maxFlow' OR func='pgr_maxFlowMinCost_Cost' THEN RETURN query SELECT * FROM set_eq(q1, 'SELECT NULL::BIGINT', 'set_eq' || q1); diff --git a/tools/testers/pg_prove_tests.sh b/tools/testers/pg_prove_tests.sh index 28c36d38828..672489585ef 100755 --- a/tools/testers/pg_prove_tests.sh +++ b/tools/testers/pg_prove_tests.sh @@ -37,15 +37,14 @@ echo "$PGPORT" pushd ./tools/testers/ || exit 1 -bash setup_db.sh "${PGPORT}" "${PGDATABASE}" "${PGUSER}" "3.6.3" +bash setup_db.sh "${PGPORT}" "${PGDATABASE}" "${PGUSER}" "3.7.0" -pg_prove --failures --Q --recurse \ - --S client_min_messages=WARNING \ - --S on_error_rollback=off \ - --S on_error_stop=true \ - --P format=unaligned \ - --P tuples_only=true \ - --P pager=off \ +PGOPTIONS="-c client_min_messages=WARNING" pg_prove --failures --Q --recurse \ + -S on_error_rollback=off \ + -S on_error_stop=true \ + -P format=unaligned \ + -P tuples_only=true \ + -P pager=off \ -p "$PGPORT" -d "$PGDATABASE" -U "$PGUSER" ../../pgtap/ popd diff --git a/tools/testers/spanningtree.sql b/tools/testers/spanningtree.sql index 98a068a3c16..b7f0d74bd9a 100644 --- a/tools/testers/spanningtree.sql +++ b/tools/testers/spanningtree.sql @@ -31,6 +31,8 @@ BEGIN RETURN QUERY SELECT function_returns(fn, ARRAY['text','bigint','bigint'], 'setof record'); RETURN QUERY SELECT function_returns(fn, ARRAY['text','anyarray','bigint'], 'setof record'); + IF NOT min_version('3.7.0') THEN + RETURN QUERY SELECT set_eq( format($$SELECT proargnames FROM pg_proc WHERE proname = %1$L$$,fn), $$VALUES @@ -46,6 +48,24 @@ BEGIN $$ ); + ELSE + + RETURN QUERY SELECT set_eq( + format($$SELECT proargnames FROM pg_proc WHERE proname = %1$L$$,fn), + $$VALUES + ('{"","","max_depth","seq","depth","start_vid","pred","node","edge","cost","agg_cost"}'::TEXT[]) + $$ + ); + + RETURN QUERY SELECT set_eq( + format($$SELECT proallargtypes FROM pg_proc WHERE proname = %1$L$$, fn), + $$VALUES + ('{25,20,20,20,20,20,20,20,20,701,701}'::OID[]), + ('{25,2277,20,20,20,20,20,20,20,701,701}'::OID[]) + $$ + ); + + END IF; END; $BODY$ LANGUAGE plpgsql VOLATILE; @@ -67,6 +87,8 @@ BEGIN RETURN QUERY SELECT function_returns(fn, ARRAY['text','bigint','double precision'], 'setof record'); RETURN QUERY SELECT function_returns(fn, ARRAY['text','anyarray','double precision'], 'setof record'); + IF NOT min_version('3.7.0') THEN + RETURN QUERY SELECT set_eq( format($$SELECT proargnames FROM pg_proc WHERE proname = %1$L$$,fn), $$VALUES @@ -85,6 +107,29 @@ BEGIN ('{25,2277,701,20,20,20,20,20,701,701}'::OID[]) $$ ); + + ELSE + + RETURN QUERY SELECT set_eq( + format($$SELECT proargnames FROM pg_proc WHERE proname = %1$L$$,fn), + $$VALUES + ('{"","","","seq","depth","start_vid","pred","node","edge","cost","agg_cost"}'::TEXT[]) + $$ + ); + + RETURN QUERY SELECT set_eq( + format($$SELECT proallargtypes FROM pg_proc WHERE proname = %1$L$$, fn), + $$VALUES + ('{25,20,701,20,20,20,20,20,20,701,701}'::OID[]), + ('{25,2277,701,20,20,20,20,20,20,701,701}'::OID[]), + ('{25,20,1700,20,20,20,20,20,20,701,701}'::OID[]), + ('{25,2277,1700,20,20,20,20,20,20,701,701}'::OID[]), + ('{25,20,701,20,20,20,20,20,20,701,701}'::OID[]), + ('{25,2277,701,20,20,20,20,20,20,701,701}'::OID[]) + $$ + ); + + END IF; END; $BODY$ LANGUAGE plpgsql VOLATILE;