Milestone 3: Finding Routes ECE 297. Directions: How?

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

Decision Maths Networks Kruskals Algorithm Wiltshire Networks A Network is a weighted graph, which just means there is a number associated with each.
Problem solving with graph search
Informed search strategies
CS203 Lecture 15.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
1 The Limits of Computation Intractable and Non-computable functions.
GRAPHS Lecture 18 CS2110 – Fall Graph Algorithms 2 Search –depth-first search –breadth-first search Shortest paths –Dijkstra's algorithm Minimum.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
CSE 380 – Computer Game Programming Pathfinding AI
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
Breadth-First Search Graph Algorithm Type #3. Depth-First Search.
9.2 The Traveling Salesman Problem. Let us return to the question of finding a cheapest possible cycle through all the given towns: We have n towns (points)
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
1 Internet Networking Spring 2002 Tutorial 6 Network Cost of Minimum Spanning Tree.
Graphs & Graph Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
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.
Backtracking.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Fundamentals, Terminology, Traversal, Algorithms Graph Algorithms Telerik Algo Academy
1 Ethics of Computing MONT 113G, Spring 2012 Session 13 Limits of Computer Science.
Representing and Using Graphs
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs. Made up of vertices and arcs Digraph (directed graph) –All arcs have arrows that give direction –You can only traverse the graph in the direction.
Informed search strategies Idea: give the algorithm “hints” about the desirability of different states – Use an evaluation function to rank nodes and select.
Administration CI meetings resume next week, as usual Some TAs in labs, plus Dr. Betz –Go to your lab as usual –If your TA is not there, ask for help from.
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.
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Review: Tree search Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search.
Trees, Binary Search Trees, Balanced Trees, Graphs Graph Fundamentals Telerik Algo Academy
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
Graphs. Introduction Graphs are a collection of vertices and edges Graphs are a collection of vertices and edges The solid circles are the vertices A,
LIMITATIONS OF ALGORITHM POWER
Breadth First Search and Depth First Search. Greatest problem in Computer Science Has lead to a lot of new ideas and data structures Search engines before.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: Graphs Data Structures.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
Algorithm Analysis with Big Oh ©Rick Mercer. Two Searching Algorithms  Objectives  Analyze the efficiency of algorithms  Analyze two classic algorithms.
Week 11 - Wednesday.  What did we talk about last time?  Exam 2  And before that:  Graph representations  Depth first search.
Graphs. What is a graph? In simple words, A graph is a set of vertices and edges which connect them. A node (or vertex) is a discrete position in the.
Breadth-First Search Graph Algorithm Type #3.
Review: Tree search Initialize the frontier using the starting state
Graphs Representation, BFS, DFS
Depth First Seach: Output Fix
Tutorial 8 An optional eighth tutorial will be held the week of March 6. This tutorial will give you practice with and feedback on oral presentation and.
Data Structures and Algorithms for Information Processing
Graphs Chapter 13.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Search Related Algorithms
Chapter 11 Graphs.
COS 461: Computer Networks Spring 2014
Networks Kruskal’s Algorithm
CSE 373: Data Structures and Algorithms
Milestone 3: Finding Routes
Breadth-First Search Graph Algorithm #2.
Efficiently Estimating Travel Time
BFS: Min. Path Issues What happened? Node 1 was re-expanded
Graphs: Shortest path and mst
Presentation transcript:

Milestone 3: Finding Routes ECE 297

Directions: How?

Model as Graph Problem (Node) (Edge) Bathurst Path: sequence of connected nodes from a source to a dest source dest

Model as Graph Problem Path: store as sequence of nodes? Bathurst source dest back lane Now sequence of nodes doesn’t uniquely describe path

Model as Graph Problem Bathurst Better: sequence of connected edges from a source to a dest source dest

Finding Routes Find path from source to dest –Is there only one path? Any path? Fewest nodes? Fewest edges? Minimum travel time! Graph texts: minimum weight path or shortest path source dest

Blue path: 200 m / 40 kmh m / 50 kmh + 1 turn  18 s s + 15 s = 54.6 s 200 m 300 m Red path: 100 m / 40 kmh m / 40 kmh m / 50 kmh + 2 turns  9 s + 18 s s + 2*15 s = 71.4 s 100 m Minimum Travel Time Definition Distance / speed limit + 15 s per street change Which is better? source dest

Minimum Travel Time Definition Don’t left turns take longer than right turns? –Yes, we’re ignoring to keep simple Name change with no turn? –15 s Bloor St. EastBloor St. West Yonge St. 15 s penalty No penalty

Other Shortest Path Applications Any Ideas?

Internet Routing source dest Nodes: computers and switches Edges: cables Find a path to connect computers Typical minimum weight path definition: Fewest routers Or least congested

Circuit Board Design Nodes: small square for metal Edges: squares we can connect Find paths to connect chip I/Os

Integrated Circuits Nodes: small grid squares for metal Edges: squares we can connect Find paths to connect gates Huge graph (tens of millions of nodes)  need fast algorithms

Depth First Search Shortest Path Algorithm #1

Recursion? int main () { Node *sourceNode = getNodebyID (sourceID); bool found = findPath (sourceNode, destID);... } bool findPath (Node* currNode, int destID) {... } source dest

bool findPath (Node* currNode, int destID) { if (currNode->id == destID) return (true); for each (outEdge of currNode) { Node *toNode = outEdge.toNode; bool found = findPath (toNode, destID); if (found) return (true); } return (false); } Recursion? source dest

Recursion? source dest bool findPath (Node* currNode, int destID) { if (currNode->id == destID) return (true); for each (outEdge of currNode) { Node *toNode = outEdge.toNode; bool found = findPath (toNode, destID); if (found) return (true); } return (false); } Infinite Loop!

How to Fix? source dest bool findPath (Node* currNode, int destID) { if (currNode->id == destID) return (true); currNode->visited = true; for each (outEdge of currNode) { Node *toNode = outEdge.toNode; if (!toNode->visited) { bool found = findPath (toNode, destID); if (found) return (true); } } return (false); } toNode visited

Output? source dest bool findPath (Node* currNode, int destID) {... return (true);... } Says whether or not a path was found But not what the path is! Worst directions ever: yes, a path exists! How to fix?

Easy Fix source dest bool findPath (Node* currNode, int destID, list path) { if (currNode->id == destID) return true; currNode->visited = true; for each (outEdge of currNode) { Node *toNode = outEdge.toNode; if (!toNode->visited) { list newPath = path; newPath.push_back (outEdge); bool found = findPath (toNode, destID, newPath); if (found) return (true); } } return (false); } Anything Missing? a b c d {} {a} {a,b} {a,b,c,d} {a,b,c}

bool findPath (Node* currNode, int destID, list path) { if (currNode->id == destID) print out or save the path, then return (true); currNode->visited = true; for each (outEdge of currNode) { Node *toNode = outEdge.toNode; if (!toNode->visited) { list newPath = path; newPath.push_back (outEdge); bool found = findPath (toNode, destID, newPath); if (found) return (true); } return (false); } Easy Fix Part 2 source dest

Depth First Search (DFS) Developed depth first search in a graph –Need a visited flag –Unlike a tree (can go in circles otherwise) Graph is big (>100,000 nodes, N) –Complexity of DFS?

bool findPath (Node* currNode, int destID, list path) { if (currNode->id == destID) print out or save the path, then return (true); currNode->visited = true; for each (outEdge of currNode) { Node *toNode = outEdge.toNode; if (!toNode->visited) { list newPath = path; newPath.push_back (outEdge); bool found = findPath (toNode, destID, newPath); if (found) return (true); } return (false); } Complexity Analysis At most one findPath call per Node Executes once per outgoing edge Average: about 4

Complexity findPath executes at most O(N) times –Constant, O(1), work in each call –Except copying path – path could have O(N) nodes –Total worst-case complexity: O(N 2 ) –Average path shorter  Average case somewhat better, but hard to analyze

Complexity Can we do better? –Don’t pass entire path around –One way: each Node stores the edge used to reach it –Reconstruct path when you reach the dest By following the previous edges / “bread crumbs” –Now work per findPath is O(1)  Total complexity is O(N) Good for a graph algorithm!

DFS - Demo