Geography and CS Philip Chan. How do I get there? Navigation Which web sites can give you turn-by-turn directions?

Slides:



Advertisements
Similar presentations
Problem solving with graph search
Advertisements

Lecture 19: Parallel Algorithms
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Chapter 14 Weighted Graphs © John Urrutia 2014, All Rights Reserved1.
The Greedy Approach Chapter 8. The Greedy Approach It’s a design technique for solving optimization problems Based on finding optimal local solutions.
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Sociology and CS Philip Chan. How close are people connected? Are people closely connected, not closely connected, isolated into groups, …
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
Outline 1. General Design and Problem Solving Strategies 2. More about Dynamic Programming – Example: Edit Distance 3. Backtracking (if there is time)
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Chapter 7: Greedy Algorithms 7.4 Finding the Shortest Path Dijkstra’s Algorithm pp
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
1 Lecture 25: Parallel Algorithms II Topics: matrix, graph, and sort algorithms Tuesday presentations:  Each group: 10 minutes  Describe the problem,
Graphs.
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.
Shortest path algorithm. Introduction 4 The graphs we have seen so far have edges that are unweighted. 4 Many graph situations involve weighted edges.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
1 Parallel Algorithms III Topics: graph and sort algorithms.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Route Planning Vehicle navigation systems, Dijkstra’s algorithm, bidirectional search, transit-node routing.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Distance Indexing on Road Networks A summary Andrew Chiang CS 4440.
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
1 Shortest Path Calculations in Graphs Prof. S. M. Lee Department of Computer Science.
Dijkstra's algorithm.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
COSC 2007 Data Structures II Chapter 14 Graphs III.
Representing and Using Graphs
Graph Algorithms. Definitions and Representation An undirected graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
CPSC 320: Intermediate Algorithm Design & Analysis Greedy Algorithms and Graphs Steve Wolfman 1.
Dijkstra’s Algorithm Supervisor: Dr.Franek Ritu Kamboj
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.
L3-Network Algorithms L3 – Network Algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems by: Irene Rangel, updated Nov by Abdulghani.
Week 12 - Monday.  What did we talk about last time?  Topological sort and cycle detection in directed graphs  Connectivity  Strong connectivity.
CS 101 – Nov. 30 Communication, continued TCP/IP review Dijkstra’s shortest path algorithm Download speeds.
Graphs. Graph Definitions A graph G is denoted by G = (V, E) where  V is the set of vertices or nodes of the graph  E is the set of edges or arcs connecting.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Graphs – Part III CS 367 – Introduction to Data Structures.
Shortest Paths.
Chapter 7: Greedy Algorithms
Single-Source Shortest Paths
Shortest Path Problems
Shortest Path Problems
CS330 Discussion 6.
Shortest Path Graph represents highway system Edges have weights
Lecture 22: Parallel Algorithms
Shortest Paths.
CSE373: Data Structures & Algorithms Lecture 18: Dijkstra’s Algorithm
A* Path Finding Ref: A-star tutorial.
CSE 373: Data Structures and Algorithms
Graphs.
Shortest Path Problems
Floyd’s Algorithm (shortest-path problem)
Chapter 15 Graphs © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
CSE 373: Data Structures and Algorithms
Shortest Path Problems
Efficiently Estimating Travel Time
CSE 373 Data Structures and Algorithms
Shortest Path Problems
Shortest Paths.
Graphs.
Richard Anderson Spring 2016
Presentation transcript:

Geography and CS Philip Chan

How do I get there? Navigation Which web sites can give you turn-by-turn directions?

Navigation [Problem understanding] Finding a route from the origin to the destination “Static” directions Mapquest, Google maps “Dynamic” on-board directions GPS navigation if the car deviates from the route, it finds a new route

Consider a Simpler Problem A national map with only Cities and Highways That is, ignoring smaller streets and intersections in a city small roads between cities …

Navigation [Problem Formulation] Given (input) Map (cities and highways) Origin city Destination city Find (output) City-by-city route between origin and destination cities

Graph Problem A graph has vertices and edges Cities -> vertices Highways -> edges City-by-city route -> shortest path

Shortest Path Problem How would you solve the shortest path problem?

Algorithm 1 Greedy algorithm 1. Pick the closest city 2. Go to the city 3. Repeat until the destination city is reached

Algorithm 1 Greedy algorithm 1. Pick the closest city 2. Go to the city 3. Repeat until the destination city is reached Does this always find the shortest path? If not, what could be a counter example?

Problem with Algorithm 1 What is the main problem?

Problem with Algorithm 1 What is the main problem? Committing to the next city too soon Any ideas for improvement?

Algorithm 2 “Exhaustive” algorithm Explore/generate all possible paths Not just the ones that look short Compare all possible paths

Greedy vs Exhaustive Greedy doesn’t guarantee the shortest path

Greedy vs Exhaustive Greedy doesn’t guarantee the shortest path Greedy is faster

Greedy vs Exhaustive Greedy doesn’t guarantee the shortest path Greedy is faster Greedy requires less memory

Algorithm 3 “smart” algorithm Guarantees the shortest path Faster than Exhaustive algorithm Any ideas on what we can ignore?

Algorithm 3 “Smart” algorithm Similar to Exhaustive explore all alternatives from each city Ignore alternative paths that are not shorter

Algorithm 4 “Smarter” algorithm Dijkstra’s algorithm Any ideas on additional alternatives that can be ignored?

Algorithm 4 “Smarter” algorithm Dijkstra’s algorithm Any ideas on additional alternatives that can be ignored? Hint: we can commit certain cities earlier Can’t have a shorter path to those cities Ignore the committed cities later

Algorithm 4 Keep track of alternative paths Commit to the next city when we are sure it is shortest no other paths are shorter

Algorithm 4 Let the current city be the origin (I) While the current city is not the destination(C) 1. Explore neighboring non-committed cities X’s of the current city if new path to X is shorter than current path to X  Update current path to X (ie, ignore the longer path) 2. Find the non-committed city that has the shortest path length 3. Commit that city 4. Update the current city to the committed city (U)

Algorithm 4 Why does it guarantee to find the shortest path? The shortest path to city X is committed When?

Algorithm 4 Why does it guarantee to find the shortest path? The shortest path to city X is committed when every path to the “non-committed” cities is longer

Algorithm 4 Why does it guarantee to find the shortest path? The shortest path to city X is committed when every path to the “non-committed” cities is longer  no way to get to city X with a shorter path via “non- committed” cities

Dijkstra’s shortest path algorithm Interesting applet to demonstrate the alg:

Comparing the Four Algorithms 1. “Greedy” Commit to closest neighboring city 2. “Exhaustive” Consider all possible paths, compare all paths 3. “Smart” Consider all neighboring cities, compare old and new paths, ignore the longer one 4. “Smarter” (Dijkstra’s) Consider only non-committed neighboring cities, compare old and new paths, ignore the worse one

Implementation of Dijkstra’s Algorithm Keeping track of information needed by the algorithm

Implementation 1 Simplified problem What is the shortest distance between origin and destination? We will worry about the intermediate cities later. Consider what we need to keep track (data) how to keep track (instructions)

What to keep track (data)?

Whether a city is committed

What to keep track (data)? Whether a city is committed What is the shortest distance so far for a city

What to keep track (data)? Whether a city is committed What is the shortest distance so far for a city How to implement the data storage?

What to keep track (data)? Whether a city is committed What is the shortest distance so far for a city How to implement the data storage? committed[city] pathLength[city] aka shortestDistance[city]

How to keep track (instructions)? Sketching on whiteboard

Implementation 2 We would like to know the intermediate cities as well the shortest path, not just the shortest distance

What to keep track (data)? Whether a city is committed What is the shortest distance so far for a city What else?

What to keep track (data)? Whether a city is committed What is the shortest distance so far for a city What else? What do you notice for each of the intermediate city?

What to keep track (data)? Whether a city is committed What is the shortest distance so far for a city What else? What do you notice for each of the intermediate city? Each was committed What do you notice when we commit a city and update the shortest distance?

What to keep track (data)? Whether a city is committed What is the shortest distance so far for a city What else? What do you notice for each of the intermediate city? Each was committed What do you notice when we commit a city and update the shortest distance? We know the previous city

What to keep track (data)? Whether a city is committed What is the shortest distance so far for a city What is the previous city How to implement the data storage? committed[city] pathLength[city] aka shortestDistance[city]

What to keep track (data)? Whether a city is committed What is the shortest distance so far for a city What is the previous city How to implement the data storage? committed[city] pathLength[city] aka shortestDistance[city] parent[city] aka previousCity[city]

Algorithm 4 with data tracking Let the current city be the origin (I) While the current city is not the destination(C) 1. Explore neighboring non-committed cities X’s of the current city if new path to X is shorter than current path to X  Update current path to X (pathLength[X], parent[X]) 2. Find the non-committed city that has the shortest path length 3. Commit that city (committed[city]) 4. Update the current city to the committed city (U)

Storing the map How to store the distance between two cities so that, given two cities, we can find the distance quickly?

How to keep track (instructions)? Sketching on whiteboard

Storing the Map How to store the distance between two cities so that, given two cities, we can find the distance quickly?

Storing the Map (graph) How to store the distance between two cities so that, given two cities, we can find the distance quickly? Adjacency matrix Table (2D array) Rows and columns are cities Cells have distance

Number of comparisons (speed of algorithm) Comparing: Shortest distance so far and Distance of an alternative path For updating what?

Number of comparisons (speed of algorithm) Comparing: Shortest distance so far and Distance of an alternative path For updating what? Shortest distance so far

Number of comparisons (speed of algorithm) Worst –case scenario When does it occur?

Number of comparisons (speed of algorithm) N is the number of cities Worst –case scenario When does it occur? Every city is connected to every city Maximum numbers of neighbors to explore

Worst-case scenario (speed of algorithm) How many comparisons? How many non-committed neighbors from the origin (in the first round)?

Worst-case scenario (speed of algorithm) How many comparisons? How many non-committed neighbors from the origin (in the first round)? N – 1 comparisons How many in the second round?

Worst-case scenario (speed of algorithm) How many comparisons? How many non-committed neighbors from the origin (in the first round)? N – 1 comparisons How many in the second round? N – 2 comparisons... How many in total?

Worst-case scenario (speed of algorithm) How many comparisons? How many non-committed neighbors from the origin (in the first round)? N – 1 comparisons How many in the second round? N – 2 comparisons... How many in total? (N-1) + (N-2) + … + 1

Worst-case scenario (speed of algorithm) How many comparisons? How many non-committed neighbors from the origin (in the first round)? N – 1 comparisons How many in the second round? N – 2 comparisons... How many in total (N-1) + (N-2) + … + 1 (N-1)N/2 = (N 2 – N)/2

Shortest Path Algorithm Dijkstra’s Algorithm In terms of vertices (cities) and edges (highways) in a graph 1959 more than 50 years ago Navigation optimization Cheapest (tolls) route? Least traffic route? Many applications

Summary Navigation problem Turn-by-turn directions Simplified: city-by-city directions Algorithms: Greedy: might not yield shortest path Dijkstra’s: always yield shortest path Reasons for guarantee Data structures in implementation Quadratic comparisons in # of cities