A random walk is a traversal of the graph starting from a node and going a number of steps by picking an edge at random (potentially weighted). random_walk() can be called both when nodes and edges are active and will adapt to return a value fitting to the currently active part. As the walk order cannot be directly encoded in the graph the return value is a list giving a vector of positions along the walk of each node or edge.

random_walk_rank(n, root = NULL, mode = "out", weights = NULL)

## Arguments

n

The number of steps to perform. If the walk gets stuck before reaching this number the walk is terminated

root

The node to start the walk at. If NULL a random node will be used

mode

How edges are followed in the search if the graph is directed. "out" only follows outbound edges, "in" only follows inbound edges, and "all" or "total" follows all edges. This is ignored for undirected graphs.

weights

The weights to use for edges when selecting the next step of the walk. Currently only used when edges are active

## Value

A list with an integer vector for each node or edge (depending on what is active) each element encode the time the node/edge is encountered along the walk

## Examples

graph <- create_notable("zachary")

# Random walk returning node order
graph |>
mutate(walk_rank = random_walk_rank(200))
#> # A tbl_graph: 34 nodes and 78 edges
#> #
#> # An undirected simple graph with 1 component
#> #
#> # Node Data: 34 × 1 (active)
#>    walk_rank
#>    <list>
#>  1 <int [26]>
#>  2 <int [9]>
#>  3 <int [15]>
#>  4 <int [7]>
#>  5 <int [3]>
#>  6 <int [8]>
#>  7 <int [5]>
#>  8 <int [3]>
#>  9 <int [6]>
#> 10 <int [4]>
#> # ℹ 24 more rows
#> #
#> # Edge Data: 78 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     1     3
#> 3     1     4
#> # ℹ 75 more rows

graph |>
activate(edges) |>
mutate(walk_rank = random_walk_rank(200))
#> # A tbl_graph: 34 nodes and 78 edges
#> #
#> # An undirected simple graph with 1 component
#> #
#> # Edge Data: 78 × 3 (active)
#>     from    to walk_rank
#>    <int> <int> <list>
#>  1     1     2 <int [1]>
#>  2     1     3 <int [0]>
#>  3     1     4 <int [2]>
#>  4     1     5 <int [0]>
#>  5     1     6 <int [0]>
#>  6     1     7 <int [3]>
#>  7     1     8 <int [6]>
#>  8     1     9 <int [1]>
#>  9     1    11 <int [1]>
#> 10     1    12 <int [2]>
#> # ℹ 68 more rows
#> #
#> # Node Data: 34 × 0