@@ -718,6 +718,29 @@ def shortest_paths(graph: Graph, algorithm: str, source: str, target: str="", **
718
718
(distances[target], predecessors): (float, dict)
719
719
If target is provided and algorithm used is
720
720
'bellman_ford'/'dijkstra'/'A_star'.
721
+
722
+ Examples
723
+ ========
724
+ >>> from pydatastructs import Graph, AdjacencyListGraphNode
725
+ >>> from pydatastructs import shortest_paths
726
+ >>> V1 = AdjacencyListGraphNode("V1")
727
+ >>> V2 = AdjacencyListGraphNode("V2")
728
+ >>> V3 = AdjacencyListGraphNode("V3")
729
+ >>> G = Graph(V1, V2, V3)
730
+ >>> G.add_edge('V2', 'V3', 10)
731
+ >>> G.add_edge('V1', 'V2', 11)
732
+ >>> shortest_paths(G, 'bellman_ford', 'V1')
733
+ ({'V1': 0, 'V2': 11, 'V3': 21}, {'V1': None, 'V2': 'V1', 'V3': 'V2'})
734
+ >>> shortest_paths(G, 'dijkstra', 'V1')
735
+ ({'V2': 11, 'V3': 21, 'V1': 0}, {'V1': None, 'V2': 'V1', 'V3': 'V2'})
736
+ >>> shortest_paths(G, 'A_star', 'V1', 'V3')
737
+ (21, {'V1': None, 'V2': 'V1', 'V3': 'V2'})
738
+
739
+ References
740
+ ==========
741
+ .. [1] https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm
742
+ .. [2] https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
743
+ .. [3] https://en.wikipedia.org/wiki/A*_search_algorithm
721
744
"""
722
745
raise_if_backend_is_not_python (
723
746
shortest_paths , kwargs .get ('backend' , Backend .PYTHON ))
0 commit comments