1616__all__ = ("components" , "shortest_path" )
1717
1818
19- def components (graph : Graph , mode : Connectedness = Connectedness .WEAK ):
19+ def components (graph : Graph , mode : Connectedness = Connectedness .WEAK ) -> IntArray :
20+ """Finds the weakly or strongly connected components of a graph.
21+
22+ Args:
23+ graph: the graph
24+ mode: whether the function should return weakly or strongly connected
25+ components
26+ """
2027 membership , _ , _ = connected_components (graph , mode )
2128 return membership
2229
@@ -29,6 +36,22 @@ def shortest_path(
2936 weights : Optional [Iterable [float ]] = None ,
3037 method : str = "dijkstra" ,
3138) -> IntArray :
39+ """Finds a single shortest path between two vertices in a graph.
40+
41+ Args:
42+ graph: the graph
43+ source: the source vertex
44+ target: the target vertex
45+ mode: TODO
46+ weights: list of weights for each edge in the graph, or ``None`` to treat
47+ the edges as unweighted
48+ method: the method to use for finding shortest paths when the graph is
49+ weighted. May be one of `"dijkstra"` (Dijkstra's algorithm) or
50+ `"bellman-ford"` (Bellman-Ford algorithm).
51+
52+ Returns:
53+ the IDs of the vertices along the shortest path
54+ """
3255 # TODO(ntamas): handle epath?
3356 if weights is None :
3457 vpath , _ = get_shortest_path (graph , source , target , mode )
0 commit comments