diff options
| author | Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com> | 2015-05-19 21:50:48 -0400 |
|---|---|---|
| committer | Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com> | 2015-07-17 01:36:27 -0400 |
| commit | 2f70ad71c5c9bf5e1929f78fc5f0d25c397a7652 (patch) | |
| tree | 9a43d466411201f12c5e18d647d281640a023a7c /networkx/algorithms/flow/preflowpush.py | |
| parent | 1bba0a9aaeac331d735247eb0ddad281f1b0d44e (diff) | |
| download | networkx-2f70ad71c5c9bf5e1929f78fc5f0d25c397a7652.tar.gz | |
Use peek(S) instead of next(iter(S)).
As of the date of this commit, there is no way to get an arbitrary
element of an iterable like a set without modifying it (for example, as
in `set.pop()`). The `peek()` function is more readable than writing
next(iter(S))
whenever an arbitrary element of an iterable is required.
Diffstat (limited to 'networkx/algorithms/flow/preflowpush.py')
| -rw-r--r-- | networkx/algorithms/flow/preflowpush.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/networkx/algorithms/flow/preflowpush.py b/networkx/algorithms/flow/preflowpush.py index 3db0ae09..6bb3e4a0 100644 --- a/networkx/algorithms/flow/preflowpush.py +++ b/networkx/algorithms/flow/preflowpush.py @@ -11,7 +11,13 @@ __author__ = """ysitu <ysitu@users.noreply.github.com>""" from collections import deque from itertools import islice import networkx as nx -from networkx.algorithms.flow.utils import * +#from networkx.algorithms.flow.utils import * +from ...utils import arbitrary_element +from .utils import build_residual_network +from .utils import CurrentEdge +from .utils import detect_unboundedness +from .utils import GlobalRelabelThreshold +from .utils import Level __all__ = ['preflow_push'] @@ -233,7 +239,7 @@ def preflow_push_impl(G, s, t, capacity, residual, global_relabel_freq, # Record the old height and level for the gap heuristic. old_height = height old_level = level - u = next(iter(level.active)) + u = arbitrary_element(level.active) height = discharge(u, True) if grt.is_reached(): # Global relabeling heuristic: Recompute the exact heights of @@ -277,7 +283,7 @@ def preflow_push_impl(G, s, t, capacity, residual, global_relabel_freq, # Move to the next lower level. height -= 1 break - u = next(iter(level.active)) + u = arbitrary_element(level.active) height = discharge(u, False) if grt.is_reached(): # Global relabeling heuristic. |
