Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.

Slides:



Advertisements
Similar presentations
Single Source Shortest Paths
Advertisements

October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CS138A Single Source Shortest Paths Peter Schröder.
Chapter 5 Shortest Paths: Label-Correcting Algorithms
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
Length of a Path The weight (length) of a path is the sum of the weights of its edges. adcbe Path p: Edge weights: w(a, b) = 7, w(b, c) = 2, w(c,
1 Maximum Flow Networks Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘capacity’ u ij. Goal: Determine the maximum amount.
Shortest Paths1 C B A E D F
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.
Lecture 19: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Shortest Path Problems
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
1 8a-ShortestPathsMore Shortest Paths in a Graph (cont’d) Fundamental Algorithms.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
TCOM 501: Networking Theory & Fundamentals
Shortest Paths Definitions Single Source Algorithms
Tirgul 13. Unweighted Graphs Wishful Thinking – you decide to go to work on your sun-tan in ‘ Hatzuk ’ beach in Tel-Aviv. Therefore, you take your swimming.
Shortest Paths1 C B A E D F
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm
Chapter 4 Shortest Path Label-Setting Algorithms Introduction & Assumptions Applications Dijkstra’s Algorithm.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
CSCI-455/552 Introduction to High Performance Computing Lecture 18.
Operations Research Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD4207 University of Palestine.
Shortest Path. Dijkstra’s Algorithm finds the shortest path from the start vertex to every other vertex in the network. We will find the shortest path.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
1 Network Optimization Chapter 3 Shortest Path Problems.
Modeling and Evaluation with Graph Mohammad Khalily Dermany Islamic Azad University, Khomein branch.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
Minimum Spanning Trees Suppose G = (V, E) is a undirected network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …) Determine.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
15.082J & 6.855J & ESD.78J September 23, 2010 Dijkstra’s Algorithm for the Shortest Path Problem.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
Introduction to Algorithms Jiafen Liu Sept
Diverse Routing Algorithms
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
The single-source shortest path problem (SSSP) input: a graph G = (V, E) with edge weights, and a specific source node s. goal: find a minimum weight (shortest)
1 Network Models Transportation Problem (TP) Distributing any commodity from any group of supply centers, called sources, to any group of receiving.
Lecture 13 Algorithm Analysis
Graphs Upon completion you will be able to:
Supplementary: Feasible Labels and Linear Programming  Consider the LP formulation of the shortest s-t path problem: (P) Minimize  (i, j)  A c ij x.
Length of a Path The weight (length) of a path is the sum of the weights of its edges. adcbe Path p: Edge weights: w(a, b) = 7, w(b, c) = 2, w(c,
Introduction to Algorithms All-Pairs Shortest Paths My T. UF.
15.082J & 6.855J & ESD.78J September 30, 2010 The Label Correcting Algorithm.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
School of Computing Clemson University Fall, 2012
Shortest Paths CONTENTS Introduction to Shortest Paths (Section 4.1)
EMIS 8374 Dijkstra’s Algorithm Updated 18 February 2008
Shortest Path.
Shortest Path.
Dijkstra’s Algorithm for the Shortest Path Problem
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
EMIS 8374 Shortest Path Problems: Introduction Updated 9 February 2008
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Shortest Path.
CSE 373 Data Structures and Algorithms
CSE 417: Algorithms and Computational Complexity
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest length between two specified nodes s and t. The length c(P) of a path P is the sum of its constituent arc lengths: c(P) = Σc ij Applications: transportation planning (shortest route) telecommunications (most reliable connection) scheduling (critical path) pattern recognition, computer graphics subproblem to a larger optimization problem Shortest Paths

1. Differentiated by the number of origin/destination(source/sink) vertices: from s to t from s to all other vertices to t from all other vertices from i to j 2. Differentiated by the properties of the edge length: Nonnegative edge lengths Negative edge lengths Different Types of SPP

1.Integer data 2.Directed network 3.There is a path from s to all other vertices 4.There is no negative length directed cycle Two algorithms to be studied: Label-setting – no negative length edges Label-correcting – negative length edges allowed KEY IDEA: Distance labels – D(i) = how far away vertex i is from s Assumptions & Algorithms

Let d j correspond to the distance of the shortest path from vertex s to vertex j. Certainly d s =0. Moreover, the condition d j ≤ d i + c ij (***) says that if we have a shortest path its length cannot be improved by means of an edge (i, j) not currently on the path. This condition (***) is used in both algorithms to efficiently solve the SPP. FOCUS: single source problems, first with nonnegative costs, then allow negatives. Optimality Conditions

Key observation: any subpath of a shortest path is also a shortest path When we find a shortest path from s to t, we also find a shortest path from s to any intermediate vertices. This leads to a way of representing all shortest paths from vertex s. Find a shortest path from s to some t; call it P 1. Repeat with another vertex t not on path P 1. Repeat until all vertices are used. This results in a shortest path tree for G. Namely, a directed tree in G whose paths s to j are all shortest paths from s to j. s b a ct Shortest Path Trees

Use two arrays to represent the shortest path tree. d(i) records the shortest distance to vertex i. p(i) records the predecessor of vertex i in the shortest path Example -p(i) i 0d(i)

Nonnegative edge lengths: At each step in the algorithm, temporarily labeled vertices have a distance label of D(i), which is an upper bound on d(i); permanently labeled vertices are guaranteed to have D(i) = d(i). Two sets to keep track of: S is the set of permanently labeled vertices; Ŝ = V – S is the set of temporarily labeled vertices Vertices are transferred from Ŝ to S, one at a time. Upon termination, all vertices are permanently labeled. The algorithm processes vertices in increasing distance from vertex s. At the k th iteration, the k th closest vertex to s will be permanently labeled. S S ^ s b a ct Label Setting Algorithms

If network has a topological order, examine vertices from 1 to n (reaching). If no topological order exists, examine vertices in order of increasing distance from s (Dijkstra’s Algorithm). DIJKSTRA’S start with all vertices in Ŝ; give vertex s a distance D(s) = 0; give all other vertices the distance D(j) = ∞; while set S is not full pick a vertex, i, in Ŝ with the smallest distance; move that vertex from Ŝ to S; update distances for vertices reachable from i; for each (i,j) in E(i) if D(j) > D(i) + c ij then D(j) = D(i) + c ij and pred(j) = i; Topological(Acyclic) or Not Topological

i p(i) D(i)0 ∞∞∞∞∞ i p(i)0 D(i) Example move to S

i p(i)01 D(i) i p(i)012 D(i) Example move to S

i p(i)0122 D(i) i p(i)01223 D(i) Example move to S

p(i) i D(i) Example 7

0D(i) ∞∞∞∞∞ i Example – Topological

Example – Dijkstra’s 0D(i) ∞∞∞∞∞ i

s t Example

Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij = positive, zero, negative d(j) = minimum length of a path from s to j D(j) = distance label, current length of some path from s to j D(j) = d(j) for all j in V iff D(j) ≤ D(i) + c ij for all (i,j) in E(i) and D(s) = 0 Label Correcting In a network with negative edge lengths, maintain a LIST of vertices with changed labels (Bellman-Ford Algorithm). Search edge list and update until no distance is changed. Maintain LIST as: Queue – FIFO Stack – LIFO Dequeue – vertex selected from top; first time vertex is added, it is placed at the bottom; and anytime after that, a vertex re-enters at top of list

Queue Stack Dequeue (Pape) List Structures enter leave enter leave enter re-enter leave

∞∞ ∞ ∞∞ 0D(i) i =List 0D(i) =List ∞∞∞3 {1} {2, 3} queue

∞∞ ∞ ∞∞ 0D(i) i =List D(i) 0 =List ∞ ∞∞3 {1} {2, 3} dequeue

A negative length cycle will cause some distance labels to decrease without limit. With label correcting algorithms, negative length cycles can be detected in a variety of ways. 1. If C is max of all |c ij |, then any D(j) falling below -nC. 2. In the queue(FIFO) implementation, more than n-1 updates for a single vertex. 3. If the graph based on predecessors fails to be a tree Negative cycle detection

1. Apply Dijkstra’s n times, once for each vertex. Good for sparse network. 2. Floyd-Warshall Algorithm finds best in phases. Good for dense network. Assume network is strongly connected. Matrix entry D(i, j) = distance from i to j. Floyd-Warshall begin set D(i, j) = c ij, pred(i, j) = i for each (i, j) in E; set D(i, i) = c ii, pred(i, i) = i for each i; for k = 1 to n do for all i,j = 1 to n do if D(i, j) > D(i, k) + D(k, j) then D(i, j) = D(i, k) + D(k, j) and pred(i, j) = pred(k, j); end All Pairs Shortest Path

Example 013∞∞ 201∞∞ ∞∞0∞2 ∞4∞0∞ ∞∞∞ k = 0 k = 1 D =pred= ∞∞ ∞0 40 ∞ k = 2 D =pred=

Example k = 5 D =pred= What is shortest path from 1 to 4? What is shortest path from 5 to 3? 4