summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhayGoyal <goyalabhay97@gmail.com>2021-01-20 15:33:52 -0500
committerGitHub <noreply@github.com>2021-01-20 15:33:52 -0500
commitf63e90ba4676fcb4ef74c5bd7ddda56be50d4c90 (patch)
tree8cd3a097ac57019b004aade9e76da8592abf88ce
parenta6dd458a12ad8db161271e2271644803d4f29a96 (diff)
downloadnetworkx-f63e90ba4676fcb4ef74c5bd7ddda56be50d4c90.tar.gz
updated cutoff def in weighted.py (#4546)
* updated cutoff def in weighted.py * Revert "updated with correct format" This reverts commit 79fee98f981a4511e231061d8e5b04dd9f45ae2a. * updated cutoff def in weighted.py * updated cutoff def in weighted.py * Adjust indentation of cutoff parameter description. * Adjust all docstring parameter description indents in weighted.py Co-authored-by: Dan Schult <dschult@colgate.edu>
-rw-r--r--networkx/algorithms/shortest_paths/weighted.py600
1 files changed, 306 insertions, 294 deletions
diff --git a/networkx/algorithms/shortest_paths/weighted.py b/networkx/algorithms/shortest_paths/weighted.py
index fa9c000b..0f2e189b 100644
--- a/networkx/algorithms/shortest_paths/weighted.py
+++ b/networkx/algorithms/shortest_paths/weighted.py
@@ -88,28 +88,28 @@ def dijkstra_path(G, source, target, weight="weight"):
G : NetworkX graph
source : node
- Starting node
+ Starting node
target : node
- Ending node
+ Ending node
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
path : list
- List of nodes in a shortest path.
+ List of nodes in a shortest path.
Raises
------
@@ -117,7 +117,7 @@ def dijkstra_path(G, source, target, weight="weight"):
If `source` is not in `G`.
NetworkXNoPath
- If no path exists between source and target.
+ If no path exists between source and target.
Examples
--------
@@ -169,23 +169,23 @@ def dijkstra_path_length(G, source, target, weight="weight"):
G : NetworkX graph
source : node label
- starting node for path
+ starting node for path
target : node label
- ending node for path
+ ending node for path
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
@@ -246,28 +246,29 @@ def single_source_dijkstra_path(G, source, cutoff=None, weight="weight"):
G : NetworkX graph
source : node
- Starting node for path.
+ Starting node for path.
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
paths : dictionary
- Dictionary of shortest path lengths keyed by target.
+ Dictionary of shortest path lengths keyed by target.
Raises
------
@@ -309,23 +310,24 @@ def single_source_dijkstra_path_length(G, source, cutoff=None, weight="weight"):
G : NetworkX graph
source : node label
- Starting node for path
+ Starting node for path
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
@@ -382,37 +384,39 @@ def single_source_dijkstra(G, source, target=None, cutoff=None, weight="weight")
G : NetworkX graph
source : node label
- Starting node for path
+ Starting node for path
target : node label, optional
- Ending node for path
+ Ending node for path
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
+
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
distance, path : pair of dictionaries, or numeric and list.
- If target is None, paths and lengths to all nodes are computed.
- The return value is a tuple of two dictionaries keyed by target nodes.
- The first dictionary stores distance to each target node.
- The second stores the path to each target node.
- If target is not None, returns a tuple (distance, path), where
- distance is the distance from source to target and path is a list
- representing the path from source to target.
+ If target is None, paths and lengths to all nodes are computed.
+ The return value is a tuple of two dictionaries keyed by target nodes.
+ The first dictionary stores distance to each target node.
+ The second stores the path to each target node.
+ If target is not None, returns a tuple (distance, path), where
+ distance is the distance from source to target and path is a list
+ representing the path from source to target.
Raises
------
@@ -485,25 +489,26 @@ def multi_source_dijkstra_path(G, sources, cutoff=None, weight="weight"):
computed paths may begin from any one of the start nodes.
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
paths : dictionary
- Dictionary of shortest paths keyed by target.
+ Dictionary of shortest paths keyed by target.
Examples
--------
@@ -557,20 +562,21 @@ def multi_source_dijkstra_path_length(G, sources, cutoff=None, weight="weight"):
computed paths may begin from any one of the start nodes.
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
@@ -635,33 +641,34 @@ def multi_source_dijkstra(G, sources, target=None, cutoff=None, weight="weight")
computed paths may begin from any one of the start nodes.
target : node label, optional
- Ending node for path
+ Ending node for path
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
distance, path : pair of dictionaries, or numeric and list
- If target is None, returns a tuple of two dictionaries keyed by node.
- The first dictionary stores distance from one of the source nodes.
- The second stores the path from one of the sources to that node.
- If target is not None, returns a tuple of (distance, path) where
- distance is the distance from source to target and path is a list
- representing the path from source to target.
+ If target is None, returns a tuple of two dictionaries keyed by node.
+ The first dictionary stores distance from one of the source nodes.
+ The second stores the path from one of the sources to that node.
+ If target is not None, returns a tuple of (distance, path) where
+ distance is the distance from source to target and path is a list
+ representing the path from source to target.
Examples
--------
@@ -776,7 +783,8 @@ def _dijkstra_multisource(
Ending node for path. Search is halted when target is found.
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
Returns
-------
@@ -860,31 +868,32 @@ def dijkstra_predecessor_and_distance(G, source, cutoff=None, weight="weight"):
G : NetworkX graph
source : node label
- Starting node for path
+ Starting node for path
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
pred, distance : dictionaries
- Returns two dictionaries representing a list of predecessors
- of a node and the distance to each node.
- Warning: If target is specified, the dicts are incomplete as they
- only contain information for the nodes along a path to target.
+ Returns two dictionaries representing a list of predecessors
+ of a node and the distance to each node.
+ Warning: If target is specified, the dicts are incomplete as they
+ only contain information for the nodes along a path to target.
Raises
------
@@ -928,20 +937,21 @@ def all_pairs_dijkstra(G, cutoff=None, weight="weight"):
G : NetworkX graph
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edge[u][v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edge[u][v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Yields
------
@@ -995,20 +1005,21 @@ def all_pairs_dijkstra_path_length(G, cutoff=None, weight="weight"):
G : NetworkX graph
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
@@ -1052,25 +1063,26 @@ def all_pairs_dijkstra_path(G, cutoff=None, weight="weight"):
G : NetworkX graph
cutoff : integer or float, optional
- Depth to stop the search. Only return paths with length <= cutoff.
+ Length (sum of edge weights) at which the search is stopped.
+ If cutoff is provided, only return paths with summed weight <= cutoff.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
distance : dictionary
- Dictionary, keyed by source and target, of shortest paths.
+ Dictionary, keyed by source and target, of shortest paths.
Examples
--------
@@ -1108,27 +1120,27 @@ def bellman_ford_predecessor_and_distance(
Parameters
----------
G : NetworkX graph
- The algorithm works for all types of graphs, including directed
- graphs and multigraphs.
+ The algorithm works for all types of graphs, including directed
+ graphs and multigraphs.
source: node label
- Starting node for path
+ Starting node for path
target : node label, optional
- Ending node for path
+ Ending node for path
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
heuristic : bool
Determines whether to use a heuristic to early detect negative
@@ -1137,8 +1149,8 @@ def bellman_ford_predecessor_and_distance(
Returns
-------
pred, dist : dictionaries
- Returns two dictionaries keyed by node to predecessor in the
- path and to the distance from the source respectively.
+ Returns two dictionaries keyed by node to predecessor in the
+ path and to the distance from the source respectively.
Raises
------
@@ -1146,10 +1158,10 @@ def bellman_ford_predecessor_and_distance(
If `source` is not in `G`.
NetworkXUnbounded
- If the (di)graph contains a negative cost (di)cycle, the
- algorithm raises an exception to indicate the presence of the
- negative cost (di)cycle. Note: any negative weight edge in an
- undirected graph is a negative cost cycle.
+ If the (di)graph contains a negative cost (di)cycle, the
+ algorithm raises an exception to indicate the presence of the
+ negative cost (di)cycle. Note: any negative weight edge in an
+ undirected graph is a negative cost cycle.
Examples
--------
@@ -1262,10 +1274,10 @@ def _bellman_ford(
If any of `source` is not in `G`.
NetworkXUnbounded
- If the (di)graph contains a negative cost (di)cycle, the
- algorithm raises an exception to indicate the presence of the
- negative cost (di)cycle. Note: any negative weight edge in an
- undirected graph is a negative cost cycle
+ If the (di)graph contains a negative cost (di)cycle, the
+ algorithm raises an exception to indicate the presence of the
+ negative cost (di)cycle. Note: any negative weight edge in an
+ undirected graph is a negative cost cycle
"""
for s in source:
if s not in G:
@@ -1350,18 +1362,18 @@ def bellman_ford_path(G, source, target, weight="weight"):
G : NetworkX graph
source : node
- Starting node
+ Starting node
target : node
- Ending node
+ Ending node
weight: string, optional (default='weight')
- Edge data key corresponding to the edge weight
+ Edge data key corresponding to the edge weight
Returns
-------
path : list
- List of nodes in a shortest path.
+ List of nodes in a shortest path.
Raises
------
@@ -1369,7 +1381,7 @@ def bellman_ford_path(G, source, target, weight="weight"):
If `source` is not in `G`.
NetworkXNoPath
- If no path exists between source and target.
+ If no path exists between source and target.
Examples
--------
@@ -1399,13 +1411,13 @@ def bellman_ford_path_length(G, source, target, weight="weight"):
G : NetworkX graph
source : node label
- starting node for path
+ starting node for path
target : node label
- ending node for path
+ ending node for path
weight: string, optional (default='weight')
- Edge data key corresponding to the edge weight
+ Edge data key corresponding to the edge weight
Returns
-------
@@ -1457,15 +1469,15 @@ def single_source_bellman_ford_path(G, source, weight="weight"):
G : NetworkX graph
source : node
- Starting node for path.
+ Starting node for path.
weight: string, optional (default='weight')
- Edge data key corresponding to the edge weight
+ Edge data key corresponding to the edge weight
Returns
-------
paths : dictionary
- Dictionary of shortest path lengths keyed by target.
+ Dictionary of shortest path lengths keyed by target.
Raises
------
@@ -1502,10 +1514,10 @@ def single_source_bellman_ford_path_length(G, source, weight="weight"):
G : NetworkX graph
source : node label
- Starting node for path
+ Starting node for path
weight: string, optional (default='weight')
- Edge data key corresponding to the edge weight.
+ Edge data key corresponding to the edge weight.
Returns
-------
@@ -1555,33 +1567,33 @@ def single_source_bellman_ford(G, source, target=None, weight="weight"):
G : NetworkX graph
source : node label
- Starting node for path
+ Starting node for path
target : node label, optional
- Ending node for path
+ Ending node for path
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
distance, path : pair of dictionaries, or numeric and list
- If target is None, returns a tuple of two dictionaries keyed by node.
- The first dictionary stores distance from one of the source nodes.
- The second stores the path from one of the sources to that node.
- If target is not None, returns a tuple of (distance, path) where
- distance is the distance from source to target and path is a list
- representing the path from source to target.
+ If target is None, returns a tuple of two dictionaries keyed by node.
+ The first dictionary stores distance from one of the source nodes.
+ The second stores the path from one of the sources to that node.
+ If target is not None, returns a tuple of (distance, path) where
+ distance is the distance from source to target and path is a list
+ representing the path from source to target.
Raises
------
@@ -1644,7 +1656,7 @@ def all_pairs_bellman_ford_path_length(G, weight="weight"):
G : NetworkX graph
weight: string, optional (default='weight')
- Edge data key corresponding to the edge weight
+ Edge data key corresponding to the edge weight
Returns
-------
@@ -1688,12 +1700,12 @@ def all_pairs_bellman_ford_path(G, weight="weight"):
G : NetworkX graph
weight: string, optional (default='weight')
- Edge data key corresponding to the edge weight
+ Edge data key corresponding to the edge weight
Returns
-------
distance : dictionary
- Dictionary, keyed by source and target, of shortest paths.
+ Dictionary, keyed by source and target, of shortest paths.
Examples
--------
@@ -1729,30 +1741,30 @@ def goldberg_radzik(G, source, weight="weight"):
Parameters
----------
G : NetworkX graph
- The algorithm works for all types of graphs, including directed
- graphs and multigraphs.
+ The algorithm works for all types of graphs, including directed
+ graphs and multigraphs.
source: node label
- Starting node for path
+ Starting node for path
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
pred, dist : dictionaries
- Returns two dictionaries keyed by node to predecessor in the
- path and to the distance from the source respectively.
+ Returns two dictionaries keyed by node to predecessor in the
+ path and to the distance from the source respectively.
Raises
------
@@ -1760,10 +1772,10 @@ def goldberg_radzik(G, source, weight="weight"):
If `source` is not in `G`.
NetworkXUnbounded
- If the (di)graph contains a negative cost (di)cycle, the
- algorithm raises an exception to indicate the presence of the
- negative cost (di)cycle. Note: any negative weight edge in an
- undirected graph is a negative cost cycle.
+ If the (di)graph contains a negative cost (di)cycle, the
+ algorithm raises an exception to indicate the presence of the
+ negative cost (di)cycle. Note: any negative weight edge in an
+ undirected graph is a negative cost cycle.
Examples
--------
@@ -1904,17 +1916,17 @@ def negative_edge_cycle(G, weight="weight", heuristic=True):
G : NetworkX graph
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
heuristic : bool
Determines whether to use a heuristic to early detect negative
@@ -1969,29 +1981,29 @@ def bidirectional_dijkstra(G, source, target, weight="weight"):
G : NetworkX graph
source : node
- Starting node.
+ Starting node.
target : node
- Ending node.
+ Ending node.
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
length, path : number and list
- length is the distance from source to target.
- path is a list of nodes on a path from source to target.
+ length is the distance from source to target.
+ path is a list of nodes on a path from source to target.
Raises
------
@@ -2114,27 +2126,27 @@ def johnson(G, weight="weight"):
G : NetworkX graph
weight : string or function
- If this is a string, then edge weights will be accessed via the
- edge attribute with this key (that is, the weight of the edge
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
- such edge attribute exists, the weight of the edge is assumed to
- be one.
-
- If this is a function, the weight of an edge is the value
- returned by the function. The function must accept exactly three
- positional arguments: the two endpoints of an edge and the
- dictionary of edge attributes for that edge. The function must
- return a number.
+ If this is a string, then edge weights will be accessed via the
+ edge attribute with this key (that is, the weight of the edge
+ joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
+ such edge attribute exists, the weight of the edge is assumed to
+ be one.
+
+ If this is a function, the weight of an edge is the value
+ returned by the function. The function must accept exactly three
+ positional arguments: the two endpoints of an edge and the
+ dictionary of edge attributes for that edge. The function must
+ return a number.
Returns
-------
distance : dictionary
- Dictionary, keyed by source and target, of shortest paths.
+ Dictionary, keyed by source and target, of shortest paths.
Raises
------
NetworkXError
- If given graph is not weighted.
+ If given graph is not weighted.
Examples
--------