0

The following returns a route as expected.

SELECT seq, id1 AS node, id2 AS edge, cost, b.the_geom as the_geom FROM pgr_dijkstra('
SELECT gid AS id,
     source::integer,
     target::integer,
     length::double precision AS cost
    FROM ways',
247542, 258349, false, false) a LEFT JOIN ways b ON (a.id2 = b.gid);

However the following does not. I expected this to return 3 routes but instead it returns nothing.

SELECT seq, id1 AS node, id2 AS edge, cost, b.the_geom as the_geom FROM pgr_ksp('
SELECT gid AS id,
     source::integer,
     target::integer,
     length::double precision AS cost
    FROM ways',
247542, 258349, 3, false) a LEFT JOIN ways b ON (a.id2 = b.gid);

Any idea why this is happening?

  • Perhaps you can expand the question to detail versions, and the source data for routing? – BradHards Dec 7 '13 at 5:17
  • I am also facing the same issue.let me know if any findings. – Veeranjaneyulu .Kota Jun 28 '17 at 12:12
1

I have the exact same problem and I have figured that out why it is happening. When you run your routing for Dijkstra with particular "source" and "target" it runs fine and gives you the shortest path. But when you are choosing same "source" and "target" for pgr_ksp it gives nothing.

It is only because from that particular "source" there is no possible way forward. "target" of the next road segment is equal to the target of your current road segment.

Try another thing, switch your "source" and "target" value in the query. i mean target = 247542 and source = 258349

I hope you will get some route. Only reason is at some point of the route target nodes are same for road segment

  • I hope you understand my answer, i have this same problem, now kindly suggest a solution to that – osqureshi Apr 11 '14 at 8:08
1

I found the issue.

pgr_dijkstra is able to found the nodes in reverse direction also.

means if you exchange the target to source and source to target it is able to identify the shortest path.

Where as pgr_KSP will not give the shortest path if you try to identify path from target to source.

ex: execute below query.

select id::integer as id , source::integer as source, target::integer as target, cost::double precision as cost from edge_table

you might have the below result as per pg routing sample data.

id source target cost 1 1 2 1 2 2 3 1

  • pgr_dijkstra giving result and pgr_KSP is not giving means. execut e and see your sql query and observe the source and targets. – Veeranjaneyulu .Kota Jun 29 '17 at 6:22
  • issue is with source and target of your network/topology table. try replacing one route source and target each other, then it will work. but this is not the right solution. We have to create our topology with bidirectional. – Veeranjaneyulu .Kota Jul 7 '17 at 11:21
0

pgr_ksp returns 5 attributes:

  • seq: sequence for ording the results
  • id1: route ID
  • id2: node ID
  • id3: edge ID (0 for the last row)
  • cost: cost to traverse from id2 using id3

pgr_dijkstra returns only 4 attributes, where id2 has a different meaning in each function.

For pgr_ksp you probably need to write LEFT JOIN ways b ON (a.id3 = b.gid) instead.

  • I have made the modification you suggested "247542, 258349, 3, false) a LEFT JOIN ways b ON (a.id3 = b.gid)" but still no rows are returned. – Cathal Coffey Oct 29 '13 at 18:28
  • to my understanding and knowledge you are getting no rows because of these values of source and target. there is no route possible between these node because of the direction – osqureshi Apr 17 '14 at 10:50
0

Change your query as below. add reverse_cost also . It will work.

SELECT gid AS id,
     source::integer,
     target::integer,
     length::double precision AS cost,
     length::double precision AS reverse_cost
    FROM ways

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.