diff options
| author | Jordi Torrents <jordi.t21@gmail.com> | 2016-04-24 22:19:27 +0200 |
|---|---|---|
| committer | Jordi Torrents <jordi.t21@gmail.com> | 2016-04-24 22:19:27 +0200 |
| commit | fe3c5073b9f68b9afd366ed8e91c21abafcb3a7c (patch) | |
| tree | dfe28748382c311eb16ed96a8b8a303f79dd18bd /networkx/algorithms/flow | |
| parent | 9fcaea9cae8beaf46cbb9df0576102de92bbc691 (diff) | |
| download | networkx-fe3c5073b9f68b9afd366ed8e91c21abafcb3a7c.tar.gz | |
Improve Notes section on simplex and friends docs.
Add a Notes section to functions that use network_simplex warning
users of the potential problems of using float edge weights. Also
mention the workaround of multimplying weights by a convenient constant
factor.
Diffstat (limited to 'networkx/algorithms/flow')
| -rw-r--r-- | networkx/algorithms/flow/mincost.py | 33 | ||||
| -rw-r--r-- | networkx/algorithms/flow/networksimplex.py | 4 |
2 files changed, 35 insertions, 2 deletions
diff --git a/networkx/algorithms/flow/mincost.py b/networkx/algorithms/flow/mincost.py index 2b3b5566..ad461491 100644 --- a/networkx/algorithms/flow/mincost.py +++ b/networkx/algorithms/flow/mincost.py @@ -81,6 +81,14 @@ def min_cost_flow_cost(G, demand = 'demand', capacity = 'capacity', -------- cost_of_flow, max_flow_min_cost, min_cost_flow, network_simplex + 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). + Examples -------- A simple example of a min cost flow problem. @@ -166,6 +174,14 @@ def min_cost_flow(G, demand = 'demand', capacity = 'capacity', -------- cost_of_flow, max_flow_min_cost, min_cost_flow_cost, network_simplex + 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). + Examples -------- A simple example of a min cost flow problem. @@ -216,6 +232,14 @@ def cost_of_flow(G, flowDict, weight = 'weight'): See also -------- max_flow_min_cost, min_cost_flow, min_cost_flow_cost, network_simplex + + 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). """ return sum((flowDict[u][v] * d.get(weight, 0) for u, v, d in G.edges(data = True))) @@ -275,6 +299,14 @@ def max_flow_min_cost(G, s, t, capacity = 'capacity', weight = 'weight'): -------- cost_of_flow, min_cost_flow, min_cost_flow_cost, network_simplex + 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). + Examples -------- >>> G = nx.DiGraph() @@ -303,7 +335,6 @@ def max_flow_min_cost(G, s, t, capacity = 'capacity', weight = 'weight'): >>> mincostFlowValue == nx.maximum_flow_value(G, 1, 7) True - """ maxFlow = nx.maximum_flow_value(G, s, t, capacity = capacity) H = nx.DiGraph(G) diff --git a/networkx/algorithms/flow/networksimplex.py b/networkx/algorithms/flow/networksimplex.py index 42cb4aaf..5a346afd 100644 --- a/networkx/algorithms/flow/networksimplex.py +++ b/networkx/algorithms/flow/networksimplex.py @@ -96,7 +96,9 @@ def network_simplex(G, demand='demand', capacity='capacity', weight='weight'): ----- This algorithm is not guaranteed to work if edge weights or demands are floating point numbers (overflows and roundoff errors can - cause problems). + cause problems). As a workaround you can use integer numbers by + multiplying the relevant edge attributes by a convenient + constant factor (eg 100). See also -------- |
