Handling one-way edges

All the routing algorithms that we have seen have an option to specify whether a graph is directed or non-directed. An edge of non-directed graphs can be travelled from source to target and from target to source with the same cost. When the cost of traveling in both directions is different, or an edge is not traversable in one of the directions, then a network is directed.

In pgRouting, cost and reverse cost is used for defining the rules of traveling in both directions (source to target and target to source). So, whenever telling the algorithms to assume a directed network is used, the reverse cost should be provided.

Basically, the rules are as follows:

  • Cost applies to edge traversal from source node to target node or, when a network is not directed, also from the target node to source node
  • Reverse cost applies to edge traversal from target to source and will only be used when assuming a directed network
  • To discourage the algorithm to use an edge in a given direction, cost should be set to a higher value
  • To remove an edge in a given direction from a graph completely, a cost should be set to a negative value

For example:

  id| source| target| cost| reverse_cost
----+-------+-------+-----+-------------
1| 1| 2| 0.1| 0.1
2| 1| 3| 0.1| 10000
3| 2| 3| -1| 0.1
4| 2| 4| 0.1| -1
  • Edge 1 is traversable in both directions
  • Edge 2 is also traversable in both directions, but the cost is high enough. So, if an edge has been used, it would mean there was no other way to get to the target; normally, algorithms would avoid traversing such edges
  • Edge 3 is only traversable from target to source node (3 -> 2); edge connecting nodes 2 -> 3 is not considered a part of the graph
  • Edge 4 is traversable only from source to target, but not the other way round; edge connecting nodes 4 -> 2 is not considered a part of the graph
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset