Network Optimization Topological Ordering Preliminary to Topological Sorting

  • Slides: 20
Download presentation
Network Optimization Topological Ordering

Network Optimization Topological Ordering

Preliminary to Topological Sorting LEMMA. If each node has at least one arc going

Preliminary to Topological Sorting LEMMA. If each node has at least one arc going out, then the first inadmissible arc of a depth first search determines a directed cycle. 1 4 6 3 7 COROLLARY 1. If G has no directed cycle, then there is a node in G with no arcs going. And there is at least one node in G with no arcs coming in. COROLLARY 2. If G has no directed cycle, then one can relabel the nodes so that for each arc (i, j), i < j. 2

Initialization Determine the indegree di of each node i. 5 LIST = {i :

Initialization Determine the indegree di of each node i. 5 LIST = {i : di = 0} 7 Node Indegree 6 1 2 8 3 4 1 2 3 4 5 6 7 8 2 2 3 2 1 1 0 2 3 7 LIST

Initialization “Next” will be the label of nodes in the topological order. 5 7

Initialization “Next” will be the label of nodes in the topological order. 5 7 6 1 2 8 3 4 1 next Node Indegree 1 2 3 4 5 6 7 8 2 2 3 2 1 1 0 2 4 7 LIST

Select a node from LIST Select Node 7. Order(7) : = 1 Delete node

Select a node from LIST Select Node 7. Order(7) : = 1 Delete node 7. 5 77 6 1 2 8 3 4 1 0 1 next Node Indegree 1 2 3 4 5 6 7 8 2 2 3 2 1 1 0 2 5 7 LIST

Updates update “next” update indegrees 5 update LIST 77 6 1 2 8 3

Updates update “next” update indegrees 5 update LIST 77 6 1 2 8 3 4 1 0 1 2 next Node Indegree 1 2 3 4 5 6 8 2 2 3 1 2 1 0 1 2 6 7 5 LIST

Select node 5 Select Node 5. Order(5) : = 2 Delete node 5. 2

Select node 5 Select Node 5. Order(5) : = 2 Delete node 5. 2 77 5 6 1 2 8 3 4 1 0 1 2 next Node Indegree 1 2 3 4 5 6 8 2 2 3 1 2 0 1 2 7 7 5 LIST

Updates update “next” update indegrees 2 update LIST 77 5 6 1 2 8

Updates update “next” update indegrees 2 update LIST 77 5 6 1 2 8 3 4 1 0 1 2 3 next Node Indegree 1 2 3 4 6 8 2 2 1 3 0 1 2 1 0 2 8 4 7 5 6 LIST

Select Node 6 (or 4) Select Node 6. Order(6) : = 3 Delete node

Select Node 6 (or 4) Select Node 6. Order(6) : = 3 Delete node 6. 2 77 5 3 6 1 2 8 3 4 1 0 1 2 3 next Node Indegree 1 2 3 4 6 8 2 2 1 3 0 1 2 0 2 9 4 7 5 6 LIST

Updates update “next” update indegrees 2 update LIST 77 5 3 6 1 2

Updates update “next” update indegrees 2 update LIST 77 5 3 6 1 2 8 3 4 1 0 1 2 3 4 next Node Indegree 1 2 3 4 8 2 1 0 3 0 1 2 2 10 4 7 5 2 LIST

Select Node 2 (or 4) Select Node 2. 3 6 Order(2) : = 4

Select Node 2 (or 4) Select Node 2. 3 6 Order(2) : = 4 Delete node 2. 2 77 5 1 2 4 8 3 4 1 0 1 2 3 4 next Node Indegree 1 2 3 4 8 2 1 0 3 0 1 2 2 11 4 7 5 6 2 LIST

Updates update “next” update indegrees 3 6 2 update LIST 77 5 1 2

Updates update “next” update indegrees 3 6 2 update LIST 77 5 1 2 4 8 3 4 1 0 1 2 3 4 5 next Node Indegree 1 3 4 8 2 1 0 3 0 1 2 2 12 4 7 5 61 LIST

Select node 4 (or 1) Select Node 4. 3 6 Order(4) : = 5

Select node 4 (or 1) Select Node 4. 3 6 Order(4) : = 5 Delete node 4. 2 77 5 1 2 4 8 3 4 1 5 0 1 2 3 4 5 next Node Indegree 1 3 4 8 2 1 0 3 0 2 13 4 7 5 61 LIST

Updates update “next” update indegrees 3 6 2 update LIST 77 1 5 1

Updates update “next” update indegrees 3 6 2 update LIST 77 1 5 1 2 4 8 3 4 5 0 1 2 3 4 5 6 next Node Indegree 1 3 8 2 1 0 3 2 2 1 14 5 7 61 LIST

Select Node 1. 3 6 Order(1) : = 6 Delete node 1. 2 77

Select Node 1. 3 6 Order(1) : = 6 Delete node 1. 2 77 1 5 6 1 2 4 8 3 4 5 0 1 2 3 4 5 6 next Node Indegree 1 3 8 0 3 2 2 1 15 5 7 61 LIST

Updates update “next” update indegrees 3 6 2 update LIST 77 1 5 6

Updates update “next” update indegrees 3 6 2 update LIST 77 1 5 6 1 2 4 8 3 4 5 0 1 2 3 4 5 6 7 next Node Indegree 3 8 3 2 1 0 16 5 7 8 LIST

Select Node 8. 3 6 Order(8) : = 7 Delete node 8. 2 77

Select Node 8. 3 6 Order(8) : = 7 Delete node 8. 2 77 1 5 6 1 7 8 2 4 3 4 5 0 1 2 3 4 5 6 7 next Node Indegree 3 8 3 2 1 0 17 5 7 8 LIST

Updates update “next” update indegrees 3 6 2 update LIST 77 1 5 6

Updates update “next” update indegrees 3 6 2 update LIST 77 1 5 6 1 7 8 2 4 3 4 5 0 1 2 3 4 5 6 7 8 next Node Indegree 3 3 2 1 0 5 7 3 18 LIST

Select node 3 Select Node 3. 3 6 Order(3) : = 8 Delete node

Select node 3 Select Node 3. 3 6 Order(3) : = 8 Delete node 3. 2 77 1 5 6 1 7 8 2 4 8 3 4 5 0 1 2 3 4 5 6 7 8 next Node Indegree 3 0 List is empty. The algorithm terminates with a topological order of the nodes 19 5 7 3 LIST

MITOpen. Course. Ware http: //ocw. mit. edu 15. 082 J / 6. 855 J

MITOpen. Course. Ware http: //ocw. mit. edu 15. 082 J / 6. 855 J / ESD. 78 J Network Optimization Fall 2010 For information about citing these materials or our Terms of Use, visit: http: //ocw. mit. edu/terms.