Friday, 16 December 2016

pgrouting - How Does Directed and has_reverse_cost Arguments when set to [true, false] and [true, true] Affect Routing?



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.




Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...