Maximum flow and minimum cut

A flow network is a directed graph from a source to a destination with capacities assigned along each edge. Just as we can model a street map as a directed graph in order to find the shortest path from one place to another, we can also interpret a directed graph as a "flow network". Some examples of flow networks are liquid flowing through pipes, current passing through electrical networks, and data transferring through communication networks. The following is an example graph flow diagram:

Maximum flow and minimum cut

The edges of the G graph are expected to have a capacity that indicates how much flow the edge can support. If this capacity is not present, then it is assumed to have infinite capacity. The maximum flow of the flow network G here is 4.

In the NetworkX package, the maximum_flow_value(Graph, from, to) function evaluates the maximum flow of a graph, as shown in the following code:

import networkx as nx
G = nx.DiGraph()
G.add_edge('p','y', capacity=5.0)
G.add_edge('p','s', capacity=4.0)
G.add_edge('y','t', capacity=3.0)
G.add_edge('s','h', capacity=5.0)
G.add_edge('s','o', capacity=4.0)

flow_value = nx.maximum_flow_value(G, 'p', 'o')

print "Flow value", flow_value
nx.draw(G, node_color='#a0cbe2')

Flow value 4.0

The graph from the preceding code is being tested for maximum_flow_value, and the display of this graph is shown in the following diagram:

Maximum flow and minimum cut
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset