distances | R Documentation |
Distances between nodes using breadth-first search (BFS) or Dijkstra's algorithm to find shortest path distances.
bfs_ugraph(A, from = NULL)
count_geodesics(A)
short_path(A, from = NULL, to = NULL)
wlocal_distances(A, select = c("all", "in", "out"), from, to, path = c())
wall_distances(A, select = c("all", "in", "out"))
A |
A symmetric matrix object |
from |
Node in which the path start |
to |
Node in which the path end |
select |
Whether to consider all sender and receiver ties of ego ( |
path |
Path of the nodes |
This function returns the distances o shortest path distance between two nodes for unweighted graph (bfs_ugraph
, count_geodesics
and short_path
respectively) and weighted graphs (wlocal_distances
or wall_distances
)
Alejandro Espinosa-Rada
Dijkstra, E. W. (1959). A note on two problems in connexion with graphs. Numerische Mathematik. 1: 269–271.
A <- matrix(c(
0, 1, 1, 0, 0, 0,
0, 0, 0, 1, 1, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0
), byrow = TRUE, nrow = 6)
rownames(A) <- letters[1:nrow(A)]
colnames(A) <- letters[1:ncol(A)]
bfs_ugraph(A, from = "a")
A <- matrix(c(
0, 1, 1, 0, 0, 0,
0, 0, 0, 1, 1, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0
), byrow = TRUE, nrow = 6)
rownames(A) <- letters[1:nrow(A)]
colnames(A) <- letters[1:ncol(A)]
count_geodesics(A)
A <- matrix(c(
0, 1, 1, 0, 0, 0,
0, 0, 0, 1, 1, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0
), byrow = TRUE, nrow = 6)
rownames(A) <- letters[1:nrow(A)]
colnames(A) <- letters[1:ncol(A)]
short_path(A, from = "a", to = "d")
A <- matrix(
c(
0, 3, 3, 10, 15, 0, 0, 0,
1, 0, 5, 2, 7, 0, 0, 0,
3, 5, 0, 0, 0, 0, 0, 0,
10, 2, 0, 0, 2, 7, 12, 0,
11, 3, 0, 3, 0, 11, 2, 0,
0, 0, 0, 7, 11, 0, 3, 2,
0, 0, 0, 12, 2, 3, 0, 2,
0, 0, 0, 0, 0, 2, 2, 0
),
byrow = TRUE, ncol = 8, nrow = 8
)
rownames(A) <- c("a", "b", "s", "c", "d", "e", "f", "z")
colnames(A) <- rownames(A)
wlocal_distances(A, from = "a", to = "d")
A <- matrix(
c(
0, 3, 3, 10, 15, 0, 0, 0,
1, 0, 5, 2, 7, 0, 0, 0,
3, 5, 0, 0, 0, 0, 0, 0,
10, 2, 0, 0, 2, 7, 12, 0,
11, 3, 0, 3, 0, 11, 2, 0,
0, 0, 0, 7, 11, 0, 3, 2,
0, 0, 0, 12, 2, 3, 0, 2,
0, 0, 0, 0, 0, 2, 2, 0
),
byrow = TRUE, ncol = 8, nrow = 8
)
rownames(A) <- c("a", "b", "s", "c", "d", "e", "f", "z")
colnames(A) <- rownames(A)
wall_distances(A, select = "in")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.