mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 00:54:32 +08:00
Enhance docs, add more tests in FordFulkerson
(#5953)
This commit is contained in:
@ -3,12 +3,30 @@ package com.thealgorithms.datastructures.graphs;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* This class implements the Ford-Fulkerson algorithm to compute the maximum flow
|
||||
* in a flow network.
|
||||
*
|
||||
* <p>The algorithm uses breadth-first search (BFS) to find augmenting paths from
|
||||
* the source vertex to the sink vertex, updating the flow in the network until
|
||||
* no more augmenting paths can be found.</p>
|
||||
*/
|
||||
public final class FordFulkerson {
|
||||
private static final int INF = Integer.MAX_VALUE;
|
||||
|
||||
private FordFulkerson() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the maximum flow in a flow network using the Ford-Fulkerson algorithm.
|
||||
*
|
||||
* @param vertexCount the number of vertices in the flow network
|
||||
* @param capacity a 2D array representing the capacity of edges in the network
|
||||
* @param flow a 2D array representing the current flow in the network
|
||||
* @param source the source vertex in the flow network
|
||||
* @param sink the sink vertex in the flow network
|
||||
* @return the total maximum flow from the source to the sink
|
||||
*/
|
||||
public static int networkFlow(int vertexCount, int[][] capacity, int[][] flow, int source, int sink) {
|
||||
int totalFlow = 0;
|
||||
|
||||
|
Reference in New Issue
Block a user