All-pairs shortest-paths problem

Given a weighted directed graph and being the weight of edge , we want to either find:

  • information whether contains a negative cycle; if it doesn’t,
  • an matrix such that is equal to (shortest-path from node to node ); and shortest-paths trees, one from each node in graph

    We skip computation of shortest-paths trees.

Solving the problem by repeatedly applying single-source shortest-paths algorithm

  • If all edge weights are non-negative:
    • Use Dijkstra’s algorithm
    • Total running time is
    • No method with a better (worst-case) running time is known
  • In general case, when edge weights may be negative:
    • We may use Bellman-Ford algorithm Total running time is This is if
    • Floyd-Warshall algorithm:
    • Johnson’s algorithm:

Changing weights of edges without changing shortest-paths

Say we have a graph as follows, and we want to change the weight of edges (ideally without removing negative weights) without changing shortest paths? Adding the same (large) number to the weight of each edge doesn’t work. In Johnson’s algorithm, we add and subtract on each edge:

Johnson’s algorithm

The main idea behind Johnson’s algorithm is that it reduces the general case (where edge weights may be negative) to the case where all edge weights are non-negative.

Re-weighting: compute new edge weights with properties:

  1. For all , shortest path from to using original weights is also a shortest path from to using the new weights
  2. for each

Explaining re-weighting

General idea for re-weighting:

  • for each node , assign a number to
  • for each , let

For any numbers , the new edge weights satisfy Property 1. If no negative cycle in , then we can find numbers which also satisfy Property 2.

For any :

Thus when we change the edge weights from to , then for each pair of nodes and , the weight of each path from to changes by the same amount:

Hence a path is a shortest path from to according to weights , if and only if, is a shortest path from to according to weights .

We also have, from : .

Example: computation of new edge weights

Johnson's Algoithm

def johnson(G, w):
	(V, E) = G
	
	G' = G # clone the graph
	(V', E') = G'
	V' = V | {s} # s is a new node
	E' = E | {(s, v) | v in V} # edges from s to all v
	
	for v in V:
		w(s, v) = 0
	
	if not bellman_ford(G', w, s):
		# terminate: input graph G contains negative cycle
	else: # bellman_ford has computed values δ(s,v)
		for v in V:
			h(v) = δ(s, v)
		
		w' = w # clone weights
		for (u, v) in E:
			w'(u, v) = w(u, v) + h(u) - h(v)
		
		for u in V:
			dijkstra(G, w', u) # compute δ(u, v) for all v in V
			
			for v in V:
				d_uv = δ(u, v) - [h(u) - h(v)]
		
	return D = d_uv

Correctness of Johnson's algorithm

  1. Input graph contains a negative cycle, if and only if, there is a negative cycle in graph reachable from . This means the algorithm correctly identifies whether the input graph has a negative cycle.
  2. For each edge in , the new weight assigned to this edge in Johnson’s algorithm is non-negative. (Triangle inequality for shortest-path weights) so Non-negative weights imply that the algorithm correctly computes for any pairs of vertices.
  3. For any numbers and for each pair of nodes and in : Thus the algorithm correctly computes for all pairs of vertices.

Point-to-point shortest-paths in geographical networks

Geographical networks: geographical coordinates of nodes are known; weights of edges are at least straight-line (geographical) distances between the nodes

Dijkstra’s for single-source single-destination

We can run in parallel, two Dijkstra’s computations, one from the source and one from the destination(s) (considering edges backward). We stop when shortest path is found. We may or may not check the whole network.

However, we need to figure out if the combined path (one part from the shortest-path tree from and the other part from the shortest-path tree to ) is the shortest path.

Dijkstra’s for ‘geographical’ networks (basis of A* algorithm)

Given the nodes are geographical places and we know their coordinates: the weights of edges are at least straight-line distances between the nodes. We want to consider this information to speed-up Dijkstra’s computation for shortest source-destination path.

We can use re-weighting of edges to prioritise those which are ‘geographically’ closer to the destination, we use where is the straight-line distance from node to destination .

As the search is directed towards the destination, not many additional edges (away from the shortest path) are considered. This can lead to considerable improvement in average running time.

Worst-case running time remains as in the main Dijkstra's algorithm for single-source (all destinations) case.

Correctness of re-weighting with distance

Re-weighting by straight-line distances to destination works because the straight-line distances satisfy the triangle inequality: So the new weights are non-negative: The straight-line distances are used here as (under)-estimates of the shortest-path weights.

A* search algorithm

The modified Dijkstra’s algorithm with re-weighting using a cost estimate function is the A search algorithm*. In A*, the function is called a heuristic function, often denoted by .

The property of the heuristic function which guarantees that when the target is taken from , then the shortest path to is computed: For each edge , .

A heuristic function which satisfies this property is called consistent or monotone, and is equivalent to the property that all new weights are non-negative.

Slides 12-18 this is all waffle?

1 item under this folder.