def create_residual_graph(self):
        '''
        API: create_residual_graph(self)
        Description:
        Creates and returns residual graph, which is a Graph instance
        itself.
        Pre:
            (1) Arcs should have 'flow', 'capacity' and 'cost' attribute
            (2) Graph should be a directed graph
        Return:
            Returns residual graph, which is a Graph instance.
        '''
        if self.graph_type is UNDIRECTED_GRAPH:
            raise Exception('residual graph is defined for directed graphs.')
        residual_g = Graph(type = DIRECTED_GRAPH)
        for e in self.get_edge_list():
            capacity_e = self.get_edge_attr(e[0], e[1], 'capacity')
            flow_e = self.get_edge_attr(e[0], e[1], 'flow')
            cost_e = self.get_edge_attr(e[0], e[1], 'cost')
            if flow_e > 0:
                residual_g.add_edge(e[1], e[0], cost=-1*cost_e,
                                    capacity=flow_e)
            if capacity_e - flow_e > 0:
                residual_g.add_edge(e[0], e[1], cost=cost_e,
                                    capacity=capacity_e-flow_e)
        return residual_g
def create_residual_graph ( self ) : if self . graph_type is UNDIRECTED_GRAPH : raise Exception ( 'residual graph is defined for directed graphs.' ) residual_g = Graph ( type = DIRECTED_GRAPH ) for e in self . get_edge_list ( ) : capacity_e = self . get_edge_attr ( e [ 0 ] , e [ 1 ] , 'capacity' ) flow_e = self . get_edge_attr ( e [ 0 ] , e [ 1 ] , 'flow' ) cost_e = self . get_edge_attr ( e [ 0 ] , e [ 1 ] , 'cost' ) if flow_e > 0 : residual_g . add_edge ( e [ 1 ] , e [ 0 ] , cost = - 1 * cost_e , capacity = flow_e ) if capacity_e - flow_e > 0 : residual_g . add_edge ( e [ 0 ] , e [ 1 ] , cost = cost_e , capacity = capacity_e - flow_e ) return residual_g
API: create_residual_graph(self)
        Description:
        Creates and returns residual graph, which is a Graph instance
        itself.
        Pre:
            (1) Arcs should have 'flow', 'capacity' and 'cost' attribute
            (2) Graph should be a directed graph
        Return:
            Returns residual graph, which is a Graph instance.