Skip to content

_find_entering_edge in mincost.py does not work for degenerate trees (migrated from Trac #619) #610

Closed

Description

@networkx-trac

Original ticket https://networkx.lanl.gov/trac/ticket/619
Reported 2011-08-11 by michael.osullivan, assigned to @loicseguin.

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

return newEdge

Activity

  1. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    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"?

  2. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @loicseguin, 2012-03-26

  3. loicseguin commented on Aug 22, 2013

    @loicseguin
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions