Download presentation

Presentation is loading. Please wait.

1
Tirgul 12 Algorithm for Single-Source-Shortest-Paths (s-s-s-p) Problem Application of s-s-s-p for Solving a System of Difference Constraints

2
Dijkstra – Review The idea: Maintain a set of vertices whose final shortest path weights from s have already been determined Each time, the vertex whose estimate for the shortest path is minimal is added to the set and all edges leaving it are ‘ Relaxed ’ Assumption: all edge weights are non-negative Proof of correctness depends on it Exercise – where does the proof fail if there are negative weights ?

3
Dijkstra Run Time In case the priority queue is implemented as a binary heap. Build heap takes O(V). Operation over the heap O(logV). Altogether O(VlogV). Going over the adjacent list O(E). Relaxation is an operation over the heap O(logV). Altogether O(ElogV). Every thing together O(ElogV+VlogV)=O(ElogV)

4
Bellman-Ford ’ s Algorithm Can handle negative weights, as long as there are no negative cycles reachable from s If there is a negative cycle – the solution to the problem is not defined.

5
Bellman-Ford ’ s Algorithm The idea: The shortest path from s to any other vertex does not contain a positive cycle (can be eliminated to produce a lighter path) The longest path (in number of edges) without cycles between any pair of vertices is |V|-1 edges long it is enough to check paths of up to |V|-1 edges

6
Bellman-Ford ’ s Algorithm

7
The first pass over the edges – only neighbors of s are affected (1 edge paths) The second pass – shortest paths of 2 edges are found After |V|-1 passes, all possible paths are checked. If we need to update any vertex in the last pass – there is a negative cycle reachable from s in G

8
Bellman-Ford Run Time The algorithm run time is: Goes over v-1 vertexes, O(V) For each vertex relaxation over E, O(E) Altogether O(VE)

9
Application of Bellman-Ford The Bellman-Ford algorithm can be used to solve a set of difference constraints. The set of difference constraints is formalized to the following set of linear inequalities :

10
Application of Bellman-Ford There are many uses for a set of difference constraints, for instance: The variables can represent the times of different events The inequalities are the constraints over there synchronization. The set of linear inequalities can also be expressed in matrix notation: A · x b

11
Application of Bellman-Ford A · x b

12
Application of Bellman-Ford What is the connection between the Bellman-Ford algorithm and a set of linear inequalities? We can interpreted the problem as a directed graph. The graph is called the constraint graph of the problem After constructing the graph, we could use the Bellman-Ford algorithm. The result of the Bellman-Ford algorithm is the vector x that solves the set of inequalities.

13
Application of Bellman-Ford Building the constraint graph out of matrix A: Each column represents a vertex (node) Each row represents an edge If edge i goes out of vertex j than A[i,j]= -1 If edge i goes into vertex j than A[i,j]= 1 Otherwise A[i,j]= 0 Each row contains a single ‘ 1 ’, a single ‘ -1 ’ and zeros.

14
Application of Bellman-Ford The problem is represented by the graph: v1v1 v5v5 v4v4 v3v3 v2v2

15
Application of Bellman-Ford Extending the constraint graph to a single-source- shortest-paths problem will be done by : Adding vertex v 0 that directs at all the other vertices. Weight all edges from v 0 as zero. The weight of the other edges is determined by the inequality constraints.

16
Application of Bellman-Ford Formally: Each node v i corresponds to a variable x i in the original problem, and an extra node - v 0 (will be s). Each edge is a constraint, except for edges (v 0,v i ) that were added. Assign weights:

17
Application of Bellman-Ford The extended constraint graph: v0v0 v1v1 v5v5 v4v4 v3v3 v2v2 0 0 0 0 0 0 1 5 4 -3

18
Application of Bellman-Ford The solution: v1v1 v5v5 v3v3 v2v2 0 0 0 0 0 0 1 5 4 -3 -4 v0v0 v4v4 -5 -3 0

19
Application of Bellman-Ford The Bellman-Ford solution for the extended constraint graph is a set of values which meets the constraints. Formally: Why is this correct?

20
Application of Bellman-Ford Because

21
Application of Bellman-Ford If there is a negative cycle reachable from v 0 – there are no feasible solutions: Suppose the cycle is where v k =v 1 v 0 cannot be on it ( it has no incoming edges) This cycle corresponds to :

22
Application of Bellman-Ford The left side sums to 0. The right side sums to the cycle ’ s weight w(c) We get But we assumed the cycle was negative …

23
Question Can any shortest path from to any vertex in the extended constrains graph be positive? v0v0

Similar presentations

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google