void updateResidualNetworkWithCurrentAugmentingPath()

in src/main/java/org/apache/commons/graph/flow/FlowNetworkHandler.java [100:131]


    void updateResidualNetworkWithCurrentAugmentingPath()
    {
        // build actual augmenting path
        WeightedPath<V, E, W> augmentingPath = predecessors.buildPath( source, target );

        // find flow increment
        W flowIncrement = null;
        for ( E edge : augmentingPath.getEdges() )
        {
            W edgeCapacity = residualEdgeCapacities.get( edge );
            if ( flowIncrement == null
                     || weightOperations.compare( edgeCapacity, flowIncrement ) < 0 )
            {
                flowIncrement = edgeCapacity;
            }
        }

        // update max flow and capacities accordingly
        maxFlow = weightOperations.append( maxFlow, flowIncrement );
        for ( E edge : augmentingPath.getEdges() )
        {
            // decrease capacity for direct edge
            W directCapacity = residualEdgeCapacities.get( edge );
            residualEdgeCapacities.put( edge, weightOperations.append( directCapacity, weightOperations.inverse( flowIncrement ) ) );

            // increase capacity for inverse edge
            VertexPair<V> vertexPair = flowNetwork.getVertices( edge );
            E inverseEdge = flowNetwork.getEdge( vertexPair.getTail(), vertexPair.getHead() );
            W inverseCapacity = residualEdgeCapacities.get( inverseEdge );
            residualEdgeCapacities.put( inverseEdge, weightOperations.append( inverseCapacity, flowIncrement ) );
        }
    }