You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_find_entering_edge in mincost.py does not work for degenerate trees (migrated from Trac #619) #610
When trying to solve a network flow problem using networkx.algorithms.flow.network_simplex, I encountered a problem when a node seemed to disappear from the basis tree. I looked into the code and reaslied that the _find_entering_edge function in networkx\algorithms\flow\mincost.py did not cater for degenerate bases/trees. The function is given below with the problem indicated:
def _find_entering_edge(H, c, capacity = 'capacity'):
"""Find an edge which creates a negative cost cycle in the actual
tree solution.
The reduced cost of every edge gives the value of the cycle
obtained by adding that edge to the tree solution. If that value is
negative, we will augment the flow in the direction indicated by
the edge. Otherwise, we will augment the flow in the reverse
direction.
If no edge is found, return and empty tuple. This will cause the
main loop of the algorithm to terminate.
"""
newEdge = ()
for u, v, d in H.edges_iter(data = True):
if d.get('flow', 0) == 0: <- if tree is degenerate then
if c[(u, v)] < 0: <- its flow is 0 and c[(u, v)]
newEdge = (u, v) <- might be < 0 by numerical error
break <- so (u, v) enters when it is
else: <- already in the tree
if capacity in d:
if (d.get('flow', 0) == d[capacity]
and c[(u, v)] > 0):
newEdge = (u, v)
break
Activity
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @loicseguin, 2011-08-11
Can you provide an example where the algorithm fails?
What exactly do you mean when you say "degenerate tree"?
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @loicseguin, 2012-03-26
Update pydot interface to use newer attribute handling style.
loicseguin commentedon Aug 22, 2013
Since there has been no feedback on this issue from the person who opened it in the last two years, I will mark it as closed.