min_cost_flow_cost(G, demand='demand', capacity='capacity', weight='weight')
G is a digraph with edge costs and capacities and in which nodes have demand, i.e., they want to send or receive some amount of flow. A negative demand means that the node wants to send flow, a positive demand means that the node want to receive flow. A flow on the digraph G satisfies all demand if the net flow into each node is equal to the demand of that node.
This algorithm is not guaranteed to work if edge weights or demands are floating point numbers (overflows and roundoff errors can cause problems). As a workaround you can use integer numbers by multiplying the relevant edge attributes by a convenient constant factor (eg 100).
DiGraph on which a minimum cost flow satisfying all demands is to be found.
Nodes of the graph G are expected to have an attribute demand that indicates how much flow a node wants to send (negative demand) or receive (positive demand). Note that the sum of the demands should be 0 otherwise the problem in not feasible. If this attribute is not present, a node is considered to have 0 demand. Default value: 'demand'.
Edges of the graph G are expected to have an attribute capacity that indicates how much flow the edge can support. If this attribute is not present, the edge is considered to have infinite capacity. Default value: 'capacity'.
Edges of the graph G are expected to have an attribute weight that indicates the cost incurred by sending one unit of flow on that edge. If not present, the weight is considered to be 0. Default value: 'weight'.
This exception is raised if the input graph is not directed or not connected.
This exception is raised in the following situations:
The sum of the demands is not zero. Then, there is no flow satisfying all demands.
There is no flow satisfying all demand.
This exception is raised if the digraph G has a cycle of negative cost and infinite capacity. Then, the cost of a flow satisfying all demands is unbounded below.
Cost of a minimum cost flow satisfying all demands.
Find the cost of a minimum cost flow satisfying all demands in digraph G.
A simple example of a min cost flow problem.
>>> G = nx.DiGraph()See :
... G.add_node("a", demand=-5)
... G.add_node("d", demand=5)
... G.add_edge("a", "b", weight=3, capacity=4)
... G.add_edge("a", "c", weight=6, capacity=10)
... G.add_edge("b", "d", weight=1, capacity=9)
... G.add_edge("c", "d", weight=2, capacity=5)
... flowCost = nx.min_cost_flow_cost(G)
... flowCost 24
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.algorithms.flow.mincost.min_cost_flow_cost
networkx.algorithms.flow.mincost.min_cost_flow
networkx.algorithms.flow.mincost.cost_of_flow
networkx.algorithms.flow.mincost.max_flow_min_cost
networkx.algorithms.flow.networksimplex.network_simplex
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them