SlideShare a Scribd company logo
Algorithm Design and Complexity

                         Course 12
Overview
   Flow Networks
   Positive Flow and Net Flow
   Flow Properties
   Maximum Flow
   Minimum Cut
   Ford-Fulkerson Method
   Edmonds-Karp Algorithm
   Sample Applications
Flow Networks
   Graphs that model materials that are transported
    through conduits
   Each edge represents a conduit: it has a capacity
    that is an upper bound for the flow rate
   Some vertices may produce materials: sources
   Other vertices may consume materials: sinks
Flow Networks (2)
   The simplest version of flow networks:
       Think of edges as pipes of different sizes (capacities)
       The flow is the effective quantity of liquid that is transported
        through the pipes

   Flow Networks are also called transportation networks
   But you can transport a lot of things beside liquids, like
    commodities, information, electricity, traffic

   There are some interesting and difficult problems for flow
    networks:
       Maximum flow problem
       Maximum flow with minimum cost problem
       Circulation problem
       Multi-commodity problem
Flow Networks (3)
   G(V, E) – directed graph
   The capacity function c: E → R+
   c(u, v) = the capacity of the edge (u, v)
    (u,v)  E  c(u,v) = 0

   Assume we have a single source vertex: s
   Assume we have a single sink vertex: t
   Assume we have a path s .. v .. t  vV
Positive Flow
   We can define a function called positive flow
       p: V x V  R+

   Properties of positive flow:
   Capacity constraint:
         u, vV: p(u, v) <= c(u, v)
   Flow conservation:
         uV  {s, t}: flow_in(u) = flow_out(u)
         uV  {s, t}: vV(p(v, u)) = vV(p(u, v))
Positive Flow – Example
   Notation on each edge: positive flow/capacity
   Note that the two properties are respected
       The flow is always lower than the capacity of each edge
       The flow is conserved in each vertex
       The source produces flow
       The sink consumes flow
Cancellation for Positive Flow
   Note that in the previous example we have:
       1 unit of flow from x  z
       2 units of flow from z  x
   We can cancel 1 unit of flow in both directions
       0 units of flow from x  z
       1 unit of flow from z  x
       Flow conservation is still respected (we cancel the same
        amount of flow in each direction)
       Capacity constraint is still respected (the flow is decreased)
   In both cases, the “net flow” is 1 from z  x

   Without loss of generality, we may always define a
    positive flow in a flow network such that for each (u, v),
    u,vV, we have positive flow either from u  v or from v
     u, but not in both directions!
Net Flow
   We can define a function called net flow
       f: V x V  R

   Properties of net flow:
   Capacity constraint:
         u, vV: f(u, v) <= c(u, v)
   Flow conservation:
         uV  {s, t}: total_net_flow_in(u) = 0
         uV  {s, t}: vV(f(u, v)) = 0
   Skew symmetry:
         u, vV: f(u, v) = - f(v, u)
Net Flow (2)
   Conservation of net flow can be rewritten:

vV (f(u, v)) = 0

As f(u, v) might be either positive or negative
 uV  {s, t}: vV and f(u,v)<0(f(u, v)) + vV and f(u,v)>0 (f(u, v))
  =0
 uV  {s, t}: vV and f(v,u)>0(f(v, u)) = vV and f(u,v)>0 (f(u, v))
  “total positive flow entering u” = “total positive flow
  leaving u”
  “flow in” = “flow out”
Net Flow – Example
   Only positive flow is illustrated in graphical
    representations
   Nevertheless, this does not mean that the (negative)
    net flow does not exist in the other direction
Positive Flow and Net Flow
   Differences

   Net flow satisfies skew symmetry

   p(u, v) >= 0, while
                      f(u, v) >= 0 or f(u, v) <= 0
Positive Flow and Net Flow (2)
   Equivalence
   We can define net flow using only positive flow and vice-
    versa

   f(u, v) = p(u, v) – p(v, u)  u, vV
   Need to show that using this definition, the net flow still
    satisfies the three properties: capacity constraint,
    conservation and skew symmetry

   p(u, v) = f(u, v)   if f(u, v) > 0
   p(u, v) = 0         otherwise
   Need to show that this definition satisfies the two
    properties of positive flow: capacity constraint and
    conservation
Positive Flow and Net Flow (3)
   f(u, v) = p(u, v) – p(v, u)  u, vV
   Capacity constraint:
    p(u, v) <= c(u, v) and p(v, u) >= 0
    => f(u, v) = p(u, v) – p(v, u) <= p(u, v) <= c(u, v)
   Flow conservation:
    vV (f(u, v)) = vV (p(u, v) – p(v, u)) = vV (p(u, v)) – vV
    (p(v, u)) = (from positive flow conservation) = 0
   Skew symmetry:
    f(u, v) = p(u, v) – p(v, u) = –(p(v, u) – p(u, v)) = –f(v,u)

    Similar for the transformation from f(u, v)  p(u, v). Prove
    them at home!
Value of the Flow
   From now on, we shall only use net flow

   Value of the flow = |f| = vV (f(s, v)) = vV (f(v, t))
       In the example below: |f| = 3
Cancellation of (Net) Flow
   Let’s say that f(u, v) = 5 and c(u, v) = 8
       We can “ship” at most 3 units of flow from u  v
       => f(u, v) = 8 = c(u, v)
       But we can also “ship” up to 5 units of flow back from v 
        u
       => f(u, v) = 3 if we cancel 2 units of flow!
       Called flow cancellation
   If (v, u) E => f(v, u) <= c(v, u) = 0
       We are not allowed to have a positive flow from v  u
       But we are allowed to have negative flow!
       This negative flow is equal in absolute value with the
        positive value from u  v
Cancellation of (Net) Flow (2)
   Due to cancellation, a flow only gives us this so-
    called “net” effect. We cannot reconstruct actual
    “shipments” of products from a net flow.
   A flow f(u, v) = 5 and f(v, u) = -5 can mean either:

    5 units u  v     6 units u  v       8 units u  v
    0 units v  u     1 units v  u       3 units v  u
Flow Operations
   Extend the definition of the flow to sets of vertices
   X,Y  V
   f(X,Y) = ΣxXΣyY f(x,y) = total flow between X and Y

   Possible operations:
       XV f(X,X) = 0;
       X,YV f(X,Y) = -f(Y,X);
       X,Y,ZV si Y⊆X
           f(X Y, Z) = f(X,Z) - f(Y,Z);
           f(Z, X Y) = f(Z,X) - f(Z,Y);
       X,Y,ZV si XY=
           f(X Y, Z) = f(X,Z) + f(Y,Z);
           f(Z, X Y) = f(Z,X) + f(Z,Y)
       |f| = f(s,V) = f(V,t)
Examples (1)

                           X             1/2
                                    a               b
                     1/8                                  2/2

                               4/4            3/3
                 s                                            t

                                                        3/9   Y
                                c                   d
                                        3/5


                       f(X,Y) = ΣxXΣyY f(x,y)


f(X,X) = f(s,a) + f(a,s) + f(s,b) + f(b,s) + f(a,b) + f(b,a) = 0
f(X,Y) = f(b,c) + f(b,t) = -f(c,b) - f(t,b) = -f(Y,X)
                                        Proiectarea Algoritmilor 2010
Examples (2)

                           X              1/2
                                     a             b
                     1/8                                        2/2
                                                 Y
                 s             4/4           3/3                               t

                                c                                        3/9       Z
                                                 3/5           d


 X, Y, Z  V si Y ⊆ X
            f(X Y, Z) = f(X, Z) - f(Y, Z)
            f(Z, X Y) = f(Z, X) - f(Z, Y)

     f(X Y, Z) = 0 = f(b,t) + f(c,d) - f(b,t) - f(c,d) = f(X,Z) - f(Y,Z)
     f(Z, X Y) = 0 = f(t,b) + f(d,c) - f(t,b) - f(d,c) = f(Z,X) - f(Z,Y)

                                         Proiectarea Algoritmilor 2010
Examples (3)
                                                      Z
                         X             1/2
                                  a               b
                   1/8                                    2/2

               s             4/4            3/3              t

                                                       3/9   Y
                              c                   d
                                      3/5

 X, Y, Z  V si X  Y = 
            f(XY, Z) = f(X,Z) + f(Y,Z)
            f(Z, XY) = f(Z,X) + f(Z,Y)

    f(X Y, Z) = f(s,b) + f(a,b) + f(t,b) + f(d,c) = f(X,Z) + f(Y,Z)
    f(Z, X Y) = f(b,a) + f(b,s) + f(b,t) + f(c,d) = f(Z,X) + f(Z,Y)

                                      Proiectarea Algoritmilor 2010
Examples (4)

                                1/2
                            a               b
                 1/8                                2/2
                       4/4            3/3
             s                                            t

                                                  3/9
                        c                   d
                                3/5



  f(s, V) = f(V, t)

  f(s, V) = f(s,a) + f(s,b) = 5 = f(d,t) + f(b,t) = f(V, t)


                                 Proiectarea Algoritmilor 2010
Maximum Flow Problem
   Given G(V, E), c: E  R+, sV and tV
   Find the maximum flow that can be “transported” from s
    to t

   We start with an initial void flow on all edges
   We want to compute the net flow between each pair of
    vertices that determines a maximum flow!

   Various methods are used
   Only look at one of the simplest:
       Ford-Fulkerson and Edmonds-Karp
       Uses the notion of residual network
Residual Network
   Given G(V, E), c: E  R+, sV and tV
   Knowing a given flow in the graph, f: E  R

   We can compute the residual capacity for any pair of
    vertices:
       cf(u, v) = c(u, v) – f(u, v) >= 0 (due to capacity constraint)
       Residual means: how much flow we can still transport from u 
        v
   We can compute the residual network of the graph:
       It is a graph Gf = (V, Ef)
       Ef = {(u, v)  V x V | cf(u, v) > 0}
       It is a graph that contains edges that have residual capacity
        (that can still transport flow!)
       How many edges does Gf have? Find the minimum and the
        maximum value!
Residual Network – Example
Augmenting Path
   Any path from the residual graph admits more flow
    from the start vertex to the end vertex
   Therefore, we want to find a path from the source s
    to the sink t in the residual graph: augmenting path

   Look for p = s..t in Gf
   If we can find this augmenting path, compute how
    much flow we can send along it!
       We are constrained by the minimum residual capacity of
        any edge along the augmenting path
       cf(p) = min(cf(u, v) | (u, v) is on p)
Augmenting Path – Example
   p = <(s, w), (w, y), (y, z), (z, t)>
   Is it unique? Can you find another?
Summing Flows
   If the graph G has a flow f
   And we can find another flow f’
   We can sum up the two flows to find the new flow:
          f(u,v) + f’(u,v)
   The value of the new flow is |f| + |f’|

   Therefore, if we can find an augmenting path, p, in the residual
    network of a graph, we can also find another flow, fp: V x V 
    R
   fp(u,v) = cf(p) if (u,v) is on p
   fp(u,v) = -cf(p) if (v,u) is on p
   fp(u,v) = 0

   We can thus define a new flow in G: |f’| = |f| + |fp| > |f|
       Thus, we can improve the existing flow!
Graph Cuts
   A cut (S, T) of a flow network G(V, E) is a partitionof
    the vertices into two sets S (sS) and T = V  S (t
    T)
       Already know cuts for minimum spanning trees
   The flow across the cut is f(S, T)
   The capacity of the cut is c(S, T) = summing up the
    capacities of all the edges starting from a vertex in S
    and ending in a vertex in T
   A minimum cut in G is a cut whose capacity is
    minimum over all the possible cuts in G
Graph Cuts – Example
   S = {s, w, y}, T = {x, z, t}
   f(S, T) = f(w, x) + f (y, x) + f(y, z) = 2 + (-1) + 2 = 3
       Includes positive flow that goes either direction across the
        cut
       But only takes into account net flow that goes from any
        vertex in S to any vertex in T
   c(S, T) = c(w, x) + c(y, z) = 2 + 3 = 5
Max-Flow Min-Cut Theorem
   The following statements are equivalent:
       f is a maximum flow in G
       There is no augmenting path in Gf
       |f| = c(S, T) for all minimum cuts (S, T)

   This theorem gives us a method to compute the
    maximum flow: push flow along augmenting paths
    until you cannot find any
   This theorem also tells us how to compute a
    minimum cut once the maximum flow is known
       When f is a maximum flow, all the vertices reachable from
        s in Gf are in S, the others are in T => (S, T) is a minimum
        cut
Ford-Fulkerson Method
1.        Start with a void flow
2.        Compute the residual graph for the given flow
3.        If there is an augmenting path in this residual graph
     a)     Increase the flow along it
     b)     Go to step 2
4.        The maximum flow has been reached!

         The disadvantage of this method is that it does not
          specify how to look for the augmenting path in step 3
           Any method can be used
           Pick a random augmenting path
           Use any search algorithms to compute the path: DFS, BFS
           Be greedy: look for the fattest pipe each time! How?
Ford-Fulkerson Method (2)
   If the augmenting path is not picked smartly, then the
    worst case running time for the algorithm is O(E*|fmax|)
   Why?
   Each augmenting path has at most O(E) edges that will
    cause a change in the value of the flow along them at
    each step!
   Maximum number of steps is fmax if a each step cf(p)=1
   See the example on the next slides!
   It is not good that the running time depends on fmax
       What happens if the capacities of the edges are irrational
        number? => so is fmax
Exemplu Ford – Fulkerson (1)
                                                   1000         B   1000
    0/1000    B         0/1000
                                                                1
                                                                                   G
              0/1                      Gf      A                               D
A                                 D
                                                   1000         C   1000
    0/1000    C         0/1000
                                              Residual Path: A-B-C-D; Cf = 1
                                                   1
     1/1000   B         0/1000                              B     1000
                                                          999                      G
                  1/1                  Gf      A                1              D
A                                 D                                 999

    0/1000    C          1/1000                    1000         C          1

                                              Residual Path : A-B-C-D; Cf = 1
    1/1000    B         1/1000                  1          B      999 1
                                       Gf                 999                      G
A             0/1                 D            A                1          D
                                                                    999
    1/1000    C         1/1000                         999 C          1
                                                   1
              Proiectarea Algoritmilor 2010
                                               Residual Path : A-B-C-D; Cf = 1
Exemplu Ford – Fulkerson (2)

                                                    2
    2/1000      B      1/1000                                  B         999        1
                                                        998                                 G
                 1/1                Gf                         1
A                               D           A                                       D
                                                                       998
                                                    999        C
    1/1000      C      2/1000                   1                               2



                           …                Residual Path: A-C-B-D; Cf = 1


1000/1000       B      1000/1000                               B
                                                        1000                 1000
                 0/1
                                    Gf
A                               D             A                    1                    D
 1000/1000      C      1000/1000                        1000   C             1000

                                                        Residual Path: Ø
             How many steps are needed to reach the maximum flow?

                                    Proiectarea Algoritmilor 2010
Edmonds-Karp Algorithm
   Is a variant of the Ford-Fulkerson algorithm that
    guarantees to have a running time that is
    independent of fmax
   Always picks the augmenting path using BFS on Gf
       Source vertex for BFS is s
       You may stop when t is reached
   This way, the length of the augmenting paths is
    increasing when running the algorithm
       We always pick an augmenting path with an equal or
        greater length than the previous one
Edmonds-Karp Algorithm (2)
Edmonds–Karp(G, s, t)
   FOREACH (u,v) in E
      f(u,v) = f(v,u) = 0          // O(E)
   WHILE (1)                       // O(E*V)
           p = find-augmenting-path-using-bfs(G, f, s, t) // O(E)
           IF (p == null)
              BREAK
           cf(p) = min{cf(u,v) | (u,v) in p}  // O(E)
           FOREACH (u,v) in p                 // O(E)
                f(u,v) = f(u,v) + cf(p)
                f(v,u) = -f(u,v)
   RETURN f

    Complexity: O(V*E2)
Edmonds-Karp – Example
                                                            1000           B   1000
    0/1000      B         0/1000
                                                                           1
                                                                                                     G
                0/1                            Gf       A                                   D
A                                   D
                                                            1000           C       1000
    0/1000      C         0/1000
                                                      Residual Path: A-B-D; Cf = 1000
    1000/1000   B         1000/1000                             1000       B
                                                                                    1000
                    0/1                        Gf                          1
                                                                                                     G
A                                    D                  A                                   D
    0/1000      C          1/1000                            1000          C        1000

                                                       Residual Path: A-C-D; Cf = 1000
1000/1000       B          1000/1000
                                                              1000     B
                                                                                          1000
                    0/1                         Gf
A                                    D                                         1
                                                            A                                    D
    1000/1000   C          1000/1000                                1000           1000
                                                                             C
                                    Proiectarea Algoritmilor 2010
                                                                       Residual Path: Ø
Application: Maximum Bipartite Matching
   Bipartite graph: we can partition the graph into two sets
    of vertices L, R such as L U R = V and for all (u, v)E,
    uL, vR
   Matching: a subset of edges, M, such that for all vV at
    most an edge in M is incident in v
   Need to transform this problem into a maximum flow
Application: The Escape Problem
   http://webcourse.cs.technion.ac.il/234247/Spring2006/ho/
    WCFiles/The%20Escape%20Problem.pdf
Conclusions
   Flow networks are met very often in real life
   A lot of applications and interesting problems to be solved:
    maximum flow is only one of them

   It is important to know the main concepts of flow networks:
    positive flow, net flow, cuts, augmenting networks, etc.

   Ford-Fulkerson gives us a generic method to compute the
    maximum flow in a graph
       Edmonds-Karp is a variant of FF that runs in O(V*E2)
   There are other algorithms that work better

   A lot of problems can be solved using maximum flow, but you
    need to be able to “transform” them into a flow problem!
References
   CLRS – Chapter 26

   http://www.cs.princeton.edu/courses/archive/fall04/cos22
    6/lectures/maxflow.4up.pdf

   www.brics.dk/~sskyum/dSoegOpt/public_html/ek.pdf

More Related Content

What's hot (20)

PPT
Graph
Shakil Ahmed
 
PDF
Minimum spanning tree
Amit Kumar Rathi
 
PPT
Algorithm Design and Complexity - Course 10
Traian Rebedea
 
PPTX
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala
 
PDF
Bfs dfs
Amit Kumar Rathi
 
PDF
Bellman ford
Kiran K
 
PDF
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
Kiran K
 
PPTX
Minimum spanning Tree
Narendra Singh Patel
 
PDF
Derivatives Lesson Oct 14
ingroy
 
PDF
Dokumen.tips mathematics ii-institute-of-aeronautical-engineering-pptpdfadvan...
Mahmood Adel
 
PPTX
vcla
Kunj Patel
 
PPT
minimum spanning trees Algorithm
sachin varun
 
PDF
My presentation all shortestpath
Carlostheran
 
PDF
A Generalization of QN-Maps
IOSR Journals
 
PPTX
Minimum spanning tree algorithms by ibrahim_alfayoumi
Ibrahim Alfayoumi
 
PDF
Pdfcode
SokhnaRokhayaDIOP
 
PPT
Linear transformation.ppt
Raj Parekh
 
PPTX
Divergence,curl,gradient
Kunj Patel
 
PPT
B.tech admission in india
Edhole.com
 
PPTX
Linear transformations-thestuffpoint.com
Abu Bakar Soomro
 
Minimum spanning tree
Amit Kumar Rathi
 
Algorithm Design and Complexity - Course 10
Traian Rebedea
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala
 
Bellman ford
Kiran K
 
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
Kiran K
 
Minimum spanning Tree
Narendra Singh Patel
 
Derivatives Lesson Oct 14
ingroy
 
Dokumen.tips mathematics ii-institute-of-aeronautical-engineering-pptpdfadvan...
Mahmood Adel
 
minimum spanning trees Algorithm
sachin varun
 
My presentation all shortestpath
Carlostheran
 
A Generalization of QN-Maps
IOSR Journals
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Ibrahim Alfayoumi
 
Linear transformation.ppt
Raj Parekh
 
Divergence,curl,gradient
Kunj Patel
 
B.tech admission in india
Edhole.com
 
Linear transformations-thestuffpoint.com
Abu Bakar Soomro
 

Similar to Algorithm Design and Complexity - Course 12 (20)

PPT
Network Information Processing
Reza Rahimi
 
DOCX
23Network FlowsAuthor Arthur M. Hobbs, Department of .docx
eugeniadean34240
 
PPTX
Graph theory
Tech_MX
 
PPTX
Graph theory 1
Tech_MX
 
PDF
07 - Graphs
Tudor Girba
 
PDF
Orchap10
anilkumar_mca
 
PDF
Network analysis
Hakeem-Ur- Rehman
 
PPT
Flow Network Talk
Imane Haf
 
PPTX
Matrix Representation Of Graph
Abhishek Pachisia
 
PPT
MaximumFlow.ppt
KrishanPalSingh39
 
PDF
Dijkstra
David Wood
 
PDF
Dijkstra's Algorithm
guest862df4e
 
PDF
Dijkstra
David Wood
 
PDF
lecture8-final.pdf ( analysis and design of algorithm)
ZainabShahzad9
 
KEY
Verification with LoLA: 7 Implementation
Universität Rostock
 
PPT
5 spatial filtering p1
Gichelle Amon
 
PDF
Lec01 network flows
Danny Luk
 
DOCX
Alg 2 trig item analysis seton nv sv
gdeangelo
 
PDF
Ford Fulkerson wjgnejgbnhjbdreryjerhsrgjhegeujtgsruyw (1).pdf
NamanBansal94
 
PDF
MATHEON Center Days: Index determination and structural analysis using Algori...
Dagmar Monett
 
Network Information Processing
Reza Rahimi
 
23Network FlowsAuthor Arthur M. Hobbs, Department of .docx
eugeniadean34240
 
Graph theory
Tech_MX
 
Graph theory 1
Tech_MX
 
07 - Graphs
Tudor Girba
 
Orchap10
anilkumar_mca
 
Network analysis
Hakeem-Ur- Rehman
 
Flow Network Talk
Imane Haf
 
Matrix Representation Of Graph
Abhishek Pachisia
 
MaximumFlow.ppt
KrishanPalSingh39
 
Dijkstra
David Wood
 
Dijkstra's Algorithm
guest862df4e
 
Dijkstra
David Wood
 
lecture8-final.pdf ( analysis and design of algorithm)
ZainabShahzad9
 
Verification with LoLA: 7 Implementation
Universität Rostock
 
5 spatial filtering p1
Gichelle Amon
 
Lec01 network flows
Danny Luk
 
Alg 2 trig item analysis seton nv sv
gdeangelo
 
Ford Fulkerson wjgnejgbnhjbdreryjerhsrgjhegeujtgsruyw (1).pdf
NamanBansal94
 
MATHEON Center Days: Index determination and structural analysis using Algori...
Dagmar Monett
 
Ad

More from Traian Rebedea (20)

PPTX
An Evolution of Deep Learning Models for AI2 Reasoning Challenge
Traian Rebedea
 
PDF
AI @ Wholi - Bucharest.AI Meetup #5
Traian Rebedea
 
PDF
Deep neural networks for matching online social networking profiles
Traian Rebedea
 
PDF
Intro to Deep Learning for Question Answering
Traian Rebedea
 
PPTX
What is word2vec?
Traian Rebedea
 
PPT
How useful are semantic links for the detection of implicit references in csc...
Traian Rebedea
 
PPT
A focused crawler for romanian words discovery
Traian Rebedea
 
PPTX
Detecting and Describing Historical Periods in a Large Corpora
Traian Rebedea
 
PDF
Practical machine learning - Part 1
Traian Rebedea
 
PPT
Propunere de dezvoltare a carierei universitare
Traian Rebedea
 
PPT
Automatic plagiarism detection system for specialized corpora
Traian Rebedea
 
PPT
Relevance based ranking of video comments on YouTube
Traian Rebedea
 
PPT
Opinion mining for social media and news items in Romanian
Traian Rebedea
 
PPT
PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...
Traian Rebedea
 
PPT
Importanța algoritmilor pentru problemele de la interviuri
Traian Rebedea
 
PPTX
Web services for supporting the interactions of learners in the social web - ...
Traian Rebedea
 
PPT
Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...
Traian Rebedea
 
PPT
Conclusions and Recommendations of the Romanian ICT RTD Survey
Traian Rebedea
 
PPT
Istoria Web-ului - part 2 - tentativ How to Web 2009
Traian Rebedea
 
PPT
Istoria Web-ului - part 1 (2) - tentativ How to Web 2009
Traian Rebedea
 
An Evolution of Deep Learning Models for AI2 Reasoning Challenge
Traian Rebedea
 
AI @ Wholi - Bucharest.AI Meetup #5
Traian Rebedea
 
Deep neural networks for matching online social networking profiles
Traian Rebedea
 
Intro to Deep Learning for Question Answering
Traian Rebedea
 
What is word2vec?
Traian Rebedea
 
How useful are semantic links for the detection of implicit references in csc...
Traian Rebedea
 
A focused crawler for romanian words discovery
Traian Rebedea
 
Detecting and Describing Historical Periods in a Large Corpora
Traian Rebedea
 
Practical machine learning - Part 1
Traian Rebedea
 
Propunere de dezvoltare a carierei universitare
Traian Rebedea
 
Automatic plagiarism detection system for specialized corpora
Traian Rebedea
 
Relevance based ranking of video comments on YouTube
Traian Rebedea
 
Opinion mining for social media and news items in Romanian
Traian Rebedea
 
PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...
Traian Rebedea
 
Importanța algoritmilor pentru problemele de la interviuri
Traian Rebedea
 
Web services for supporting the interactions of learners in the social web - ...
Traian Rebedea
 
Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...
Traian Rebedea
 
Conclusions and Recommendations of the Romanian ICT RTD Survey
Traian Rebedea
 
Istoria Web-ului - part 2 - tentativ How to Web 2009
Traian Rebedea
 
Istoria Web-ului - part 1 (2) - tentativ How to Web 2009
Traian Rebedea
 
Ad

Recently uploaded (20)

PPTX
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
DOCX
DLL english grade five goof for one week
FlordelynGonzales1
 
PDF
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
PDF
VCE Literature Section A Exam Response Guide
jpinnuck
 
PPTX
How to use _name_search() method in Odoo 18
Celine George
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PPTX
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
PPTX
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
PDF
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
 
PPTX
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PDF
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
PPTX
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
PPTX
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
PDF
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
DOCX
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
DLL english grade five goof for one week
FlordelynGonzales1
 
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
VCE Literature Section A Exam Response Guide
jpinnuck
 
How to use _name_search() method in Odoo 18
Celine George
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 

Algorithm Design and Complexity - Course 12

  • 1. Algorithm Design and Complexity Course 12
  • 2. Overview  Flow Networks  Positive Flow and Net Flow  Flow Properties  Maximum Flow  Minimum Cut  Ford-Fulkerson Method  Edmonds-Karp Algorithm  Sample Applications
  • 3. Flow Networks  Graphs that model materials that are transported through conduits  Each edge represents a conduit: it has a capacity that is an upper bound for the flow rate  Some vertices may produce materials: sources  Other vertices may consume materials: sinks
  • 4. Flow Networks (2)  The simplest version of flow networks:  Think of edges as pipes of different sizes (capacities)  The flow is the effective quantity of liquid that is transported through the pipes  Flow Networks are also called transportation networks  But you can transport a lot of things beside liquids, like commodities, information, electricity, traffic  There are some interesting and difficult problems for flow networks:  Maximum flow problem  Maximum flow with minimum cost problem  Circulation problem  Multi-commodity problem
  • 5. Flow Networks (3)  G(V, E) – directed graph  The capacity function c: E → R+  c(u, v) = the capacity of the edge (u, v)   (u,v)  E  c(u,v) = 0  Assume we have a single source vertex: s  Assume we have a single sink vertex: t  Assume we have a path s .. v .. t  vV
  • 6. Positive Flow  We can define a function called positive flow p: V x V  R+  Properties of positive flow:  Capacity constraint:  u, vV: p(u, v) <= c(u, v)  Flow conservation:  uV {s, t}: flow_in(u) = flow_out(u)  uV {s, t}: vV(p(v, u)) = vV(p(u, v))
  • 7. Positive Flow – Example  Notation on each edge: positive flow/capacity  Note that the two properties are respected  The flow is always lower than the capacity of each edge  The flow is conserved in each vertex  The source produces flow  The sink consumes flow
  • 8. Cancellation for Positive Flow  Note that in the previous example we have:  1 unit of flow from x  z  2 units of flow from z  x  We can cancel 1 unit of flow in both directions  0 units of flow from x  z  1 unit of flow from z  x  Flow conservation is still respected (we cancel the same amount of flow in each direction)  Capacity constraint is still respected (the flow is decreased)  In both cases, the “net flow” is 1 from z  x  Without loss of generality, we may always define a positive flow in a flow network such that for each (u, v), u,vV, we have positive flow either from u  v or from v  u, but not in both directions!
  • 9. Net Flow  We can define a function called net flow f: V x V  R  Properties of net flow:  Capacity constraint:  u, vV: f(u, v) <= c(u, v)  Flow conservation:  uV {s, t}: total_net_flow_in(u) = 0  uV {s, t}: vV(f(u, v)) = 0  Skew symmetry:  u, vV: f(u, v) = - f(v, u)
  • 10. Net Flow (2)  Conservation of net flow can be rewritten: vV (f(u, v)) = 0 As f(u, v) might be either positive or negative  uV {s, t}: vV and f(u,v)<0(f(u, v)) + vV and f(u,v)>0 (f(u, v)) =0  uV {s, t}: vV and f(v,u)>0(f(v, u)) = vV and f(u,v)>0 (f(u, v)) “total positive flow entering u” = “total positive flow leaving u” “flow in” = “flow out”
  • 11. Net Flow – Example  Only positive flow is illustrated in graphical representations  Nevertheless, this does not mean that the (negative) net flow does not exist in the other direction
  • 12. Positive Flow and Net Flow  Differences  Net flow satisfies skew symmetry  p(u, v) >= 0, while f(u, v) >= 0 or f(u, v) <= 0
  • 13. Positive Flow and Net Flow (2)  Equivalence  We can define net flow using only positive flow and vice- versa  f(u, v) = p(u, v) – p(v, u)  u, vV  Need to show that using this definition, the net flow still satisfies the three properties: capacity constraint, conservation and skew symmetry  p(u, v) = f(u, v) if f(u, v) > 0  p(u, v) = 0 otherwise  Need to show that this definition satisfies the two properties of positive flow: capacity constraint and conservation
  • 14. Positive Flow and Net Flow (3)  f(u, v) = p(u, v) – p(v, u)  u, vV  Capacity constraint: p(u, v) <= c(u, v) and p(v, u) >= 0 => f(u, v) = p(u, v) – p(v, u) <= p(u, v) <= c(u, v)  Flow conservation: vV (f(u, v)) = vV (p(u, v) – p(v, u)) = vV (p(u, v)) – vV (p(v, u)) = (from positive flow conservation) = 0  Skew symmetry: f(u, v) = p(u, v) – p(v, u) = –(p(v, u) – p(u, v)) = –f(v,u) Similar for the transformation from f(u, v)  p(u, v). Prove them at home!
  • 15. Value of the Flow  From now on, we shall only use net flow  Value of the flow = |f| = vV (f(s, v)) = vV (f(v, t))  In the example below: |f| = 3
  • 16. Cancellation of (Net) Flow  Let’s say that f(u, v) = 5 and c(u, v) = 8  We can “ship” at most 3 units of flow from u  v  => f(u, v) = 8 = c(u, v)  But we can also “ship” up to 5 units of flow back from v  u  => f(u, v) = 3 if we cancel 2 units of flow!  Called flow cancellation  If (v, u) E => f(v, u) <= c(v, u) = 0  We are not allowed to have a positive flow from v  u  But we are allowed to have negative flow!  This negative flow is equal in absolute value with the positive value from u  v
  • 17. Cancellation of (Net) Flow (2)  Due to cancellation, a flow only gives us this so- called “net” effect. We cannot reconstruct actual “shipments” of products from a net flow.  A flow f(u, v) = 5 and f(v, u) = -5 can mean either: 5 units u  v 6 units u  v 8 units u  v 0 units v  u 1 units v  u 3 units v  u
  • 18. Flow Operations  Extend the definition of the flow to sets of vertices  X,Y  V  f(X,Y) = ΣxXΣyY f(x,y) = total flow between X and Y  Possible operations:  XV f(X,X) = 0;  X,YV f(X,Y) = -f(Y,X);  X,Y,ZV si Y⊆X  f(X Y, Z) = f(X,Z) - f(Y,Z);  f(Z, X Y) = f(Z,X) - f(Z,Y);  X,Y,ZV si XY=  f(X Y, Z) = f(X,Z) + f(Y,Z);  f(Z, X Y) = f(Z,X) + f(Z,Y)  |f| = f(s,V) = f(V,t)
  • 19. Examples (1) X 1/2 a b 1/8 2/2 4/4 3/3 s t 3/9 Y c d 3/5 f(X,Y) = ΣxXΣyY f(x,y) f(X,X) = f(s,a) + f(a,s) + f(s,b) + f(b,s) + f(a,b) + f(b,a) = 0 f(X,Y) = f(b,c) + f(b,t) = -f(c,b) - f(t,b) = -f(Y,X) Proiectarea Algoritmilor 2010
  • 20. Examples (2) X 1/2 a b 1/8 2/2 Y s 4/4 3/3 t c 3/9 Z 3/5 d X, Y, Z  V si Y ⊆ X f(X Y, Z) = f(X, Z) - f(Y, Z) f(Z, X Y) = f(Z, X) - f(Z, Y) f(X Y, Z) = 0 = f(b,t) + f(c,d) - f(b,t) - f(c,d) = f(X,Z) - f(Y,Z) f(Z, X Y) = 0 = f(t,b) + f(d,c) - f(t,b) - f(d,c) = f(Z,X) - f(Z,Y) Proiectarea Algoritmilor 2010
  • 21. Examples (3) Z X 1/2 a b 1/8 2/2 s 4/4 3/3 t 3/9 Y c d 3/5 X, Y, Z  V si X  Y =  f(XY, Z) = f(X,Z) + f(Y,Z) f(Z, XY) = f(Z,X) + f(Z,Y) f(X Y, Z) = f(s,b) + f(a,b) + f(t,b) + f(d,c) = f(X,Z) + f(Y,Z) f(Z, X Y) = f(b,a) + f(b,s) + f(b,t) + f(c,d) = f(Z,X) + f(Z,Y) Proiectarea Algoritmilor 2010
  • 22. Examples (4) 1/2 a b 1/8 2/2 4/4 3/3 s t 3/9 c d 3/5 f(s, V) = f(V, t) f(s, V) = f(s,a) + f(s,b) = 5 = f(d,t) + f(b,t) = f(V, t) Proiectarea Algoritmilor 2010
  • 23. Maximum Flow Problem  Given G(V, E), c: E  R+, sV and tV  Find the maximum flow that can be “transported” from s to t  We start with an initial void flow on all edges  We want to compute the net flow between each pair of vertices that determines a maximum flow!  Various methods are used  Only look at one of the simplest:  Ford-Fulkerson and Edmonds-Karp  Uses the notion of residual network
  • 24. Residual Network  Given G(V, E), c: E  R+, sV and tV  Knowing a given flow in the graph, f: E  R  We can compute the residual capacity for any pair of vertices:  cf(u, v) = c(u, v) – f(u, v) >= 0 (due to capacity constraint)  Residual means: how much flow we can still transport from u  v  We can compute the residual network of the graph:  It is a graph Gf = (V, Ef)  Ef = {(u, v)  V x V | cf(u, v) > 0}  It is a graph that contains edges that have residual capacity (that can still transport flow!)  How many edges does Gf have? Find the minimum and the maximum value!
  • 26. Augmenting Path  Any path from the residual graph admits more flow from the start vertex to the end vertex  Therefore, we want to find a path from the source s to the sink t in the residual graph: augmenting path  Look for p = s..t in Gf  If we can find this augmenting path, compute how much flow we can send along it!  We are constrained by the minimum residual capacity of any edge along the augmenting path  cf(p) = min(cf(u, v) | (u, v) is on p)
  • 27. Augmenting Path – Example  p = <(s, w), (w, y), (y, z), (z, t)>  Is it unique? Can you find another?
  • 28. Summing Flows  If the graph G has a flow f  And we can find another flow f’  We can sum up the two flows to find the new flow: f(u,v) + f’(u,v)  The value of the new flow is |f| + |f’|  Therefore, if we can find an augmenting path, p, in the residual network of a graph, we can also find another flow, fp: V x V  R  fp(u,v) = cf(p) if (u,v) is on p  fp(u,v) = -cf(p) if (v,u) is on p  fp(u,v) = 0  We can thus define a new flow in G: |f’| = |f| + |fp| > |f|  Thus, we can improve the existing flow!
  • 29. Graph Cuts  A cut (S, T) of a flow network G(V, E) is a partitionof the vertices into two sets S (sS) and T = V S (t T)  Already know cuts for minimum spanning trees  The flow across the cut is f(S, T)  The capacity of the cut is c(S, T) = summing up the capacities of all the edges starting from a vertex in S and ending in a vertex in T  A minimum cut in G is a cut whose capacity is minimum over all the possible cuts in G
  • 30. Graph Cuts – Example  S = {s, w, y}, T = {x, z, t}  f(S, T) = f(w, x) + f (y, x) + f(y, z) = 2 + (-1) + 2 = 3  Includes positive flow that goes either direction across the cut  But only takes into account net flow that goes from any vertex in S to any vertex in T  c(S, T) = c(w, x) + c(y, z) = 2 + 3 = 5
  • 31. Max-Flow Min-Cut Theorem  The following statements are equivalent:  f is a maximum flow in G  There is no augmenting path in Gf  |f| = c(S, T) for all minimum cuts (S, T)  This theorem gives us a method to compute the maximum flow: push flow along augmenting paths until you cannot find any  This theorem also tells us how to compute a minimum cut once the maximum flow is known  When f is a maximum flow, all the vertices reachable from s in Gf are in S, the others are in T => (S, T) is a minimum cut
  • 32. Ford-Fulkerson Method 1. Start with a void flow 2. Compute the residual graph for the given flow 3. If there is an augmenting path in this residual graph a) Increase the flow along it b) Go to step 2 4. The maximum flow has been reached!  The disadvantage of this method is that it does not specify how to look for the augmenting path in step 3  Any method can be used  Pick a random augmenting path  Use any search algorithms to compute the path: DFS, BFS  Be greedy: look for the fattest pipe each time! How?
  • 33. Ford-Fulkerson Method (2)  If the augmenting path is not picked smartly, then the worst case running time for the algorithm is O(E*|fmax|)  Why?  Each augmenting path has at most O(E) edges that will cause a change in the value of the flow along them at each step!  Maximum number of steps is fmax if a each step cf(p)=1  See the example on the next slides!  It is not good that the running time depends on fmax  What happens if the capacities of the edges are irrational number? => so is fmax
  • 34. Exemplu Ford – Fulkerson (1) 1000 B 1000 0/1000 B 0/1000 1 G 0/1 Gf A D A D 1000 C 1000 0/1000 C 0/1000 Residual Path: A-B-C-D; Cf = 1 1 1/1000 B 0/1000 B 1000 999 G 1/1 Gf A 1 D A D 999 0/1000 C 1/1000 1000 C 1 Residual Path : A-B-C-D; Cf = 1 1/1000 B 1/1000 1 B 999 1 Gf 999 G A 0/1 D A 1 D 999 1/1000 C 1/1000 999 C 1 1 Proiectarea Algoritmilor 2010 Residual Path : A-B-C-D; Cf = 1
  • 35. Exemplu Ford – Fulkerson (2) 2 2/1000 B 1/1000 B 999 1 998 G 1/1 Gf 1 A D A D 998 999 C 1/1000 C 2/1000 1 2 … Residual Path: A-C-B-D; Cf = 1 1000/1000 B 1000/1000 B 1000 1000 0/1 Gf A D A 1 D 1000/1000 C 1000/1000 1000 C 1000 Residual Path: Ø How many steps are needed to reach the maximum flow? Proiectarea Algoritmilor 2010
  • 36. Edmonds-Karp Algorithm  Is a variant of the Ford-Fulkerson algorithm that guarantees to have a running time that is independent of fmax  Always picks the augmenting path using BFS on Gf  Source vertex for BFS is s  You may stop when t is reached  This way, the length of the augmenting paths is increasing when running the algorithm  We always pick an augmenting path with an equal or greater length than the previous one
  • 37. Edmonds-Karp Algorithm (2) Edmonds–Karp(G, s, t) FOREACH (u,v) in E f(u,v) = f(v,u) = 0 // O(E) WHILE (1) // O(E*V) p = find-augmenting-path-using-bfs(G, f, s, t) // O(E) IF (p == null) BREAK cf(p) = min{cf(u,v) | (u,v) in p} // O(E) FOREACH (u,v) in p // O(E) f(u,v) = f(u,v) + cf(p) f(v,u) = -f(u,v) RETURN f Complexity: O(V*E2)
  • 38. Edmonds-Karp – Example 1000 B 1000 0/1000 B 0/1000 1 G 0/1 Gf A D A D 1000 C 1000 0/1000 C 0/1000 Residual Path: A-B-D; Cf = 1000 1000/1000 B 1000/1000 1000 B 1000 0/1 Gf 1 G A D A D 0/1000 C 1/1000 1000 C 1000 Residual Path: A-C-D; Cf = 1000 1000/1000 B 1000/1000 1000 B 1000 0/1 Gf A D 1 A D 1000/1000 C 1000/1000 1000 1000 C Proiectarea Algoritmilor 2010 Residual Path: Ø
  • 39. Application: Maximum Bipartite Matching  Bipartite graph: we can partition the graph into two sets of vertices L, R such as L U R = V and for all (u, v)E, uL, vR  Matching: a subset of edges, M, such that for all vV at most an edge in M is incident in v  Need to transform this problem into a maximum flow
  • 40. Application: The Escape Problem  http://webcourse.cs.technion.ac.il/234247/Spring2006/ho/ WCFiles/The%20Escape%20Problem.pdf
  • 41. Conclusions  Flow networks are met very often in real life  A lot of applications and interesting problems to be solved: maximum flow is only one of them  It is important to know the main concepts of flow networks: positive flow, net flow, cuts, augmenting networks, etc.  Ford-Fulkerson gives us a generic method to compute the maximum flow in a graph  Edmonds-Karp is a variant of FF that runs in O(V*E2)  There are other algorithms that work better  A lot of problems can be solved using maximum flow, but you need to be able to “transform” them into a flow problem!
  • 42. References  CLRS – Chapter 26  http://www.cs.princeton.edu/courses/archive/fall04/cos22 6/lectures/maxflow.4up.pdf  www.brics.dk/~sskyum/dSoegOpt/public_html/ek.pdf