edmonds karp algorithm
play

Edmonds Karp Algorithm Dr. Mattox Beckman University of Illinois at - PowerPoint PPT Presentation

Introduction Edmonds Karp Algorithm Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science Introduction Objectives Your Objectives: Implement the Edmonds Karp algorithm for Network Flow Introduction


  1. Introduction Edmonds Karp Algorithm Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science

  2. Introduction Objectives Your Objectives: ◮ Implement the Edmonds Karp algorithm for Network Flow

  3. Introduction A simple example A 10/0 5/0 5/0 B C 10/0 5/0 D

  4. Introduction A simple example A 10/0 5/0 5/0 B C 5/0 10/0 D

  5. Introduction A simple example A 10/5 5/0 5/0 B C 5/5 10/0 D

  6. Introduction A simple example A 5/0 10/5 5/0 B C 10/0 5/5 D

  7. Introduction A simple example A 10/5 5/5 5/0 B C 10/5 5/5 D

  8. Introduction A simple example A 10/5 5/5 5/0 B C 10/5 5/5 D

  9. Introduction A simple example A 10/10 5/5 5/5 B C 10/10 5/5 D

  10. Introduction A second example A 10/0 5/0 5/0 B C 10/0 5/0 D

  11. Introduction A second example A 5/0 10/0 5/0 B C 10/0 5/0 D

  12. Introduction A second example A 5/5 10/0 5/5 B C 10/0 5/5 D

  13. Introduction A second example A 10/0 5/5 5/5 B C 10/0 5/5 D

  14. Introduction A second example A 10/5 5/5 5/0 B C 10/5 5/5 D

  15. f = minEdge; if (v == s) { res[v][p[v]] += f; res[p[v]][v] -= f; augment(p[v], min(minEdge, res[p[v]][v])); } else if (p[v] != - 1) { return ; Introduction Implementation 0 // Stolen from Competitive Programming 3 1 // global variables 2 int res[MAX_V][MAX_V], mf, f, s, t; 3 vi p; // p stores the BFS spanning tree from s 4 5 // traverse BFS spanning tree from s->t 6 void augment ( int v, int minEdge) { 7 8 9 10 11 12 13 14 } }

  16. augment(t, INF); } if (res[u][v] > 0 && dist[v] == INF) if (f == 0) break ; // we cannot send any more flow for ( int v = 0; v < MAX_V; v ++ ) f = 0; mf += f; int u = q.front(); q.pop(); while ( ! q.empty()) { p.assign(MAX_V, - 1); Introduction Implementation, 2 0 mf = 0; 1 while (1) { // O(VE^2) (actually O(V^3 E) Edmonds Karp’s algorithm 2 3 vi dist (MAX_V, INF); dist[s] = 0; queue <int> q; q.push(s); 4 5 6 7 if (u == t) break ; // stop when we reach sink t 8 9 10 dist[v] = dist[u] + 1, q.push(v), p[v] = u; 11 12 13 14 }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend