图的直径是最长测地线的长度。
用法
diameter(graph, directed = TRUE, unconnected = TRUE, weights = NULL)
get_diameter(graph, directed = TRUE, unconnected = TRUE, weights = NULL)
farthest_vertices(graph, directed = TRUE, unconnected = TRUE, weights = NULL)
值
diameter()
的数值常量,get_diameter()
的数值向量。 farthest_vertices()
返回一个包含两个条目的列表
vertices
两个最远的顶点。
distance
它们的距离。
详细信息
直径是通过使用类似广度优先搜索的方法计算的。
get_diameter()
返回具有实际直径的路径。 如果存在多个直径长度的最短路径,则它返回找到的第一个。
farthest_vertices()
返回两个顶点 ID,即由直径路径连接的顶点。
参见
其他路径: all_simple_paths()
, distance_table()
, eccentricity()
, graph_center()
, radius()
作者
Gabor Csardi csardi.gabor@gmail.com
示例
g <- make_ring(10)
g2 <- delete_edges(g, c(1, 2, 1, 10))
diameter(g2, unconnected = TRUE)
#> [1] 7
diameter(g2, unconnected = FALSE)
#> [1] Inf
## Weighted diameter
set.seed(1)
g <- make_ring(10)
E(g)$weight <- sample(seq_len(ecount(g)))
diameter(g)
#> [1] 27
get_diameter(g)
#> + 5/10 vertices, from 11464ae:
#> [1] 1 10 9 8 7
diameter(g, weights = NA)
#> [1] 5
get_diameter(g, weights = NA)
#> + 6/10 vertices, from 11464ae:
#> [1] 1 2 3 4 5 6