Giter Club home page Giter Club logo

ford-fulkerson's Introduction

Ford Fulkerson Max-Flow / Min Cut Algorithm

Simple implementation to find the maximum flow through a flow network (no Capacity Scaling)

"0/10" means an edge with capacity 10 and 0 flow assigned

Terminology

  • Residual graph
    Directed graph showing how much of the flow assignments can be undone
    Edge e=(u,v) shows how much flow is left to be assigned to that edge
    Edge e=(v,u) is how much flow already been assigned (how much ca be undone)
  • Augmentation Path
    An arbitrary path from S to T found in residual graph
  • Bottleneck
    Minimum capacity from the path found in the residual graph (how much flow is assigned after each path is found)

Usage

  • vertexCount must be hard coded for different graphs
  • Code deals directly with integer array indexes. Index 0 is S (source) and index vertexCount-1 is T (sink) (-1 since arrays count from 0)
  • arrayIndexStringEquivalents holds string equivalents of the index. So vertices can have humanly readable IDs like S & T, and don't have to be sequential integers
    • arrayIndexStringEquivalents[1] is 2 because the vertex called "2" is the in position 1 in the array indexes
  • Graphs are represented as adjacency matrices
    • Directed Graph so order matters
    • graphMatrix[i][j] represents the capacity of an edge from i to j
      • 0 if no edge exists
      • No vertex has an edge to itself. There should always be a 0 in graphMatrix[x][x]
        • graphMatrix[0][0] is 0 since S has no edges to itself
        • Same for all vertices
        • graphMatrix[1][1] is 0 since the vertex in position 1 (vertex "2") has no edges to itself, etc.
      • Row vertexCount-1 is always all 0's since T (the sink) has NO outgoing edges {0, 0, 0, 0, 0, 0, 0, 0}

Final Flow Network

Final Residual Graph

Max Flow = 28

Code Details

  • Constructor takes in an array of strings to have human readable vertices instead of ints
  • maxFlow() finds the maximum flow through the network
    • Creates a residual graph & leaves the original graph unchanged
  • Uses Breadth First Search bfs() to find augmentation paths
    • Returns true/false if a path from S to T was found
    • Updates parent[] array so the actual path can be found
  • maxFlow() outputs each augmentation path found & the amount of flow added to total flow (bottleneck)

ford-fulkerson's People

Contributors

sleekpanther avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.