Skip to content

Shortest paths and components

igraph_ctypes.paths module

Functions related to shortest or widest paths in a graph.

components(graph, mode=Connectedness.WEAK)

Finds the weakly or strongly connected components of a graph.

Parameters:

Name Type Description Default
graph Graph

the graph

required
mode Connectedness

whether the function should return weakly or strongly connected components

WEAK

shortest_path(graph, source, target, mode=NeighborMode.OUT, weights=None, method='dijkstra')

Finds a single shortest path between two vertices in a graph.

Parameters:

Name Type Description Default
graph Graph

the graph

required
source VertexLike

the source vertex

required
target VertexLike

the target vertex

required
mode NeighborMode

TODO

OUT
weights Optional[Iterable[float]]

list of weights for each edge in the graph, or None to treat the edges as unweighted

None
method Literal['auto', 'dijkstra', 'bellman_ford']

the method to use for finding shortest paths when the graph is weighted. May be one of "auto" (pick the best method), "dijkstra" (Dijkstra's algorithm) or "bellman_ford" (Bellman-Ford algorithm).

'dijkstra'

Returns:

Type Description
IntArray

the IDs of the vertices along the shortest path