// calculateResidualNetwork will calculate residual network with current flow based on flow network
calculateResidualNetwork will calculate residual network with current flow based on flow network
// calculateResidualNetwork will calculate residual network with current flow based on flow network
func calculateResidualNetwork(fn *flownetwork.FlowNetwork, flow flowStorage) *residualNetwork {
	rn := &residualNetwork{graph.NewAdjacencyListGraph(fn.NodeCount(), fn.Directed()), flownetwork.CapacityStorage{}}
	fn.IterateAllNodes(func(u graph.NodeID) {
		fn.IterateAdjacencyNodes(u, func(v graph.NodeID) {
			edge := graph.EdgeID{From: u, To: v}
			edgeFlow := flow[edge]
			if edgeFlow > 0 {
				if fn.Capacity(edge) > edgeFlow {
					rn.AddEdge(u, v)
					rn.residualCapacities[edge] = fn.Capacity(edge) - edgeFlow
				}
				rn.AddEdge(v, u)
				rn.residualCapacities[edge.Reverse()] = edgeFlow
			} else {
				rn.AddEdge(u, v)
				rn.residualCapacities[edge] = fn.Capacity(edge)
			}
		})
	})
	return rn
}
func calculateResidualNetwork ( fn * flownetwork . FlowNetwork , flow flowStorage ) * residualNetwork { rn := & residualNetwork { graph . NewAdjacencyListGraph ( fn . NodeCount ( ) , fn . Directed ( ) ) , flownetwork . CapacityStorage { } } fn . IterateAllNodes ( func ( u graph . NodeID ) { fn . IterateAdjacencyNodes ( u , func ( v graph . NodeID ) { edge := graph . EdgeID { From : u , To : v } edgeFlow := flow [ edge ] if edgeFlow > 0 { if fn . Capacity ( edge ) > edgeFlow { rn . AddEdge ( u , v ) rn . residualCapacities [ edge ] = fn . Capacity ( edge ) - edgeFlow } rn . AddEdge ( v , u ) rn . residualCapacities [ edge . Reverse ( ) ] = edgeFlow } else { rn . AddEdge ( u , v ) rn . residualCapacities [ edge ] = fn . Capacity ( edge ) } } ) } ) return rn }
calculateResidualNetwork will calculate residual network with current flow based on flow network
calculateResidualNetwork will calculate residual network with current flow based on flow network
//reverse edge for residual network graph