_bellman_ford(G, source, weight, pred=None, paths=None, dist=None, target=None, heuristic=True)
This is an implementation of the SPFA variant. See https://en.wikipedia.org/wiki/Shortest_Path_Faster_Algorithm
List of source nodes. The shortest path from any of the source nodes will be found if multiple sources are provided.
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.
dict to store a list of predecessors keyed by that node If None, predecessors are not stored
dict to store the path list from source to each node, keyed by node If None, paths are not stored
dict to store distance from source to the keyed node If None, returned dist dict contents default to 0 for every node in the source list
Ending node for path. Path lengths to other destinations may (and probably will) be incorrect.
Determines whether to use a heuristic to early detect negative cycles at a hopefully negligible cost.
If any of :None:None:`source`
is not in G
.
If the (di)graph contains a negative (di)cycle, the algorithm raises an exception to indicate the presence of the negative (di)cycle. Note: any negative weight edge in an undirected graph is a negative cycle
Returns a dict keyed by node to the distance from the source. Dicts for paths and pred are in the mutated input dicts by those names.
Calls relaxation loop for Bellman–Ford algorithm and builds paths
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