@@ -1299,6 +1299,61 @@ def _max_flow_dinic_(graph: Graph, source, sink):
12991299
13001300
13011301def max_flow (graph , source , sink , algorithm = 'edmonds_karp' , ** kwargs ):
1302+ """
1303+ Computes the maximum flow in a flow network using the specified algorithm.
1304+
1305+ Parameters
1306+ ==========
1307+
1308+ graph: Graph
1309+ The flow network represented as a graph.
1310+ source: str
1311+ The source node in the flow network.
1312+ sink: str
1313+ The sink node in the flow network.
1314+ algorithm: str, optional
1315+ The algorithm to be used for computing maximum flow.
1316+ Currently, the following is supported:
1317+
1318+ 'edmonds_karp' -> Edmonds-Karp algorithm as described in [1].
1319+ 'ford_fulkerson' -> Ford-Fulkerson algorithm as described in [2].
1320+ 'dinic' -> Dinic's algorithm as described in [3].
1321+
1322+ Default is 'edmonds_karp'.
1323+ **kwargs:
1324+ Additional keyword arguments specific to the chosen algorithm.
1325+
1326+ Returns
1327+ =======
1328+
1329+ float
1330+ The maximum flow value from source to sink in the flow network.
1331+
1332+ Examples
1333+ ========
1334+
1335+ >>> from pydatastructs import Graph, max_flow, AdjacencyListGraphNode
1336+ >>> a = AdjacencyListGraphNode("a")
1337+ >>> b = AdjacencyListGraphNode("b")
1338+ >>> c = AdjacencyListGraphNode("c")
1339+ >>> d = AdjacencyListGraphNode("d")
1340+ >>> e = AdjacencyListGraphNode("e")
1341+ >>> G = Graph(a, b, c, d, e)
1342+ >>> G.add_edge('a', 'b', 3)
1343+ >>> G.add_edge('a', 'c', 4)
1344+ >>> G.add_edge('b', 'c', 2)
1345+ >>> G.add_edge('b', 'd', 3)
1346+ >>> G.add_edge('c', 'd', 1)
1347+ >>> G.add_edge('d', 'e', 6)
1348+ 4
1349+
1350+ References
1351+ ==========
1352+
1353+ .. [1] https://en.wikipedia.org/wiki/Edmonds%E2%80%93Karp_algorithm
1354+ .. [2] https://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm
1355+ .. [3] https://en.wikipedia.org/wiki/Dinic%27s_algorithm
1356+ """
13021357 raise_if_backend_is_not_python (
13031358 max_flow , kwargs .get ('backend' , Backend .PYTHON ))
13041359
0 commit comments