cost_of_flow#
- cost_of_flow(G, flowDict, weight='weight')[source]#
Compute the cost of the flow given by flowDict on graph G.
Note that this function does not check for the validity of the flow flowDict. This function will fail if the graph G and the flow donâ€™t have the same edge set.
- Parameters:
- GNetworkX graph
DiGraph on which a minimum cost flow satisfying all demands is to be found.
- weightstring
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â€™.
- flowDictdictionary
Dictionary of dictionaries keyed by nodes such that flowDict[u][v] is the flow edge (u, v).
- Returns:
- costInteger, float
The total cost of the flow. This is given by the sum over all edges of the product of the edgeâ€™s flow and the edgeâ€™s weight.
Notes
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).