Code Examples
  Home arrow Code Examples arrow Page 3 - The Ford-Fulkerson Algorithm
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

The Ford-Fulkerson Algorithm
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2009-06-02

    Table of Contents:
  • The Ford-Fulkerson Algorithm
  • The Theory
  • Implementation issues
  • The C Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Ford-Fulkerson Algorithm - Implementation issues


    (Page 3 of 4 )

    While the algorithm presented on the previous page will indeed provide a correct answer, the order in which we take the improved roads to perfect our solution matters. The difference is in execution time and the number of steps required to solve it.

    According to the Edmon-Karps Theorem, if at every step we make the enhancement through the roads that contain the minimum number of roads, the Ford-Fulkerson Algorithm will have its solution in a polynomial time. For the proof of this, look up the Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Cliff Stein book titled Introduction to Algorithms.

    Therefore, we will store the data in two ways before we let the algorithm start. We will use a neighbor list with the modification that we will ignore the direction of the edges, and have another item showing us the sum of the incoming and outgoing edges to a specific vertex.

    The second structure is a neighbor matrix where, at position u and v (representing in practice the edge from u to v), we will store first the current flow of the edge, and the capacity of the edge. While the capacity of the edge will be the read-in data if we have it, one, and otherwise minus one, the current flow value is, for all of them, zero.

    We will do the minimum road search with a modified version of the breadth first search. The search will use the neighbor list that eliminates the direction of the edges; however, we will only consider edges that are not yet saturated. This assures us that we can make the enhancement through the found road.

    To get the amount by which it can improve through an edge, the search will use the neighbor matrix. Inside of this we can deduce if the edge from u to v is incoming or outgoing. If a forward-pointing exists and it still has not reached its capacity, we can travel ahead on it.

    The other valid option is that there exists an incoming edge. Moreover, this has a flow value greater than zero. If there exist both types, first consider the outgoing edges, and after that, the incoming ones. If we find an edge that is valid, we save its parent. The search will start out from the source and will end up in the terminal node. Now we can start a little recursion on this array to find and make the improvement at once.

    While we go deeper on the recursion, we can calculate the maximum value for each vertex. Pick out of them the minimal value. On the back-pointing branch of the recursion, make the improvement as well. To the forward-pointing edges we will add it, and from the backward-indicating ones, subtract it. An example of improvement for the graph:

    The first step is:

    If the minimal value found with this approach is zero, there are no more roads that can provide improvement, and the Ford- Fulkerson Algorithm is finished. Add up all the values with which we enhanced our network, and the overall flow value is also given.

    More Code Examples Articles
    More By Gabor Bernat


     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek