Download
ece 643 design and analysis of computer networks k shortest paths n.
Skip this Video
Loading SlideShow in 5 Seconds..
ECE 643- Design and Analysis of Computer Networks K Shortest Paths PowerPoint Presentation
Download Presentation
ECE 643- Design and Analysis of Computer Networks K Shortest Paths

ECE 643- Design and Analysis of Computer Networks K Shortest Paths

97 Vues Download Presentation
Télécharger la présentation

ECE 643- Design and Analysis of Computer Networks K Shortest Paths

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. ECE 643- Design and Analysis of Computer NetworksK Shortest Paths Dept. of Electrical and Computer Eng. George Mason UniversityFairfax, 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.

  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

  4. Recursive Enumeration Algorithm (REA) (1) • Define a digraph G=<V, E>, 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 kth 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. 2 0 0 2 1 4 3 0 5 1 2 0 3 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) • 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} • If v=s and k=2, then go to 6 • Let u and k’ be the node and index, respectively, such that πk-1(v)=πk’(u)v • If πk’+1(u) has not been computed yet, compute it by calling NextPath(u,k’+1). • If πk’+1(u) exists, then insert πk’+1(u)v in C[v] • 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.

  6. YEN’s Algorithm Initial solution tree with the shortest path, i<-1 and initial a heap, cache the source node. Traverse the tree for nodes has not been cached. If all nodes has been cached, go to step 8. Block the corresponding nodes and edges. Find the shortest path from the point to the destination. If no path can be found, goto step 6. Push the found path into the heap, unblock the corresponding nodes and edges. Cache the node. Gotostep 2 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. If i=k, exit. Otherwise, goto step 2 2 0 0 2 1 4 3 0 5 1 2 0 3

  7. A Sample Solution Tree

  8. Sample Digraph 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 2 0 0 2 1 4 3 0 5 1 2 0 3

  9. Project Schedule (2012) • Part I - Generate and output the network graph (20%) (November 12th) • 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 19th) • Implement Dijkstra’s algorithm yourself • Part III – K shortest Path (60%) (November 26th) • 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 3rd

  10. Some Hints About How to Read File in Java BufferedReaderbr = null; FileReaderfr = new FileReader(fileName); br= new BufferedReader(fr); System.out.println("Reading from file."); String line = br.readLine(); MyGraphg = 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();

  11. Some Hints About How to Implement YEN’s algorithm in Java (1) public LinkedList<Path> myKSPImpl(intsrc, int des, int k) { LinkedList<Path> myKSP = new LinkedList<Path>(); // myKSP is the list of final solution LinkedList<Path> heap = new LinkedList<Path>(); // 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<Integer> solTree = subTreeFromPath(spath,0); // initiate the tree structure using the shortest path intiCount = 1;

  12. Some Hints About How to Implement YEN’s algorithm in Java (2) while (iCount < k) { List<Node<Integer>> l = solTree.toList(); for (Node<Integer> 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<Integer> parent = node.parent; Node<Integer> child = node;

  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; PathmPath = null; // find the minimum cost of the paths in the heap

  14. for (PathmyPath : heap) { if(myPath.cost<min) { min = myPath.cost; mPath= myPath;}} // if the heapis 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;