Giter VIP home page Giter VIP logo

ford-fulkerson-algorithm's Introduction

Ford-Fulkerson Algorithm

This code implements the Ford-Fulkerson algorithm for finding the maximum flow in a graph ๐Ÿ“ˆ.

The output is the maximum flow found, along with a track of the capacity of edges to transport this flow.

๐Ÿ“ Residual graph

The code uses a "residual graph" to save the maximum flow of each iteration. The residual graph is a copy of the original graph, but this is set with the capacities of the edges that transport the maximum flow found in each iteration. This allows the code to find the maximum flow in a graph by iteratively finding paths from the source vertex to the sink vertex, subtracting the capacity of the edges of the main graph of each from the capacities of the edges in the residual graph of each iteration. The algorithm terminates when there are no more paths from the source vertex to the sink vertex.

๐Ÿš€ Usage

  1. Prepare your input data:
  • Create a CSV file representing the graph ๐Ÿ“„.
  • The CSV file should contain a square matrix where each element represents the capacity of an edge between two nodes.
  • The values should be non-negative integers.
  1. To run the code, you will need to have Python 3 installed. Once you have Python 3 installed, you can run the code by typing the following command in a terminal:
python ford_fulkerson.py <filename> <source> <sink>

Arguments:

  • filename: the name or the path of the CSV file.
  • source and sink: the indices of the source and sink nodes in the graph, respectively.

๐Ÿ“š Examples

The code can be tested with three examples:

Alt text

In this graph the source node is 0 and the sink node is 5. You can run the code typing the command:

python ford_fulkerson.py example.csv 0 5

Alt text

In this graph the source node is 0 and the sink node is 8. You can run the code typing the command:

python ford_fulkerson.py example2.csv 0 8

In the last graph the source node is 0 and the sink node is 31. You can run the code typing the command:

python ford_fulkerson.py example3.csv 0 31

๐Ÿงช Testing

  1. First you need to install pytest if you currently don't have it installed by typing this command:
pip install pytest
  1. Modify the file test_fordfulkerson.py (by default it have some asserts of the result of the examples) and type this command:
pytest test_fordfulkerson.py

ford-fulkerson-algorithm's People

Contributors

carlosantiagorojas avatar

Watchers

 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.