5. 最短路問題 Shortest Path Problem Problem Definition(1) Given : digraph G=(V, A) w:A →R (length w(a) of each arc a) W=(a 1, a 2, … a k ): a directed walk.

Slides:



Advertisements
Similar presentations
Chapter 6. Relaxation (1) Superstring Ding-Zhu Du.
Advertisements

* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
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,
Breadth-First Search of Graphs Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Introduction to Algorithms 6.046J/18.401J/SMA5503
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Approximation Algorithms Chapter 5: k-center. Overview n Main issue: Parametric pruning –Technique for approximation algorithms n 2-approx. algorithm.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Graph. Undirected Graph Directed Graph Simple Graph.
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.
Graphs and Trees This handout: Trees Minimum Spanning Tree Problem.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
Analysis of Algorithms CS 477/677 Shortest Paths Instructor: George Bebis Chapter 24.
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.
COS 423 Lecture 9 Shortest Paths II ©Robert E. Tarjan 2011.
Tirgul 13 Today we’ll solve two questions from last year’s exams.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 8 Greedy Graph.
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
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.
5.4 Shortest-path problem  Let G=(V,E,w) be a weighted connected simple graph, w is a function from edges set E to position real numbers set. We denoted.
1 Shortest Path Problems How can we find the shortest route between two points on a road map? Model the problem as a graph problem: –Road map is a weighted.
Chapter 2 Graph Algorithms.
Approximating Minimum Bounded Degree Spanning Tree (MBDST) Mohit Singh and Lap Chi Lau “Approximating Minimum Bounded DegreeApproximating Minimum Bounded.
Trees and Distance. 2.1 Basic properties Acyclic : a graph with no cycle Forest : acyclic graph Tree : connected acyclic graph Leaf : a vertex of degree.
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.
Master Method (4. 3) Recurrent formula T(n) = a  T(n/b) + f(n) 1) if for some  > 0 then 2) if then 3) if for some  > 0 and a  f(n/b)  c  f(n) for.
Introduction to Algorithms Jiafen Liu Sept
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)
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
Introduction to Graphs And Breadth First Search. Graphs: what are they? Representations of pairwise relationships Collections of objects under some specified.
Lecture 13 Algorithm Analysis
Graph -definition V : vertex set (頂点集合) A ⊆ V×V: arc set (枝集合) G=(V, A) discrete structure (離散構造) vertex (頂点) arc (枝)
Trees Thm 2.1. (Cayley 1889) There are nn-2 different labeled trees
Graphs Lecture 2. Graphs (1) An undirected graph is a triple (V, E, Y), where V and E are finite sets and Y:E g{X V :| X |=2}. A directed graph or digraph.
EMIS 8374 Shortest Path Trees Updated 11 February 2008 Slide 1.
Great Theoretical Ideas in Computer Science for Some.
COMPSCI 102 Introduction to Discrete Mathematics.
割当問題とマッチング Assignment Problem B=(b ij ) : n×n matrix C ⊆ {b ij |1 ≦ i ≦ n, 1 ≦ j ≦ n} C is diagonal ⇔ (1) ∀ b ij, b kh ∈ C, ⇒ i≠k and j≠h (2) |C | =
Trees.
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Algorithms and Data Structures Lecture XIII
Breadth-First Search The Breadth-first search algorithm
CSCE 411 Design and Analysis of Algorithms
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Basic Graph Algorithms
CS 583 Analysis of Algorithms
Advanced Algorithms Analysis and Design
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Shortest-Path Property 4.1
Lecture 13 Algorithm Analysis
CSCE 411 Design and Analysis of Algorithms
Lecture 13 Algorithm Analysis
Fundamental Data Structures and Algorithms
Chapter 24: Single-Source Shortest Paths
Fundamental Data Structures and Algorithms
Autumn 2016 Lecture 10 Minimum Spanning Trees
Advanced Algorithms Analysis and Design
Chapter 24: Single-Source Shortest Paths
Winter 2019 Lecture 10 Minimum Spanning Trees
Single-Source Shortest Path & Minimum Spanning Trees
Advanced Algorithms Analysis and Design
Data Structures and Algorithm Analysis Lecture 8
Presentation transcript:

5. 最短路問題 Shortest Path Problem

Problem Definition(1) Given : digraph G=(V, A) w:A →R (length w(a) of each arc a) W=(a 1, a 2, … a k ): a directed walk length of the walk W : w(W)=w(a 1 )+w(a 2 )+ … w(a k ) W

Problem Definition(2) v, v’ ∈ V distance between v and v’ mininum of all lengths of walk from v to v’ d(v, v’) = ( ∃ walk from v to v’) ∞ ( no walk from v to v’) v v’ d(v, v’)=4 shortest path from v to v’

Problem Definition(3) s v’ d(s, v’)=4 shortest path from s to v’ Given : digraph G=(V, A) w:A →R (length w(a) of each arc a) start vertex s (root of G) Find : shortest paths from s to other vertices

If G contains Negative cycles v v’ negative cycle : directed cycles of negative length there might be walks of arbitrary short length Assume that G does not contain any negative cycles.

Main Property d(v) := d(s, v) :distance between the start vertex s and v Lemma 5.1 d(s) = 0 d(v) = min{d(x) + w(x, v) | (x, v) ∈ A} ∀ v ∈ V - {s} Bellman’s equation v s

Lemma5.1(proof) ∀ v ∈ V - {s} (1) d(v) ≦ min{d(x) + w(x, v) | (x, v) ∈ A} (x, v) ∈ A, W(x): a walk from s to x of length d(x) W(x)+(x, v) is a walk from s to v (2) d(v) ≧ min{d(x) + w(x, v) | (x, v) ∈ A} W(v): a walk from s to x of length d(v) W(v) = (s, …, x’, v) W(v) - (x’, v) is a walk from s to x’ of length w(W(v))-w(x’, v)

Corollary ∀ v ∈ V - {s} d(x’)+w(x’, v) := min{d(x) + w(x, v) | (x, v) ∈ A} ⇒ there exists a shortest path from s to v containing a last arc (x’, v) A’ denotes a set of such an arc for each vertex v ∈ V - {s}. Then, (V, A’) is a spanning arborescence for G shortest path tree a unique path from s to each vertex v is a shoretst path from s to v

Shortest path tree s d(v)

When w(a)=1 ∀ a ∈ A Breadth first search label d satisfies Bellman’s equation breadth first search tree is a shortest path tree

When w(a) ≧ 0 ∀ a ∈ A Dijkstra algorithm begin set d(s)←0, d(v)←∞ for all v ∈ V- {s} and T←V; while T≠φ do begin find some u ∈ T such that d(u) is minimal; delete u from T; for v ∈ T∩Au do begin set d(v) ←min{d(v), d(u)+w(u, v) }; end end.

Dijkstra algorithm - example s 0 ∞ ∞ ∞ ∞ ∞ ∞ d(v) ∈T∈T : u sa, f ab, c bd ce, f da ea, d fe AvAv a b c d e f

Correctness Theorem 5.3 At the end of algorithm, d(v) is a distance from s to v for each v ∈ V.

Theorem5.3 (proof 1) d(t)<∞ ⇒ there exists a directed path of length d(t) from s to t. d(t) = ∞ ⇔ there exists no directed path from s to t. d(t) ≧ distance from s to t Show that d(t) ≦ distance from s to t using induction on the order in which vertices are removed from T. the first vertex removed from T = s d(s) = 0 ….. OK Assume that the inequality is true for all vertices t that were removed from T before u

Theorem5.3 (proof 2) P(u) = (sa 1 v 1 a 2 v 2 … v k-1 a k u) : shortest path from s to u Choose i to be the maximal index such that v i was removed from T before u. s a1a1 v1v1 a2a2 v2v2 vivi u akak P(v i ) by induction hypothesis, d(v i )=distance from s to v i = w(P(v i )) T In the next iteration, we remove u from T. Show that d(t) ≦ distance from s to t

Theorem5.3 (proof 3) s a1a1 v1v1 a2a2 v2v2 vivi u akak T s a1a1 v1v1 a2a2 v2v2 vivi u akak T when v i =v k-1 when v i ≠v k-1 v i+1 d(v i+1 ) ≦ d(v i )+w(a i+1 ) = distance from s to v i+1 ≦ distance from s to u Show that d(t) ≦ distance from s to t If d(u) > distance from s to u ⇒ d(v i+1 ) < d(u) contradict!

Think Think Think Modify Dijkstra algorithm such that it finds a shortest path form s to t as well not only a distance. That is, construct a shortest path tree. Solve a shortest path problem on an undirected graph. Solve a shortest path problem on a models with magnets and loops.

begin set d(s)←0, d(v)←∞ for all v ∈ V- {s} and T←V; set p(v) ←v for all v ∈ V; while T≠φ do begin find some u ∈ T such that d(u) is minimal; delete u from T; for v ∈ T∩Au do begin if (d(v) < d(u)+w(u, v)) do set d(v) ←d(u)+w(u, v) and p(v)←u; end end. Modified Dijkstra Algorithm

undirected -> directed

0 s magnets and loops model When you want to find a shortest path from s to v, why do you keep away v from s?

LP Finding a shortest path from s to t variable x :A→{0, 1} 1 ( when a shortest path contains an arc a) x(a) = 0 ( otherwise)

LP - dual