### pg_kruskalDFS Multiple Vertices Example (SQL) Source: https://docs.pgrouting.org/latest/zh_Hans/migration Demonstrates how to use the pgr_kruskalDFS function with multiple starting vertices. The example shows the output before and after explicitly enumerating columns, highlighting the new 'depth' and 'pred' columns introduced in newer versions. ```sql SELECT * FROM pgr_kruskalDFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', ARRAY[9, 6], max_depth => 3); ``` ```sql 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', ARRAY[9, 6], max_depth => 3); ``` -------------------------------- ### Install pgRouting Compilation Dependencies on Linux (Debian/Ubuntu) Source: https://docs.pgrouting.org/latest/en/pgRouting-installation Example commands using apt to install the necessary build tools and libraries for compiling pgRouting on a Debian-based Linux system. Includes essential build tools, Boost Graph Library, PostgreSQL development files, and PostGIS. ```bash sudo apt install \ build-essential \ libboost-graph-dev \ postgresql-13 \ postgresql-server-dev-13 \ postgresql-13-postgis ``` -------------------------------- ### pgr_dijkstra Example Source: https://docs.pgrouting.org/latest/en/migration Demonstrates the usage of the pgr_dijkstra function for finding shortest paths. ```APIDOC ## GET /websites/pgrouting/pgr_dijkstra ### Description This endpoint demonstrates the usage of the `pgr_dijkstra` function, which calculates the shortest path between nodes in a graph. This is a standard implementation of Dijkstra's algorithm for finding the shortest path in a weighted graph. ### Method GET ### Endpoint `/websites/pgrouting/pgr_dijkstra` ### Parameters #### Query Parameters - **edges_query** (string) - Required - A SQL query string that returns the graph edges with columns: `id`, `source`, `target`, `cost`, `reverse_cost`. - **start_nodes** (array of integers) - Required - An array of starting node IDs. - **end_node** (integer) - Required - The target node ID. ### Request Example ```sql SELECT * FROM pgr_dijkstra( $$SELECT id, source, target, cost, reverse_cost FROM edges$$); ``` ### Response #### Success Response (200) - **seq** (integer) - Sequence number of the path segment. - **path_seq** (integer) - Sequence number within the path. - **start_vid** (integer) - The starting vertex ID for this segment. - **end_vid** (integer) - The ending vertex ID for this segment. - **node** (integer) - The current node ID in the path. - **edge** (integer) - The ID of the edge traversed. - **cost** (float) - The cost of traversing the edge. - **agg_cost** (float) - The accumulated cost to reach this node. #### Response Example ```json [ { "seq": 1, "path_seq": 1, "start_vid": 1, "end_vid": 17, "node": 1, "edge": 6, "cost": 1, "agg_cost": 0 }, { "seq": 2, "path_seq": 2, "start_vid": 1, "end_vid": 17, "node": 3, "edge": 7, "cost": 1, "agg_cost": 1 } ] ``` #### Response Example (Enumerated Columns) ```json [ { "seq": 1, "path_seq": 1, "start_vid": 1, "node": 1, "edge": 6, "cost": 1, "agg_cost": 0 }, { "seq": 2, "path_seq": 2, "start_vid": 1, "node": 3, "edge": 7, "cost": 1, "agg_cost": 1 } ] ``` ``` -------------------------------- ### pgr_drivingDistance Single Vertex Example (SQL) Source: https://docs.pgrouting.org/latest/zh_Hans/migration Illustrates the usage of the pgr_drivingDistance function for a single starting vertex. The example shows the output before and after explicitly selecting columns, demonstrating the default output format. ```sql SELECT * FROM pgr_drivingDistance( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, 11, 3.0); ``` ```sql SELECT seq, node, edge, cost, agg_cost FROM pgr_drivingDistance( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, 11, 3.0); ``` -------------------------------- ### pgr_withPointsDD Example Migration (SQL) Source: https://docs.pgrouting.org/latest/en/migration Demonstrates the migration of a pgr_withPointsDD example from an older version of pgRouting to a newer one. It highlights changes in the SQL query, specifically the enumeration of output columns and the handling of the 'driving side' parameter. The output table also shows the difference in results after the update. ```sql SELECT * FROM pgr_withPointsDD( $$SELECT * FROM edges ORDER BY id$$$$SELECT pid, edge_id, fraction, side from pointsOfInterest$$, ARRAY[-1, 16], 3.3, 'l', equicost => true); ``` ```sql SELECT seq, start_vid, node, edge, cost, agg_cost FROM pgr_withPointsDD( $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$, $$SELECT pid, edge_id, fraction, side from pointsOfInterest$$, ARRAY[-1, 16], 3.3, 'l', equicost => true) WHERE node >= 0 OR cost = 0; ``` -------------------------------- ### pgr_dijkstra Function Example Source: https://docs.pgrouting.org/latest/zh_Hans/migration Illustrates the use of the pgr_dijkstra function for shortest path calculations, including an example of selecting specific columns. ```APIDOC ## pgr_dijkstra Function ### Description Computes the shortest path using Dijkstra's algorithm on a directed graph. This example demonstrates a typical query and how to alias columns for clarity. ### Method SQL Query ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql SELECT * FROM pgr_dijkstra( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, ARRAY[6, 1], 17); ``` ### Response #### Success Response (200) Returns a table containing the shortest path information, with columns such as `seq`, `path_seq`, `start_vid`, `end_vid`, `node`, `edge`, `cost`, and `agg_cost`. #### Response Example ```text seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost -----+----------+-----------+---------+------+------+------+---------- 1 | 1 | 1 | 17 | 1 | 6 | 1 | 0 2 | 2 | 1 | 17 | 3 | 7 | 1 | 1 3 | 3 | 1 | 17 | 7 | 8 | 1 | 2 4 | 4 | 1 | 17 | 11 | 11 | 1 | 3 5 | 5 | 1 | 17 | 12 | 13 | 1 | 4 6 | 6 | 1 | 17 | 17 | -1 | 0 | 5 7 | 1 | 6 | 17 | 6 | 4 | 1 | 0 8 | 2 | 6 | 17 | 7 | 8 | 1 | 1 9 | 3 | 6 | 17 | 11 | 11 | 1 | 2 10 | 4 | 6 | 17 | 12 | 13 | 1 | 3 11 | 5 | 6 | 17 | 17 | -1 | 0 | 4 (11 rows) ``` ### Column Enumeration Example ```sql SELECT seq, path_seq, start_vid, node, edge, cost, agg_cost FROM pgr_dijkstra( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, ARRAY[6, 1], 17); ``` ### Column Enumeration Response Example ```text seq | path_seq | start_vid | node | edge | cost | agg_cost -----+----------+-----------+------+------+------+---------- 1 | 1 | 1 | 1 | 6 | 1 | 0 2 | 2 | 1 | 3 | 7 | 1 | 1 3 | 3 | 1 | 7 | 8 | 1 | 2 4 | 4 | 1 | 11 | 11 | 1 | 3 5 | 5 | 1 | 12 | 13 | 1 | 4 6 | 6 | 1 | 17 | -1 | 0 | 5 7 | 1 | 6 | 6 | 4 | 1 | 0 8 | 2 | 6 | 7 | 8 | 1 | 1 9 | 3 | 6 | 11 | 11 | 1 | 2 10 | 4 | 6 | 12 | 13 | 1 | 3 11 | 5 | 6 | 17 | -1 | 0 | 4 (11 rows) ``` ``` -------------------------------- ### pgr_bdDijkstra Function Example Source: https://docs.pgrouting.org/latest/zh_Hans/migration Demonstrates the usage of the pgr_bdDijkstra function for finding shortest paths, including an example of how to enumerate columns. ```APIDOC ## pgr_bdDijkstra Function ### Description Calculates the shortest path using Dijkstra's algorithm on a directed graph, considering reverse costs. This example shows a basic usage and how to select specific columns from the result. ### Method SQL Query ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql SELECT * FROM pgr_bdDijkstra( 'select id, source, target, cost, reverse_cost from edges', ARRAY[6, 1], 17); ``` ### Response #### Success Response (200) Returns a table with the shortest path details, including columns like `seq`, `path_seq`, `start_vid`, `end_vid`, `node`, `edge`, `cost`, and `agg_cost`. #### Response Example ```text seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost -----+----------+-----------+---------+------+------+------+---------- 1 | 1 | 1 | 17 | 1 | 6 | 1 | 0 2 | 2 | 1 | 17 | 3 | 7 | 1 | 1 3 | 3 | 1 | 17 | 7 | 8 | 1 | 2 4 | 4 | 1 | 17 | 11 | 11 | 1 | 3 5 | 5 | 1 | 17 | 12 | 13 | 1 | 4 6 | 6 | 1 | 17 | 17 | -1 | 0 | 5 7 | 1 | 6 | 17 | 6 | 4 | 1 | 0 8 | 2 | 6 | 17 | 7 | 8 | 1 | 1 9 | 3 | 6 | 17 | 11 | 11 | 1 | 2 10 | 4 | 6 | 17 | 12 | 13 | 1 | 3 11 | 5 | 6 | 17 | 17 | -1 | 0 | 4 (11 rows) ``` ### Column Enumeration Example ```sql SELECT seq, path_seq, start_vid AS start_pid, node, edge, cost, agg_cost FROM pgr_bdDijkstra( 'select id, source, target, cost, reverse_cost from edges', ARRAY[6, 1], 17); ``` ### Column Enumeration Response Example ```text seq | path_seq | start_pid | node | edge | cost | agg_cost -----+----------+-----------+------+------+------+---------- 1 | 1 | 1 | 1 | 6 | 1 | 0 2 | 2 | 1 | 3 | 7 | 1 | 1 3 | 3 | 1 | 7 | 8 | 1 | 2 4 | 4 | 1 | 11 | 11 | 1 | 3 5 | 5 | 1 | 12 | 13 | 1 | 4 6 | 6 | 1 | 17 | -1 | 0 | 5 7 | 1 | 6 | 6 | 4 | 1 | 0 8 | 2 | 6 | 7 | 8 | 1 | 1 9 | 3 | 6 | 11 | 11 | 1 | 2 10 | 4 | 6 | 12 | 13 | 1 | 3 11 | 5 | 6 | 17 | -1 | 0 | 4 (11 rows) ``` ``` -------------------------------- ### pgr_withPointsDD Example Source: https://docs.pgrouting.org/latest/en/migration Demonstrates the usage of the `pgr_withPointsDD` function for routing with multiple points, including before and after updates to pgRouting. ```APIDOC ## pgr_withPointsDD Function Usage ### Description This section illustrates the `pgr_withPointsDD` function, showcasing its application with multiple points and detailing changes after pgRouting updates. ### Method SQL Function Call ### Endpoint N/A (SQL Function) ### Parameters #### SQL Function Parameters - **edges_sql** (text) - Required - SQL query returning edge data (id, source, target, cost, reverse_cost). - **points_sql** (text) - Required - SQL query returning points of interest (pid, edge_id, fraction, side). - **start_end_points** (integer[]) - Required - Array of start and end vertex IDs. - **max_distance** (numeric) - Required - Maximum distance for routing. - **driving_side** (text) - Optional - Specifies the driving side ('l' for left, 'r' for right). - **equicost** (boolean) - Optional - If true, considers equally costly paths. ### Request Example (Before Update) ```sql SELECT * FROM pgr_withPointsDD( $$SELECT * FROM edges ORDER BY id$$ $$SELECT pid, edge_id, fraction, side from pointsOfInterest$$ ARRAY[-1, 16], 3.3, 'l', equicost => true); ``` ### Request Example (After Update) ```sql SELECT seq, start_vid, node, edge, cost, agg_cost FROM pgr_withPointsDD( $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$ $$SELECT pid, edge_id, fraction, side from pointsOfInterest$$ ARRAY[-1, 16], 3.3, 'l', equicost => true) WHERE node >= 0 OR cost = 0; ``` ### Response #### Success Response (SQL Result Set) - **seq** (integer) - Sequence of the path segment. - **start_vid** (integer) - Starting vertex ID of the segment. - **node** (integer) - The current node ID in the path. - **edge** (integer) - The edge ID used in the segment. - **cost** (numeric) - The cost of the current segment. - **agg_cost** (numeric) - The accumulated cost up to the current segment. #### Response Example (After Update) ```json { "example": "seq | start_vid | node | edge | cost | agg_cost\n-----+-----------+------+------+------+----------\n 1 | -1 | -1 | -1 | 0 | 0\n 2 | -1 | 6 | 1 | 0.6 | 0.6\n 3 | -1 | 7 | 4 | 1 | 1.6\n 4 | -1 | 5 | 1 | 1 | 1.6\n 5 | -1 | 3 | 7 | 1 | 2.6\n 6 | -1 | 8 | 10 | 1 | 2.6\n 9 | 16 | 16 | -1 | 0 | 0\n 10 | 16 | 11 | 9 | 1 | 1\n 11 | 16 | 15 | 16 | 1 | 1\n 12 | 16 | 17 | 15 | 1 | 1\n 13 | 16 | 10 | 3 | 1 | 2\n 14 | 16 | 12 | 11 | 1 | 2\n(12 rows)" } ``` ``` -------------------------------- ### pgr_aStarCost with Same Start and End Vids (SQL) Source: https://docs.pgrouting.org/latest/en/pgr_aStarCost This example shows how to use pgr_aStarCost when the start and end vertex IDs in the input arrays are the same. The function calculates the shortest path costs between these specified vertices. It requires a table named 'edges' with relevant routing information. ```sql SELECT * FROM pgr_aStarCost( 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges', ARRAY[7, 10, 15], ARRAY[7, 10, 15]); ``` -------------------------------- ### pgr_trsp_withPoints Example: One to One Path with Details Source: https://docs.pgrouting.org/latest/en/pgr_trsp_withPoints This example demonstrates the usage of `pgr_trsp_withPoints` for finding a path between a single start point and a single end point, with specific driving side and detail options enabled. It utilizes SQL queries for edges, restrictions, and points of interest. ```sql SELECT * FROM pgr_trsp_withPoints( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', 'SELECT id, path, cost FROM restrictions', 'SELECT pid, edge_id, fraction, side FROM pointsOfInterest', -1, 10, details => true); ``` -------------------------------- ### Solve TSP with pgr_TSP, specifying start_id (SQL) Source: https://docs.pgrouting.org/latest/en/pgr_TSP This example shows how to use the pgr_TSP function when a specific starting vertex is required. It utilizes a cost matrix generated by pgr_dijkstraCostMatrix and sets the 'start_id' parameter to 1, influencing the starting point of the calculated tour. ```sql SELECT * FROM pgr_TSP( $$SELECT * FROM pgr_dijkstraCostMatrix( 'SELECT id, source, target, cost, reverse_cost FROM edges', (SELECT array_agg(id) FROM vertices WHERE id NOT IN (2, 4, 13, 14)), directed => false) $$, start_id => 1 ); ``` -------------------------------- ### pgr_KSP with start/end nodes and heap_paths enabled Source: https://docs.pgrouting.org/latest/en/pgr_KSP This example demonstrates how to find multiple shortest paths between a start node and an end node on an undirected graph, also retrieving the paths stored in a heap. ```APIDOC ## GET /websites/pgrouting/ksp_nodes_heap ### Description Finds multiple shortest paths between specified start and end nodes on an undirected graph, with options to retrieve heap paths. ### Method GET ### Endpoint `/websites/pgrouting/ksp_nodes_heap` ### Parameters #### Query Parameters - **source_edges** (string) - Required - SQL query to select edges with id, source, target, cost, and reverse_cost. - **start_node** (integer) - Required - The starting node ID. - **end_node** (integer) - Required - The ending node ID. - **num_paths** (integer) - Required - The number of shortest paths to find. - **directed** (boolean) - Optional - Set to `false` for undirected graphs. - **heap_paths** (boolean) - Optional - Set to `true` to retrieve paths in the heap. ### Request Example ```sql SELECT * FROM pgr_KSP( 'SELECT id, source, target, cost, reverse_cost FROM edges', 6, 17, 2, directed => false, heap_paths => true ); ``` ### Response #### Success Response (200) - **seq** (integer) - Sequence number of the path segment. - **path_id** (integer) - Identifier for the specific path. - **path_seq** - Sequence number within a path. - **start_vid** (integer) - The starting vertex ID of the segment. - **end_vid** (integer) - The ending vertex ID of the segment. - **node** (integer) - The current node ID. - **edge** (integer) - The edge ID connecting the nodes. - **cost** (float) - The cost of the current edge. - **agg_cost** (float) - The accumulated cost to reach the current node. #### Response Example ```json [ { "seq": 1, "path_id": 1, "path_seq": 1, "start_vid": 6, "end_vid": 17, "node": 6, "edge": 4, "cost": 1, "agg_cost": 0 }, { "seq": 2, "path_id": 1, "path_seq": 2, "start_vid": 6, "end_vid": 17, "node": 7, "edge": 10, "cost": 1, "agg_cost": 1 } ] ``` ``` -------------------------------- ### pgr_withPoints Function Example Source: https://docs.pgrouting.org/latest/en/migration Demonstrates the usage of the `pgr_withPoints` function for calculating routes with intermediate points, including a breakdown of the output columns and a note on version compatibility. ```APIDOC ## POST /pgr_withPoints ### Description Calculates routes considering intermediate points specified in `pointsOfInterest` and origin-destination pairs. This function is useful for scenarios where the route must pass through specific locations. ### Method POST (or any method that can execute SQL queries) ### Endpoint `/pgr_withPoints` (This is a conceptual endpoint representing the function call within a SQL environment) ### Parameters This function is called within a SQL query. The parameters are arguments to the `pgr_withPoints` function: - **`edges_sql`** (string) - SQL query to select edges from the graph. Must include `id`, `source`, `target`, `cost`, and `reverse_cost` columns. - **`points_sql`** (string) - SQL query to select points of interest. Must include `pid`, `edge_id`, `fraction`, and `side` columns. - **`combinations_sql`** (string) - SQL query defining the source and target combinations for routing. Must include `source` and `target` columns. - **`process_sql`** (string) - A string specifying the processing mode. Common values include 'r' for routing, 'd' for driving distance, etc. Use 'r' for standard routing. - **`details`** (boolean, optional) - If `true`, includes detailed path information in the output. Defaults to `false`. ### Request Example ```sql SELECT * FROM pgr_withPoints( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', 'SELECT pid, edge_id, fraction, side from pointsOfInterest', 'SELECT * FROM (VALUES (-1, 10), (6, -3)) AS combinations(source, target)', 'r', details => true); ``` ### Response #### Success Response (200) Returns a table with routing results. The columns depend on the `details` parameter: - **`seq`** (integer) - Sequence number of the path. - **`path_seq`** (integer) - Sequence number of the step within a path. - **`start_vid`** (integer) - The starting vertex ID of the edge in the path. - **`end_vid`** (integer) - The ending vertex ID of the edge in the path. - **`node`** (integer) - The vertex ID of the current node. - **`edge`** (integer) - The ID of the edge traversed. - **`cost`** (numeric) - The cost of traversing the current edge. - **`agg_cost`** (numeric) - The accumulated cost to reach the current node. - **`start_pid`** (integer, optional) - The ID of the starting point of interest for this path segment (used in older versions). - **`end_pid`** (integer, optional) - The ID of the ending point of interest for this path segment (used in older versions). #### Response Example ``` seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost -----+----------+-----------+---------+------+------+------+---------- 1 | 1 | -1 | 10 | -1 | 1 | 0.4 | 0 2 | 2 | -1 | 10 | 5 | 1 | 1.0 | 0.4 ... 14 | 5 | 6 | -3 | -3 | -1 | 0.0 | 2.6 (14 rows) ``` ### Warning **Breaking Change**: If using `pgr_withPoints` with pgRouting versions after v3.8, column names in the output have changed. `start_vid` and `end_vid` replace the older `start_pid` and `end_pid`. To maintain compatibility with older applications, you can alias these columns in your query: `start_vid AS start_pid`, `end_vid AS end_pid`. ``` -------------------------------- ### pgr_drivingDistance - Multiple Vertices Example Source: https://docs.pgrouting.org/latest/en/migration Demonstrates the usage of the pgr_drivingDistance function with multiple starting vertices and provides an example of how to migrate to newer column names. ```APIDOC ## pgr_drivingDistance - Multiple Vertices ### Description This section shows an example of using the `pgr_drivingDistance` function with multiple starting vertices. It also includes a guide on how to adapt the output to match older column names. ### Method SQL Query ### Endpoint N/A (SQL Function) ### Parameters #### Query Parameters - **`sql`** (string) - Required - The SQL query to select edges with `id`, `source`, `target`, `cost`, and `reverse_cost`. - **`start_vertices`** (array of integers) - Required - An array of starting vertex IDs. - **`distance`** (float) - Required - The maximum driving distance. - **`equicost`** (boolean) - Optional - If true, considers only edges with the minimum cost. - **`driving_side`** (string) - Optional - Specifies the driving side ('r', 'R', 'l', 'L' for directed graphs; 'b', 'B' for undirected graphs). ### Request Example ```sql SELECT * FROM pgr_drivingDistance( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, ARRAY[11, 16], 3.0, equicost => true); ``` ### Response #### Success Response (200) - **`seq`** (integer) - Sequence number of the path. - **`depth`** (integer) - Depth of the node in the search tree. - **`start_vid`** (integer) - The starting vertex ID for this path. - **`pred`** (integer) - The predecessor vertex ID in the path. - **`node`** (integer) - The current vertex ID. - **`edge`** (integer) - The edge ID leading to the current node. - **`cost`** (float) - The cost of the edge leading to the current node. - **`agg_cost`** (float) - The accumulated cost to reach the current node. #### Response Example ``` seq | depth | start_vid | pred | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+------+---------- 1 | 0 | 11 | 11 | 11 | -1 | 0 | 0 2 | 1 | 11 | 11 | 7 | 8 | 1 | 1 3 | 1 | 11 | 11 | 12 | 11 | 1 | 1 4 | 2 | 11 | 7 | 3 | 7 | 1 | 2 5 | 2 | 11 | 7 | 6 | 4 | 1 | 2 6 | 2 | 11 | 7 | 8 | 10 | 1 | 2 7 | 3 | 11 | 3 | 1 | 6 | 1 | 3 8 | 3 | 11 | 6 | 5 | 1 | 1 | 3 9 | 3 | 11 | 8 | 9 | 14 | 1 | 3 10 | 0 | 16 | 16 | 16 | -1 | 0 | 0 11 | 1 | 16 | 16 | 15 | 16 | 1 | 1 12 | 1 | 16 | 16 | 17 | 15 | 1 | 1 13 | 2 | 16 | 15 | 10 | 3 | 1 | 2 (13 rows) ``` ### Migration Notes To get the old version column names `(seq, from_v, node, edge, cost, agg_cost)`: filter out the column `pred` and `depth` and rename `start_vid` to `from_v`. ```sql SELECT seq, start_vid AS from_v, node, edge, cost, agg_cost FROM pgr_drivingDistance( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, ARRAY[11, 16], 3.0, equicost => true); ``` ``` -------------------------------- ### Create PostgreSQL Database and Load Extension Source: https://docs.pgrouting.org/latest/en/pgRouting-concepts Demonstrates how to create a new PostgreSQL database and enable the pgRouting extension. This is a prerequisite for using pgRouting functionalities. ```bash createdb sampledata psql sampledata -c "CREATE EXTENSION pgrouting CASCADE" ``` -------------------------------- ### Test pgRouting Installation Source: https://docs.pgrouting.org/latest/en/pgRouting-installation This snippet outlines the steps for testing a pgRouting installation. It involves generating documentation queries, creating a test database, running a test script, and then dropping the test database. This process requires the 'tools/testers/doc_queries_generator.pl' script and 'tools/testers/pg_prove_tests.sh' script, along with database command-line tools. ```bash tools/testers/doc_queries_generator.pl createdb -U ___pgr___test ___ sh ./tools/testers/pg_prove_tests.sh dropdb -U ___pgr___test ___ ``` -------------------------------- ### Build pgRouting Code and Documentation (Make) Source: https://docs.pgrouting.org/latest/en/pgRouting-installation This snippet shows how to use the 'make' command to build the pgRouting project. It covers default builds, generating user and developer documentation, and building both code and user documentation. No external dependencies are explicitly mentioned for these commands. ```bash $ make # default build $ make doc # build only the user's documentation $ make doxy # build only the developer's documentation $ make all # build both the code and the user's documentation ``` -------------------------------- ### Install pgRouting Extension Source: https://docs.pgrouting.org/latest/en/pgRouting-concepts This sequence of shell commands demonstrates how to create a new PostgreSQL database named 'wiki' and then install the pgRouting extension within that database. This is a prerequisite for using pgRouting functionalities. ```bash createdb wiki psql wiki wiki =# CREATE EXTENSION pgRouting CASCADE; ``` -------------------------------- ### pgr_kruskalDFS - Multiple Vertices Example Source: https://docs.pgrouting.org/latest/en/migration Demonstrates the usage of the pgr_kruskalDFS function for finding shortest paths with multiple starting vertices. Includes pre- and post-pgRouting update column enumerations. ```APIDOC ## pgr_kruskalDFS - Multiple Vertices ### Description This endpoint demonstrates the usage of the `pgr_kruskalDFS` function to find shortest paths in a graph, starting from multiple specified vertices. It includes examples of how the output columns change before and after updating pgRouting. ### Method SQL Query ### Endpoint N/A (SQL Function) ### Parameters #### SQL Function Parameters - **graph_sql** (string) - Required - SQL query to select graph edges with id, source, target, cost, and reverse_cost. - **start_vids** (array of integers) - Required - An array of starting vertex IDs. - **max_depth** (integer) - Optional - The maximum depth for the search. ### Request Example ```sql SELECT * FROM pgr_kruskalDFS( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', ARRAY[9, 6], max_depth => 3); ``` ### Response #### Success Response (SQL Result) - **seq** (integer) - Sequence number of the path. - **depth** (integer) - Depth of the node in the search tree. - **start_vid** (integer) - The starting vertex for this path segment. - **pred** (integer) - The predecessor vertex in the path. - **node** (integer) - The current vertex ID. - **edge** (integer) - The edge ID leading to the current node. - **cost** (numeric) - The cost of the edge leading to the current node. - **agg_cost** (numeric) - The accumulated cost to reach the current node. #### Response Example ``` 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) ``` ### Migration Notes - **Before updating pgRouting**: Enumerate columns as `(seq, depth, start_vid, pred, node, edge, cost, agg_cost)`. - **After updating pgRouting (for old column names)**: Filter out `pred` and `depth`, and rename `start_vid` to `from_v` to get `(seq, from_v, node, edge, cost, agg_cost)`. ``` -------------------------------- ### pgr_drivingDistance - Single Vertex Example Source: https://docs.pgrouting.org/latest/en/migration Illustrates the pgr_drivingDistance function for calculating reachable nodes within a specified distance from a single starting vertex. Shows column enumeration before and after pgRouting updates. ```APIDOC ## pgr_drivingDistance - Single Vertex ### Description This endpoint demonstrates the usage of the `pgr_drivingDistance` function to find all nodes reachable within a given cost (distance) from a single starting vertex. It provides examples of column enumeration before and after pgRouting updates. ### Method SQL Query ### Endpoint N/A (SQL Function) ### Parameters #### SQL Function Parameters - **graph_sql** (string) - Required - SQL query to select graph edges with id, source, target, cost, and reverse_cost. - **start_vid** (integer) - Required - The starting vertex ID. - **cost** (numeric) - Required - The maximum cost (distance) to search. ### Request Example ```sql SELECT * FROM pgr_drivingDistance( $$SELECT id, source, target, cost, reverse_cost FROM edges$$, 11, 3.0); ``` ### Response #### Success Response (SQL Result) - **seq** (integer) - Sequence number of the path. - **depth** (integer) - Depth of the node in the search tree. - **start_vid** (integer) - The starting vertex for this search. - **pred** (integer) - The predecessor vertex in the path. - **node** (integer) - The current vertex ID. - **edge** (integer) - The edge ID leading to the current node. - **cost** (numeric) - The cost of the edge leading to the current node. - **agg_cost** (numeric) - The accumulated cost to reach the current node. #### Response Example ``` seq | depth | start_vid | pred | node | edge | cost | agg_cost -----+-------+-----------+------+------+------+------+---------- 1 | 0 | 11 | 11 | 11 | -1 | 0 | 0 2 | 1 | 11 | 11 | 7 | 8 | 1 | 1 3 | 1 | 11 | 11 | 12 | 11 | 1 | 1 4 | 1 | 11 | 11 | 16 | 9 | 1 | 1 5 | 2 | 11 | 7 | 3 | 7 | 1 | 2 6 | 2 | 11 | 7 | 6 | 4 | 1 | 2 7 | 2 | 11 | 7 | 8 | 10 | 1 | 2 8 | 2 | 11 | 16 | 15 | 16 | 1 | 2 9 | 2 | 11 | 16 | 17 | 15 | 1 | 2 10 | 3 | 11 | 3 | 1 | 6 | 1 | 3 11 | 3 | 11 | 6 | 5 | 1 | 1 | 3 12 | 3 | 11 | 8 | 9 | 14 | 1 | 3 13 | 3 | 11 | 15 | 10 | 3 | 1 | 3 (13 rows) ``` ### Migration Notes - **Before updating pgRouting**: Enumerate columns as `(seq, depth, start_vid, pred, node, edge, cost, agg_cost)`. - **After updating pgRouting**: Enumerate columns as `(seq, path_seq, node, edge, cost, agg_cost)`. ``` -------------------------------- ### One to Many Routing with pgr_withPoints Source: https://docs.pgrouting.org/latest/en/migration Illustrates one-to-many routing using the pgr_withPoints function, which allows routing to specific points of interest defined by their edge ID and fraction along the edge. This example shows the SQL query and its output, including routing from a starting vertex to multiple points. ```sql SELECT * FROM pgr_withPoints( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', 'SELECT pid, edge_id, fraction, side from pointsOfInterest', -1, ARRAY[-3, 7], 'b', directed => false); ``` -------------------------------- ### Initial_solution::do_while_foo() Source: https://docs.pgrouting.org/doxygen/classpgrouting_1_1vrp_1_1Initial__solution Internal method for constructing an initial solution by assigning unassigned orders to trucks. ```APIDOC ## Initial_solution::do_while_foo() ### Description Internal method for constructing an initial solution by assigning unassigned orders to trucks. This method is part of the initial solution generation process. ### Method POST ### Endpoint `/websites/pgrouting/initial_solution/do_while_foo` ### Parameters #### Path Parameters None #### Query Parameters - **kind** (integer) - Required - Specifies the type of initial solution to generate (1 to OneDepot). #### Request Body None ### Request Example None ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Vehicle Data Example Source: https://docs.pgrouting.org/latest/en/pgr_pickDeliverEuclidean Provides an example of vehicle data structure, including capacity, start location, and time windows, as used in the lc101 dataset. ```APIDOC ## GET /websites/pgrouting/example/vehicles ### Description Provides an example of vehicle data structure, including capacity, start location, and time windows, as used in the lc101 dataset. ### Method GET ### Endpoint /websites/pgrouting/example/vehicles ### Parameters #### Query Parameters - **None** ### Request Example ```json { "dataset": "lc101" } ``` ### Response #### Success Response (200) - **id** (BIGINT) - Vehicle identifier. - **capacity** (BIGINT) - Vehicle capacity. - **start_x** (FLOAT) - Starting X coordinate. - **start_y** (FLOAT) - Starting Y coordinate. - **start_open** (INTEGER) - Earliest start time. - **start_close** (INTEGER) - Latest start time. #### Response Example ```json [ { "id": 1, "capacity": 200, "start_x": 30.0, "start_y": 50.0, "start_open": 0, "start_close": 1236 } // ... 24 more vehicles ] ``` ```