Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "ECE 643- Design and Analysis of Computer Networks K Shortest Paths Dept. of Electrical and Computer Eng. George Mason University Fairfax, VA 22030-4444,"— Presentation transcript:

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

2 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

3 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

4 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. 4 1 1 4 4 5 5 3 3 2 2 00 30 12 2 0 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)

5 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

6 YEN’s Algorithm 6 1 1 4 4 5 5 3 3 2 2 00 30 12 2 0 1.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

7 A Sample Solution Tree 7

8 Sample Digraph 8 1 1 4 4 5 5 3 3 2 2 00 30 12 2 0 5 12,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

9 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

10 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

11 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

12 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

13 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

14 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


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

Similar presentations


Ads by Google