Repository: networkx/networkx
Pull request: issue #6081: allow cutoff functionality for flow functions
In maxflow.py, I changed ``` flow_funcs ``` to ``` flow_funcs_without_cutoff  ``` and also updated the flow functions that support *cutoff*. In text_maxflow.py, I added  ``` flow_funcs_without_cutoff  ```. 
This was discussed in https://github.com/networkx/networkx/issues/6081. 
Closes #6081

Problem statement:
cutoff argument improperly disallowed when calling `minimum_cut` with `shortest_augmenting_path`
It should be possible to call `minimum_cut(G, s, t, flow_func=shortest_augmenting_path, cutoff=3)` however this raises an exception.

From `maxflow.py`, `minium_cut()` definition:
```
    if kwargs.get("cutoff") is not None and flow_func in flow_funcs:
        raise nx.NetworkXError("cutoff should not be specified.")
```
where
```
# Functions that don't support cutoff for minimum cut computations.
flow_funcs = [
    boykov_kolmogorov,
    dinitz,
    edmonds_karp,
    preflow_push,
    shortest_augmenting_path,
]
```
however the docstring and source for `shortestaugmentingpath.py` do allow the `cutoff` argument.

Hints from issue discussion:
I think the problem is that cutoff for shortest_augmenting_path is not working properly that's why is disabled even when the function does allow the argument. 
Can you point me to any github issue or failing unit test for `shortest_augmenting_path` not working properly?
In the details of #1102 it seems that the initial flagging of functions that don't have the cutoff functionality correctly included the `shortest_augmenting_path` (as well as some others) but the `cutoff` functionality was added in a commit a few days later. It looks like an oversight that these functions did not get removed from the list of functions that do not support the cutoff input parameter.  

I believe there may be others in `flow_funcs` that also do now support (and long have supported) the cutoff feature.
Can someone check those functions and make a PR to correct the list of functions that don't support the cutoff feature?

~~I'm going to transfer this discussion to an Issue so we make sure to fix this.~~{already is an Issue :}
I'll do it 
Awesome! I might suggest the list variable be called `flow_funcs_without_cutoff` for readability.
I agree that the name of that variable needs to be changed. That suggestion looks good to me.

Commit message: update flow_funcs_without_cutoff

Patch to review:
diff --git a/networkx/algorithms/flow/maxflow.py b/networkx/algorithms/flow/maxflow.py
index 8d2fb8f03e5..d8e719b43bd 100644
--- a/networkx/algorithms/flow/maxflow.py
+++ b/networkx/algorithms/flow/maxflow.py
@@ -13,13 +13,7 @@
 # Define the default flow function for computing maximum flow.
 default_flow_func = preflow_push
 # Functions that don't support cutoff for minimum cut computations.
-flow_funcs = [
-    boykov_kolmogorov,
-    dinitz,
-    edmonds_karp,
-    preflow_push,
-    shortest_augmenting_path,
-]
+flow_funcs_without_cutoff = [preflow_push]
 
 __all__ = ["maximum_flow", "maximum_flow_value", "minimum_cut", "minimum_cut_value"]
 
@@ -452,7 +446,7 @@ def minimum_cut(flowG, _s, _t, capacity="capacity", flow_func=None, **kwargs):
     if not callable(flow_func):
         raise nx.NetworkXError("flow_func has to be callable.")
 
-    if kwargs.get("cutoff") is not None and flow_func in flow_funcs:
+    if kwargs.get("cutoff") is not None and flow_func in flow_funcs_without_cutoff:
         raise nx.NetworkXError("cutoff should not be specified.")
 
     R = flow_func(flowG, _s, _t, capacity=capacity, value_only=True, **kwargs)
@@ -603,7 +597,7 @@ def minimum_cut_value(flowG, _s, _t, capacity="capacity", flow_func=None, **kwar
     if not callable(flow_func):
         raise nx.NetworkXError("flow_func has to be callable.")
 
-    if kwargs.get("cutoff") is not None and flow_func in flow_funcs:
+    if kwargs.get("cutoff") is not None and flow_func in flow_funcs_without_cutoff:
         raise nx.NetworkXError("cutoff should not be specified.")
 
     R = flow_func(flowG, _s, _t, capacity=capacity, value_only=True, **kwargs)
diff --git a/networkx/algorithms/flow/tests/test_maxflow.py b/networkx/algorithms/flow/tests/test_maxflow.py
index 36bc5ec7ce6..097ff18d26b 100644
--- a/networkx/algorithms/flow/tests/test_maxflow.py
+++ b/networkx/algorithms/flow/tests/test_maxflow.py
@@ -13,6 +13,10 @@
     shortest_augmenting_path,
 )
 
+flow_funcs_without_cutoff = {
+    preflow_push,
+}
+
 flow_funcs = {
     boykov_kolmogorov,
     dinitz,
@@ -20,6 +24,7 @@
     preflow_push,
     shortest_augmenting_path,
 }
+
 max_min_funcs = {nx.maximum_flow, nx.minimum_cut}
 flow_value_funcs = {nx.maximum_flow_value, nx.minimum_cut_value}
 interface_funcs = max_min_funcs & flow_value_funcs
@@ -427,7 +432,7 @@ def test_flow_func_parameters(self):
 
     def test_minimum_cut_no_cutoff(self):
         G = self.G
-        for flow_func in flow_funcs:
+        for flow_func in flow_funcs_without_cutoff:
             pytest.raises(
                 nx.NetworkXError,
                 nx.minimum_cut,


Code review comments:
diff_hunk: @@ -13,13 +13,18 @@
     shortest_augmenting_path,
 )
 
+flow_funcs_without_cutoff = {
+    preflow_push,
+}
+
path: networkx/algorithms/flow/tests/test_maxflow.py
text: @user1:
can this be imported from `maxflow.py` so that there is a single source of truth?

@author:
Definitely!