all_simple_paths: List all simple paths from one source

View source: R/paths.R

all_simple_pathsR Documentation

List all simple paths from one source

Description

This function lists are simple paths from one source vertex to another vertex or vertices. A path is simple if the vertices it visits are not visited more than once.

Usage

all_simple_paths(
  graph,
  from,
  to = V(graph),
  mode = c("out", "in", "all", "total"),
  cutoff = -1
)

Arguments

graph

The input graph.

from

The source vertex.

to

The target vertex of vertices. Defaults to all vertices.

mode

Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If out then the shortest paths from the vertex, if ⁠in⁠ then to it will be considered. If all, the default, then the corresponding undirected graph will be used, i.e. not directed paths are searched. This argument is ignored for undirected graphs.

cutoff

Maximum length of path that is considered. If negative, paths of all lengths are considered.

Details

Note that potentially there are exponentially many paths between two vertices of a graph, and you may run out of memory when using this function, if your graph is lattice-like.

This function currently ignored multiple and loop edges.

Value

A list of integer vectors, each integer vector is a path from the source vertex to one of the target vertices. A path is given by its vertex ids.

See Also

Other paths: diameter(), distance_table(), eccentricity(), radius()

Examples


g <- make_ring(10)
all_simple_paths(g, 1, 5)
all_simple_paths(g, 1, c(3, 5))


igraph documentation built on Aug. 10, 2023, 9:08 a.m.