<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>I’m cc’ing pgRouting users list since some people might have some more ideas there.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>@Shaozhong – you should join the pgRouting Users mailing list if you more pointed questions about it’s capabilities.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Thanks,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Regina<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> postgis-users [mailto:postgis-users-bounces@lists.osgeo.org] <b>On Behalf Of </b>Shaozhong SHI<br><b>Sent:</b> Friday, July 28, 2023 4:45 PM<br><b>To:</b> Imre Samu <pella.samu@gmail.com><br><b>Cc:</b> PostGIS Users Discussion <postgis-users@lists.osgeo.org><br><b>Subject:</b> Re: [postgis-users] best finding all paths with recursive query<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Imre Samu,<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Very interesting.  I will read and review.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I am interested in exploring new concepts.  Something like connectivity tests.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Different network have different connectivity or known as topological relationships between objects.  For instance, water network and road network.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Certain types are expected to be valid in water network whilst other types are expected to be valid in road network.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Regards,<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>David<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>On Fri, 28 Jul 2023 at 02:16, Imre Samu <<a href="mailto:pella.samu@gmail.com">pella.samu@gmail.com</a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><div><p class=MsoNormal>Hi David,<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>I have created<o:p></o:p></p><div><p class=MsoNormal>an extended source data  ( 20 edges ;  with pgrouting create topology ) <o:p></o:p></p></div><div><p class=MsoNormal>Therefore, the pgrouting extension is essential! It's also crucial to grasp the fundamental PGRouting concepts.<o:p></o:p></p><div><p class=MsoNormal>- <a href="https://docs.pgrouting.org/3.5/en/pgRouting-concepts.html" target="_blank">https://docs.pgrouting.org/3.5/en/pgRouting-concepts.html</a> <o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>As I understand, your example represents a 'directed' network. <o:p></o:p></p></div><div><p class=MsoNormal>In response, I have developed two solutions:<br>-  A Common Table Expressions (CTE) recursive pure SQL version, and<br>-  A version utilizing pgr_ksp.<o:p></o:p></p></div><div><div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>CTE SQL  - result  ( for my extended test data ~ 20 edges )<br><span style='font-family:"Courier New";color:#38761D'>+-------------------+<br>|       path        |<br>+-------------------+<br>| {6,3,14,20}       |<br>| {6,3,1,18,19}     |<br>| {6,3,14,16,18,19} |<br>| {6,3,15,17,18,19} |<br>+-------------------+</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>and a pgr_ksp version result:<o:p></o:p></p></div><div><p class=MsoNormal><span style='font-family:"Courier New";color:#741B47'>+---------+--------+--------+---------+-------------------+--------------------+<br>| edge_id | source | target | path_id |       edges       |       nodes        |<br>+---------+--------+--------+---------+-------------------+--------------------+<br>|       6 |      7 |     18 |       1 | {6,3,1,18,19}     | {7,4,1,2,17,18}    |<br>|       6 |      7 |     18 |       2 | {6,3,14,16,18,19} | {7,4,1,15,2,17,18} |<br>|       6 |      7 |     18 |       3 | {6,3,15,17,18,19} | {7,4,1,16,2,17,18} |<br>|       6 |      7 |     19 |       1 | {6,3,14,20}       | {7,4,1,15,19}      |<br>+---------+--------+--------+---------+-------------------+--------------------+</span><o:p></o:p></p></div><div><p class=MsoNormal><br><br>And this is the Data + Code:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-family:"Courier New"'>--------------------------------<br><span style='color:#351C75'>DROP TABLE IF EXISTS network;</span><br><span style='color:#351C75'>BEGIN;</span><br><span style='color:#351C75'>CREATE TABLE network ( segment geometry, id integer primary key);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 1  1,  0  0)',  1);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 2  1,  1  1)',  2);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 1  2,  1  1)',  3);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 3  1,  2  1)',  4);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 3  2,  2  1)',  5);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 2  3,  1  2)',  6);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 1  3,  1  2)',  7);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 4  2,  3  2)',  8);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 3  4,  2  3)',  9);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 2  4,  2  3)', 10);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 1  4,  1  3)', 11);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 4  3,  4  2)', 12);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 4  4,  3  4)', 13);</span><br><br><span style='color:#351C75'>-- add some extra edges to make it interesting</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 1  1,  1  0)', 14);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 1  1,  0  1)', 15);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 1  0,  0  0)', 16);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 0  1,  0  0)', 17);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 0  0, -1 -1)', 18);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING(-1 -1, -2 -2)', 19);</span><br><span style='color:#351C75'>INSERT INTO network VALUES ('LINESTRING( 1  0,  5  0)', 20);</span><br><br><span style='color:#351C75'>ALTER TABLE network ADD COLUMN "source" integer;</span><br><span style='color:#351C75'>ALTER TABLE network ADD COLUMN "target" integer;</span><br><span style='color:#351C75'>ALTER TABLE network ADD COLUMN cost float;</span><br><span style='color:#351C75'>UPDATE network SET cost = ST_Length(segment);</span><br><span style='color:#351C75'>CREATE INDEX network_gix    ON network USING GIST (segment);</span><br><span style='color:#351C75'>COMMIT;</span><br><br><span style='color:#351C75'>VACUUM FULL ANALYZE network;</span><br><br><span style='color:#351C75'>-- enable pgrouting : <a href="https://pgrouting.org/" target="_blank">https://pgrouting.org/</a></span><br><span style='color:#351C75'>CREATE EXTENSION IF NOT EXISTS PGROUTING ;</span><br><span style='color:#351C75'>--  Builds a network topology based on the geometry information.</span><br><span style='color:#351C75'>--  <a href="https://docs.pgrouting.org/latest/en/pgr_createTopology.html" target="_blank">https://docs.pgrouting.org/latest/en/pgr_createTopology.html</a></span><br><span style='color:#351C75'>SELECT pgr_createTopology('network', 0.000001, 'segment', 'id');</span><br><span style='color:#351C75'>-- Vertices table for table public.network is: public.network_vertices_pgr</span><br><br><span style='color:#351C75'>--  analyze the network table</span><br><span style='color:#351C75'>SELECT pgr_analyzeGraph('network',   0.000001, the_geom := 'segment', id := 'id');</span><br><br><span style='color:#351C75'>-- the new network table</span><br><span style='color:#351C75'>\d+ network</span><br><span style='color:#351C75'>select * from network;</span><br><br><span style='color:#351C75'>-- the new vertices table</span><br><span style='color:#351C75'>\d+ network_vertices_pgr</span><br><span style='color:#351C75'>select * from network_vertices_pgr;</span><br><br><span style='color:#38761D'>-----------------------------------<br>-- This code essentially finds all paths in the network <br>-- that start from the edge with id = 6 and end at a node that has no outgoing edges (end node). <br>-- It avoids cycles by not including an edge in a path if it is already in the path. <br>-- This code uses a recursive common table expression (CTE) to perform the path search. <br>-- The recursion is done by joining the paths generated <br>-- so far with the edges in the network based on the end node of the path <br>-- and the start node of the edge.<br>-----------------------------------<br>--<br>-- Start a recursive CTE (Common Table Expression)  <br>WITH RECURSIVE paths(path, last_node) AS (<br><br>  -- Initial selection for the recursive CTE ------<br>  -- The initial path is an array with a single element, the start node's id<br>  -- The last_node is the end node of the edge with the start node's id    <br>  SELECT ARRAY[id] AS path, target AS last_node<br>  FROM network<br>  WHERE id = 6  -- Select the edge with id = 6 as the start edge<br><br>  UNION ALL -- Union to append following results to the initial selection<br><br>  -- Recursive part of the CTE -------<br>  -- Build the path by appending the current edge id to the existing path,<br>  -- and update the last node to the end node of the current edge <br>  SELECT p.path || ARRAY[<a href="http://e.id" target="_blank">e.id</a>], e.target<br>  FROM network e<br>  INNER JOIN paths p ON e.source = p.last_node -- Join with the previous paths based on the last_node<br>  WHERE NOT <a href="http://e.id" target="_blank">e.id</a>  = any( p.path )  -- Prevent cycles: Do not select an edge if its id is already in the path<br>)<br>-- Finally, select the paths<br>SELECT path<br>FROM paths<br>WHERE NOT EXISTS (<br>  -- For each path, check if there exists an edge in the network starting from the path's last node<br>  -- If such an edge exists, the path is not selected, because the path has not reached the end<br>  SELECT 1<br>  FROM network e<br>  WHERE e.source = paths.last_node<br>);<br></span><br><span style='color:#351C75'>----------------------------------</span><br><br><span style='color:#741B47'><br>---------------------------------------------------------<br>-- (pgrouting) pgr_KSP - K Shortest Path solution;<br>-- This script first creates a  "ksp" table<br>--    to fetch the K shortest paths from a specific source to all other targets<br>--    in the "network" that are not "sources". <br>-- From the "ksp":  It then extracts each path, organizes the sequence of edges and nodes, <br>-- and presents the result in a structured way.<br>------------------------------------------------<br><br>-- Creating a 'ksp' table (K Shortest Paths)<br>drop table if exists ksp;<br>create table ksp as<br>  -- Selects the edge_id and source from the network table where id = 6,<br>  -- and selects all targets from the network that are not sources    <br>  SELECT <br>      tsource.edge_id as edge_id  -- This is the id of the selected edge<br>    , tsource.source  as source   -- This is the source node of the selected edge<br>    , tx.target       as target   -- These are the target nodes which are not sources<br>    , (pgr_KSP (  -- This is a pgRouting function to get the K shortest paths from source to target.<br>                  -- <a href="https://docs.pgrouting.org/latest/en/pgr_KSP.html" target="_blank">https://docs.pgrouting.org/latest/en/pgr_KSP.html</a><br>         'SELECT id, source, target, cost FROM network' -- This is the SQL to generate the network graph<br>         ,tsource.source -- This is the source node of the selected edge<br>         ,tx.target      -- These are the target nodes which are not sources<br>         ,999999999      -- This is the maximum number of paths to return<br>         ,directed:=true -- This is a pgRouting function to indicate that the graph is directed<br>      )).*  <br>  FROM <br>   ( <br>    -- This subquery selects the edge with id = 6 as the source edge<br>    select id as edge_id, source from network where id = 6 ) as tsource<br>  ,( <br>    -- This subquery selects all targets that are not sources<br>        SELECT target <br>          FROM network<br>        EXCEPT <br>        SELECT source <br>          FROM network<br>  ) tx<br>;<br><br>-- examine ksp<br>select * from ksp;<br><br>-- Now the final edges and nodes :<br>select edge_id  -- Selects edge_id<br>      ,source   -- Selects source<br>      ,target   -- Selects target<br>      ,path_id  -- Selects path_id <br>      -- Aggregates all edges from 'ksp' in the order of their sequence, excluding edge = -1      <br>      ,array_agg(edge order by path_seq ) FILTER (Where edge != -1 ) as edges <br>      -- Aggregates all nodes from 'ksp' in the order of their sequence<br>      ,array_agg(node order by path_seq ) as nodes <br>  from ksp    <br>  group by edge_id,source,target, path_id<br>  order by edge_id,source,target, path_id</span><br><span style='color:#351C75'>; </span><br></span><br>-----------------------------------<br>in gist ( SQL + Log ) : <a href="https://gist.github.com/ImreSamu/cdd9afed6106366296622b10c0d44be2" target="_blank">https://gist.github.com/ImreSamu/cdd9afed6106366296622b10c0d44be2</a> <o:p></o:p></p></div><div><p class=MsoNormal>------------------<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I assume it's not easy to understand the code, especially the pgrouting concepts, but I think it's inevitable if you want to deal with similar networks.<o:p></o:p></p></div><div><p class=MsoNormal>And I think it's definitely worth spending a few weeks on pgrouting and completing the basic workshop.<o:p></o:p></p></div><div><p class=MsoNormal>(  <a href="https://workshop.pgrouting.org/2.8/en/index.html" target="_blank">https://workshop.pgrouting.org/2.8/en/index.html</a> )<o:p></o:p></p></div><div><p class=MsoNormal>And if you have any more questions about pgrouting, there is also a dedicated mailing list.<o:p></o:p></p></div><div><p class=MsoNormal>( <a href="https://lists.osgeo.org/mailman/listinfo/pgrouting-users" target="_blank">https://lists.osgeo.org/mailman/listinfo/pgrouting-users</a> )<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I hope you can use something from the solution I suggested.<o:p></o:p></p></div><div><p class=MsoNormal>  Imre<o:p></o:p></p></div><div><div><p class=MsoNormal><o:p> </o:p></p></div></div></div></div></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>Shaozhong SHI <<a href="mailto:shishaozhong@gmail.com" target="_blank">shishaozhong@gmail.com</a>> ezt írta (időpont: 2023. júl. 19., Sze, 11:22):<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><p class=MsoNormal>Imre Samu,<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>With the example:  the output the path is <o:p></o:p></p></div><div><p class=MsoNormal>6<o:p></o:p></p></div><div><p class=MsoNormal>3<o:p></o:p></p></div><div><p class=MsoNormal>1<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>When extra added:<o:p></o:p></p></div><div><p class=MsoNormal>the output is:<o:p></o:p></p></div><div><p class=MsoNormal>6<o:p></o:p></p></div><div><p class=MsoNormal>3<o:p></o:p></p></div><div><p class=MsoNormal>1<o:p></o:p></p></div><div><p class=MsoNormal>14<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Regards,<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>David<o:p></o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>On Mon, 17 Jul 2023 at 23:12, Imre Samu <<a href="mailto:pella.samu@gmail.com" target="_blank">pella.samu@gmail.com</a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><p class=MsoNormal>> How about finding out all possible route paths.?<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>I'm sorry, I don't fully understand your question as it could be interpreted in several ways.<br>Could you provide a small set of test data and specify the kind of output you're looking for?<o:p></o:p></p></div></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Thanks,<o:p></o:p></p></div><div><p class=MsoNormal>  Imre<o:p></o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>Shaozhong SHI <<a href="mailto:shishaozhong@gmail.com" target="_blank">shishaozhong@gmail.com</a>> ezt írta (időpont: 2023. júl. 17., H, 21:24):<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><p class=MsoNormal>How about finding out all possible route paths.?<o:p></o:p></p><div><p class=MsoNormal>Regards, david<br><br>On Monday, 17 July 2023, Imre Samu <<a href="mailto:pella.samu@gmail.com" target="_blank">pella.samu@gmail.com</a>> wrote:<o:p></o:p></p><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><div><p class=MsoNormal>> Which one is the best example for finding all paths with recursive query?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>What type of graph are you working with?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>1.) <o:p></o:p></p></div><p class=MsoNormal>You can check Yugabyte (PostgreSQL compatible) documentation for pure SQL recursive-graph solutions for :<o:p></o:p></p><div><p class=MsoNormal>- Undirected cyclic graph<br>- Directed cyclic graph<br>- Directed acyclic graph<br>- Rooted tree<br>- Unique containing paths<o:p></o:p></p><div><p class=MsoNormal><a href="https://docs.yugabyte.com/preview/api/ysql/the-sql-language/with-clause/traversing-general-graphs/common-code/" target="_blank">https://docs.yugabyte.com/preview/api/ysql/the-sql-language/with-clause/traversing-general-graphs/common-code/</a><o:p></o:p></p></div></div><div><p class=MsoNormal>I think there's a pretty good summary for solving basic graph problems with SQL, which could potentially help you understand your problem as well and find a solution for it...<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>2.) <o:p></o:p></p></div><div><p class=MsoNormal>Or use pgr_KSP - if you're only interested in the final result and you're not attached to the purely recursive SQL solution. <o:p></o:p></p></div><div><p class=MsoNormal>And it's much more optimal for large graphs as well. <o:p></o:p></p></div><div><p class=MsoNormal>Here, you just need to provide a large enough K value (e.g., ~ maximum (integer/bigint) value) and then you get all possible paths. <o:p></o:p></p></div><div><p class=MsoNormal>Or if you're only interested in the top 2, then set K=2.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><a href="https://docs.pgrouting.org/latest/en/pgr_KSP.html" target="_blank">https://docs.pgrouting.org/latest/en/pgr_KSP.html</a><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif;color:blue'>"The K shortest path routing algorithm based on Yen’s algorithm<b>. “K” is the number of shortest paths desired.</b>"</span><o:p></o:p></p></div><div><p class=MsoNormal><a href="https://en.wikipedia.org/wiki/K_shortest_path_routing" target="_blank">https://en.wikipedia.org/wiki/K_shortest_path_routing</a><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif;color:#333333'>regards,</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif;color:#333333'> Imre</span><o:p></o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>Shaozhong SHI <<a href="mailto:shishaozhong@gmail.com" target="_blank">shishaozhong@gmail.com</a>> ezt írta (időpont: 2023. júl. 17., H, 9:01):<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><p class=MsoNormal>Which one is the best example for finding all paths with recursive query?<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Regards,<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>David<o:p></o:p></p></div></div><p class=MsoNormal>_______________________________________________<br>postgis-users mailing list<br><a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br><a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><o:p></o:p></p></blockquote></div></blockquote></div><p class=MsoNormal>_______________________________________________<br>postgis-users mailing list<br><a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br><a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><o:p></o:p></p></blockquote></div><p class=MsoNormal>_______________________________________________<br>postgis-users mailing list<br><a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br><a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><o:p></o:p></p></blockquote></div><p class=MsoNormal>_______________________________________________<br>postgis-users mailing list<br><a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br><a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><o:p></o:p></p></blockquote></div></blockquote></div></div></div></body></html>