ECE 643- Design and Analysis of Computer Networks K Shortest Paths Dept. of Electrical and Computer Eng. George Mason University Fairfax, VA 22030-4444,

Slides:



Advertisements
Similar presentations
Traffic assignment.
Advertisements

ECE Longest Path dual 1 ECE 665 Spring 2005 ECE 665 Spring 2005 Computer Algorithms with Applications to VLSI CAD Linear Programming Duality – Longest.
§3 Shortest Path Algorithms Given a digraph G = ( V, E ), and a cost function c( e ) for e  E( G ). The length of a path P from source to destination.
1 Theory I Algorithm Design and Analysis (10 - Shortest paths in graphs) T. Lauer.
Computability and Complexity 23-1 Computability and Complexity Andrei Bulatov Search and Optimization.
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Data Structures Heaps and Graphs i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
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.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs.
Cache Placement in Sensor Networks Under Update Cost Constraint Bin Tang, Samir Das and Himanshu Gupta Department of Computer Science Stony Brook University.
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 10 / 14 / 2009 Instructor: Michael Eckmann.
Chapter 7 Network Flow Models.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Fibonacci Heaps. Single Source All Destinations Shortest Paths
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Fall 2006CSC311: Data Structures1 Chapter 3 Arrays, Linked Lists, and Recursion Objectives –Using Arrays –Singly Linked Lists –Doubly Linked Lists –Circularly.
Priority Queues, Heaps & Leftist Trees
CS 146: Data Structures and Algorithms June 18 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
CS 46B: Introduction to Data Structures July 30 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
Review Binary Tree Binary Tree Representation Array Representation Link List Representation Operations on Binary Trees Traversing Binary Trees Pre-Order.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Directed graphs Definition. A directed graph (or digraph) is a pair (V, E), where V is a finite non-empty set of vertices, and E is a set of ordered pairs.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Binary Search From solving a problem to verifying an answer.
Algorithm Paradigms High Level Approach To solving a Class of Problems.
Pointers OVERVIEW.
Homework #5 New York University Computer Science Department Data Structures Fall 2008 Eugene Weinstein.
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.
CS 206 Introduction to Computer Science II 10 / 05 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 02 / 13 / 2009 Instructor: Michael Eckmann.
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
Where’s the title? You gotta search for it!. PotW Solution String s = new Scanner(System.in).next(); int[] prev = new int[s.length() * 2 + 2]; Arrays.fill(prev,
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
HEAPS. Review: what are the requirements of the abstract data type: priority queue? Quick removal of item with highest priority (highest or lowest key.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
1. What is it? It is a queue that access elements according to their importance value. Eg. A person with broken back should be treated before a person.
Week 15 – Friday.  What did we talk about last time?  Student questions  Review up to Exam 2  Recursion  Binary trees  Heaps  Tries  B-trees.
1 Trees What is a Tree? Tree terminology Why trees? What is a general tree? Implementing trees Binary trees Binary tree implementation Application of Binary.
abstract data types built on other ADTs
Graphs – Part III CS 367 – Introduction to Data Structures.
SHORTEST ROUTE PROBLEM A Networking Model Report for DPA 702 QUANTITATIVE METHODS OF RESEARCH By: ALONA M. SALVA Cebu Technological University.
Heaps and Priority Queues
12. Graphs and Trees 2 Summary
Trees Lecture 12 CS2110 – Fall 2017.
Trees.
Week 11 - Friday CS221.
Single-Source Shortest Paths
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
CSCI2100 Data Structures Tutorial 7
HW05: Graphs and Shortest Paths
i206: Lecture 14: Heaps, Graphs intro.
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Analysis of Algorithms
Greedy Algorithms TOPICS Greedy Strategy Activity Selection
Graphs.
Graphs.
Heaps By JJ Shepherd.
Graphs.
Trees.
Graphs.
Graphs: Shortest path and mst
Analysis of Algorithms
Heaps Section 6.4, Pg. 309 (Section 9.1).
Presentation transcript:

ECE 643- Design and Analysis of Computer Networks K Shortest Paths Dept. of Electrical and Computer Eng. George Mason University Fairfax, VA , USA Fall 2012

Why KSP? Sometimes, it is necessary to consider additional constraints that are additive to the original routing problems, such as maximum delay requirement. Optimization of all the additive constraints also is NP-hard. Additive constraints only need to be satisfied rather than optimized. 2

How to KSP The calculation of KSP is based on the shortest path algorithm, which can be achieved through Dijkstra’s algorithm. Two different algorithms for KSP will be introduced here: – Recursive Enumeration Algorithm (REA) – YEN’s Algorithm 3

Recursive Enumeration Algorithm (REA) (1) Define a digraph G=, where V is the node set and E is the edge set. Define N(t) as the neighbor nodes set of node v. Define π k (v) is the k th shortest path from s to v. It is easy to find the shortest path from node s to v and other node, and denote them as π 1 (u), u ∈ V V={1,2, 3, 4, 5} E={12, 14, 13, 25, 24, 34, 45} N(4)={1, 2, 3} (5 is not 4’s neighbor)

Recursive Enumeration Algorithm (REA) (2) NextPath(v, k) 1.If k=2, then initialize a set of candidates to the next shortest path from s to v by setting C[v] ←{π 1 (u)  v: u ∈ N(v) and π 1 (v)≠π 1 (u)  v} 2.If v=s and k=2, then go to 6 3.Let u and k’ be the node and index, respectively, such that π k- 1 (v)=π k’ (u)  v 4.If π k’+1 (u) has not been computed yet, compute it by calling NextPath(u,k’+1). 5.If π k’+1 (u) exists, then insert π k’+1 (u)  v in C[v] 6.If C[v]≠empty, then select and delete the path with minimum length from C[v] and assign it to π 1 (v), otherwise π k (v) does not exist. 5

YEN’s Algorithm Initial solution tree with the shortest path, i<- 1 and initial a heap, cache the source node. 2.Traverse the tree for nodes has not been cached. If all nodes has been cached, go to step 8. 3.Block the corresponding nodes and edges. 4.Find the shortest path from the point to the destination. If no path can be found, goto step 6. 5.Push the found path into the heap, unblock the corresponding nodes and edges. 6.Cache the node. 7.Goto step 2 8.If the heap is empty, exit. Otherwise, output the shortest path in the heap, add the path into the solution tree, i<-i+1, un-cache the corresponding deviation node. 9.If i=k, exit. Otherwise, goto step 2

A Sample Solution Tree 7

Sample Digraph ,1,2,0 13,1,3,1 14,1,4,3 24,2,4,2 25,2,5,0 34,3,4,0 35,3,5,2 45,4,5,0

Project Schedule (2012) Part I - Generate and output the network graph (20%) (November 12 th ) – We need to have a program which can generate a network graph from a input file. You also need to demonstrate the graph by printing the list of the nodes and edges. Part II - Shortest Path (20%) (November 19 th ) – Implement Dijkstra’s algorithm yourself Part III – K shortest Path (60%) (November 26 th ) – Find the K shortest paths in a network, where K can be any integer greater than 0. If all possible paths are exhausted before K is reached, the program should output “path exhausted” (20%) The path should be output in the order of length (20%) All paths should be loopless (20%) Presentation on December 3 rd 9

Some Hints About How to Read File in Java BufferedReader br = null; FileReader fr = new FileReader(fileName); br = new BufferedReader(fr); System.out.println("Reading from file."); String line = br.readLine(); MyGraph g = new MyGraph(Integer.parseInt(line)); line = br.readLine(); while (line != null) { String[] list = line.split(","); g.addEdge(Integer.parseInt(list[0]), Integer.parseInt(list[1]) - 1, Integer.parseInt(list[2]) - 1, Integer.parseInt(list[3])); line = br.readLine(); } br.close(); 10

Some Hints About How to Implement YEN’s algorithm in Java (1) public LinkedList myKSPImpl(int src, int des, int k) { LinkedList myKSP = new LinkedList (); // myKSP is the list of final solution LinkedList heap = new LinkedList (); // heap is used to store the midway results Path spath = myDijkstraImpl(src,des); myKSP.add(spath); // find the shortest path, and save it in myKSP Tree solTree = subTreeFromPath(spath,0); // initiate the tree structure using the shortest path int iCount = 1; 11

Some Hints About How to Implement YEN’s algorithm in Java (2) while (iCount < k) { List > l = solTree.toList(); for (Node node : l) {// go through the solution tree if(node.data==des) continue; if (!node.isCached) { // if the node in the tree hasn't been checked, // block its parent, grandparent, grand-grandparent and so on. // Also block the links between itself with its children. // find the shortest path from the node to the destination // under the blocking condition Path temp = myDijkstraImpl(node.data, des); if (temp != null) { // if can find a path, then reconstruct the path from the source to // the destination as well as the cost. Node parent = node.parent; Node child = node; 12

Some Hints About How to Implement YEN’s algorithm in Java (3) while (parent != null) { temp.path.addFirst(parent.data); temp.cost += findEdge(parent.data,child.data).cost; child = parent; parent = parent.parent; } heap.add(temp); // put the path into the heap node.isCached = true; // note the node has been checked } // undo all the blockings undoKSPreparation(node); }} int min = INF; Path mPath = null; // find the minimum cost of the paths in the heap 13

for (Path myPath : heap) { if(myPath.cost<min) { min = myPath.cost; mPath = myPath;}} // if the heap is not empty, then put the minimum path in myKSP if(min<INF){ myKSP.add(mPath); heap.remove(mPath); addPath2Tree(mPath, solTree); iCount++;} // otherwise all the paths have been found, return else break; } return myKSP; 14