Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

What will be the difference on the routing behaviour when I try to play with the directed and has_reverse_cost arguments on all the three routing algorithms?

Example: the following SQL queries give me a different result each time.

SELECT rt.gid, ST_AsGeoJSON(rt.the_geom) AS geojson, at_2po_4pgr.gid FROM at_2po_4pgr, (SELECT gid, the_geom FROM dijkstra_sp_delta_directed( 'at_2po_4pgr', 66126, 9013, 0.1, false, false) ) as rt WHERE at_2po_4pgr.gid=rt.gid;

SELECT rt.gid, ST_AsGeoJSON(rt.the_geom) AS geojson, at_2po_4pgr.gid FROM at_2po_4pgr, (SELECT gid, the_geom FROM dijkstra_sp_delta_directed( 'at_2po_4pgr', 66126, 9013, 0.1, true, false) ) as rt WHERE at_2po_4pgr.gid=rt.gid;

SELECT rt.gid, ST_AsGeoJSON(rt.the_geom) AS geojson, at_2po_4pgr.gid FROM at_2po_4pgr, (SELECT gid, the_geom FROM dijkstra_sp_delta_directed( 'at_2po_4pgr', 66126, 9013, 0.1, true, true) ) as rt WHERE at_2po_4pgr.gid=rt.gid;

I can understand if both are set to false but what if one is true and the other is false?

Any explanation please?

Thanks.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Only matched booleans make any sense. Unmatched ones are either irrelevant or 'broken':

  1. FALSE FALSE: Undirected graphs (“directed false”) ignore “has_reverse_cost” setting, which means you can travel in both directions between any pair of nodes and the cost is the same both ways.
  2. TRUE TRUE: This is a directed graph and the cost of reverse travel is taken from a reverse cost attribute column. For instance, if you have a one-way street, you would set this to be negative (which stops the link being used in the calculation), or perhaps your cost is fuel consumption rather than distance and the reverse link is uphill, in which case you would have a higher figure for the reverse direction.
  3. FALSE TRUE: This is an undirected graph, so setting the 'has_reverse_cost' to TRUE is irrelevant.
  4. TRUE FALSE: This is a directed graph, so setting the 'has_reverse_cost' to FALSE does not make any sense. PgRouting will expect a reverse_cost column in the data so this statement is broken.

So your only logical options are when both booleans match. Of course, that begs the question why the developers implemented the two booleans as it would indeed seem that the second one is redundant in all cases and only the 'directed' true/false option is necessary.

share|improve this answer
    
i tried to re-read the latest pgrouting workshop tutorial, workshop.pgrouting.org/chapters/shortest_path.html, then i notice under the note tag on each routing algorithm, it mentions this "Undirected graphs (“directed false”) ignore “has_reverse_cost” setting" what exactly does try to tell me? that if i want either directed or undirected graph, just set the directed accordingly and ignore the has_reverse_cost? –  Charles Jordan Cabero Jan 16 '13 at 4:01
    
Not quite. For an undirected graph set False False. For a directed graph make sure you have a 'reverse-cost' attribute and set True True. –  MappaGnosis Jan 16 '13 at 8:51
add comment

I'm not really sure, but as far as I remember pgRouting creates edges on-the-fly each time you calculate a route. Hence a combination of FALSE TRUE does make sense because in this case pgRouting creates additional reverse ones. osm2po outputs undirected graphs with reverse_cost, meaning you should get correct results with regards to the one-ways. Here FALSE TRUE should be set. As a consequence TRUE TRUE is the combination which doesn't make sense. Because the reverse cost is implicitly set by the forward cost of the reverse edge. But maybe Daniel is following this thread and can give us a final best-practise.

share|improve this answer
    
i tried to re-read the latest pgrouting workshop tutorial, workshop.pgrouting.org/chapters/shortest_path.html, then i notice under the note tag on each routing algorithm, it mentions this "Undirected graphs (“directed false”) ignore “has_reverse_cost” setting" what exactly does try to tell me? that if i want either directed or undirected graph, just set the directed accordingly and ignore the has_reverse_cost? –  Charles Jordan Cabero Jan 16 '13 at 4:02
    
I've just checked it and my assumption above is correct. For osm2po-tables you'll have to set either FALSE TRUE or FALSE FALSE. The first pair does take oneways into account, the second ignores them. But I used shortest_path() instead of dijkstra_sp_delta_directed() which is a wrapper. The name implies that it expects directed graphs only. If so, don't use it for osm2po-tables. –  Carsten Jan 16 '13 at 8:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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