环边是从顶点到自身的边。如果一条边与另一条边具有完全相同的头顶点和尾顶点,则该边是多重边。没有多重边和环边的图称为简单图。
值
any_loop()
和 any_multiple()
返回一个逻辑标量。which_loop()
和 which_multiple()
返回一个逻辑向量。count_multiple()
返回一个数值向量。
详细信息
any_loop()
决定图中是否有任何环边。
which_loop()
决定图的边是否为环边。
any_multiple()
决定图中是否有任何多重边。
which_multiple()
决定图的边是否为多重边。
count_multiple()
计算图中每条边的重数。
请注意,which_multiple()
和 count_multiple()
的语义不同。which_multiple()
对于多重边的所有出现都给出 TRUE
,但一个除外。也就是说,如果图中有三个 i-j
边,则 which_multiple()
仅对其中两个返回 TRUE
,而 count_multiple()
对所有三个返回 “3”。
请参阅示例,了解如何在保留其原始重数作为边属性的同时消除多重边。
参见
simplify()
删除环边和多重边。
其他 structural.properties:bfs()
, component_distribution()
, connect()
, constraint()
, coreness()
, degree()
, dfs()
, distance_table()
, edge_density()
, feedback_arc_set()
, feedback_vertex_set()
, girth()
, is_acyclic()
, is_dag()
, is_matching()
, k_shortest_paths()
, knn()
, reciprocity()
, subcomponent()
, subgraph()
, topo_sort()
, transitivity()
, unfold_tree()
, which_mutual()
作者
Gabor Csardi csardi.gabor@gmail.com
C 库中的相关文档
is_multiple()
, has_multiple()
, count_multiple()
, is_loop()
, has_loop()
.
示例
# Loops
g <- make_graph(c(1, 1, 2, 2, 3, 3, 4, 5))
any_loop(g)
#> [1] TRUE
which_loop(g)
#> [1] TRUE TRUE TRUE FALSE
# Multiple edges
g <- sample_pa(10, m = 3, algorithm = "bag")
any_multiple(g)
#> [1] TRUE
which_multiple(g)
#> [1] FALSE TRUE TRUE FALSE FALSE TRUE FALSE TRUE TRUE FALSE TRUE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE
#> [25] FALSE FALSE TRUE
count_multiple(g)
#> [1] 3 3 3 1 2 2 3 3 3 2 2 1 1 1 1 1 1 1 2 1 2 1 1 1 2 1 2
which_multiple(simplify(g))
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
all(count_multiple(simplify(g)) == 1)
#> [1] TRUE
# Direction of the edge is important
which_multiple(make_graph(c(1, 2, 2, 1)))
#> [1] FALSE FALSE
which_multiple(make_graph(c(1, 2, 2, 1), dir = FALSE))
#> [1] FALSE TRUE
# Remove multiple edges but keep multiplicity
g <- sample_pa(10, m = 3, algorithm = "bag")
E(g)$weight <- count_multiple(g)
g <- simplify(g, edge.attr.comb = list(weight = "min"))
any(which_multiple(g))
#> [1] FALSE
E(g)$weight
#> [1] 3 2 1 2 1 1 1 1 2 1 1 1 1 1 1 1 3 1 1 1