Presentation is loading. Please wait.

Presentation is loading. Please wait.

© J. Christopher Beck 20081 Lecture 5: Graph Theory and Longest Paths.

Similar presentations


Presentation on theme: "© J. Christopher Beck 20081 Lecture 5: Graph Theory and Longest Paths."— Presentation transcript:

1 © J. Christopher Beck 20081 Lecture 5: Graph Theory and Longest Paths

2 © J. Christopher Beck 2008 2 Outline What is Graph Theory? Graph Theory Basics Finding the Longest Path Why? (modeling) How

3 © J. Christopher Beck 2008 3 Readings Gibbons, Algorithmic Graph Theory, Cambridge University Press, 1985 Sedgewick, Algorithms in C++, 3 rd Edition, 2002 Wikipedia (“Graph Theory”), accessed August 12, 2008

4 © J. Christopher Beck 2008 4 The Bridges of Konigsberg Can you walk a route that crosses each bridge exactly once? Euler, 1736 Islands Bridges

5 © J. Christopher Beck 2008 5 The Bridges of Konigsberg Node or vertex Edge or arc

6 © J. Christopher Beck 2008 6 The Bridges of Konigsberg So, now the problem is: can you traverse every edge exactly once? Any ideas?

7 © J. Christopher Beck 2008 7 Graph Theory Nodes and edges form a graph, G(V,E), with V being the set of nodes, E being the set of edges Edges may be directed or un-directed Edges may have a weight Just a number associated with each edge

8 © J. Christopher Beck 2008 8 Graph Theory Graph theory is the secret to the universe A tremendous number of problems can be modeled and solved using graph theory OR, epidemiology, geometry, IT (the web is a graph), social networks, biological pathways, chemical reactions, …

9 © J. Christopher Beck 2008 9 CPM Can we pose this as a graph theory problem? Why would we want to?

10 © J. Christopher Beck 2008 10 CPM Model Job  Node Precedence  Directed Edge Processing time  Edge Weight (This is the job-on-arc format: P p. 52)

11 © J. Christopher Beck 2008 11 Our Small Example 1 2 3 64 5 1 2 3 64 5 2 3 3 4 What are we missing?

12 © J. Christopher Beck 2008 12 Dummy Nodes 1 2 3 64 5 0 0 0 0 1 264 5 2 3 3 4 7 1 2 1 Two dummy nodes (0 and n+1) 3

13 © J. Christopher Beck 2008 13 Makespan? 0 0 0 0 1 264 5 2 3 3 4 7 1 2 1 3 How do we find the makespan? Critical Path?

14 © J. Christopher Beck 2008 14 Initialize Nodes & Queue class Node { public int label; public int numPredecessors; public int head; }; // initialize Nodes.label and numPredecessors // from input data. head = 0 Node node0 = initial dummy node Node nodeLast = final dummy node queue.push(node0);

15 © J. Christopher Beck 2008 15 Process Each Node while(!queue.empty()) { Node n = queue.pop(); for each e = out-going edge of n Node next = e.getOtherNode(n); if (n.head + e.weight > next.head) next.head = n.head + e.weight; --next.numPredecessors; if (next.numPredecessors == 0) queue.push(next); } After executing this, where is the makespan?

16 © J. Christopher Beck 2008 16 Critical Path How would you modify this algorithm to also allow you to find a critical path?

17 © J. Christopher Beck 2008 17 Add a Field class Node { public int label; public int numPredecessors; public int head; public Node criticalPredecessor; };

18 © J. Christopher Beck 2008 18 Add a Line while(!queue.empty()) { Node n = queue.pop(); for each e = out-going edge of n Node next = e.getOtherNode(n); if (n.head + e.weight > next.head) next.head = n.head + e.weight; next.criticalPredecessor = n; --next.numPredecessors; if (next.numPredecessors == 0) queue.push(next); } Then follow the criticalPredecessor links from nodeLast back to node0. Does this form of algorithm (i.e., use of criticalPredecessor) remind you of anything?

19 © J. Christopher Beck 2008 19 Example 4.2.3 Jobs1234567891011121314 pjpj 569127 106 97875 Model and solve using a graph

20 © J. Christopher Beck 2008 20 The Bridges of Konigsberg So, now the problem is: can you traverse every edge exactly once? Any ideas? Hint: The degree of a node is the number of its edges. Think about the degrees of the nodes in any path.


Download ppt "© J. Christopher Beck 20081 Lecture 5: Graph Theory and Longest Paths."

Similar presentations


Ads by Google