NetworkFlow

Network Flow Example

This project provides a simple implementation and example of finding the maximum flow of a network.

This implements the Edmonds-Karp algorithm for Ford-Fulkerson using breadth-first search and an adjacency matrix representation of the network.

Utility class: MaxFlowExample

JUnit 5 Test class: MaxFlowExampleTest

Software Development Observation

Why use a Record?

The first draft used side-effects in Java, where a method modifies an object passed to it. The residualGraph array was passed into the method as a mutable object to be modified by the method. It is a simple way to “return” multiple pieces of information, in this case the int flow (return value) and the int[][] graph.

Argument Against Side-Effects (clean code)

Most modern programming paradigms (especially Functional Programming) argue for immutability. When a method modifies an object passed into it:

Why do we treat returning the parent array and the residualGraph differently?

There is a subtle but important distinction in how these two arrays function within the logic:


https://metrocs.github.io/NetworkFlow/