跳到内容

补图包含输入图中不存在的所有边。

用法

complementer(graph, loops = FALSE)

参数

graph

输入图,可以是有向图或无向图。

loops

逻辑常量,是否生成环边。

一个新的图对象。

详细信息

complementer() 创建一个图的补图。只有在原始图中存在的边才会包含在新图中。

complementer() 保留图和顶点属性,但边属性会丢失。

参见

作者

Gabor Csardi csardi.gabor@gmail.com

示例


## Complementer of a ring
g <- make_ring(10)
complementer(g)
#> IGRAPH 7ce8e15 U--- 10 35 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l)
#> + edges from 7ce8e15:
#>  [1] 1-- 9 1-- 8 1-- 7 1-- 6 1-- 5 1-- 4 1-- 3 2--10 2-- 9 2-- 8 2-- 7 2-- 6
#> [13] 2-- 5 2-- 4 3--10 3-- 9 3-- 8 3-- 7 3-- 6 3-- 5 4--10 4-- 9 4-- 8 4-- 7
#> [25] 4-- 6 5--10 5-- 9 5-- 8 5-- 7 6--10 6-- 9 6-- 8 7--10 7-- 9 8--10

## A graph and its complementer give together the full graph
g <- make_ring(10)
gc <- complementer(g)
gu <- union(g, gc)
gu
#> IGRAPH bd5210e U--- 10 45 -- 
#> + attr: name_1 (g/c), name_2 (g/c), mutual_1 (g/l), mutual_2 (g/l),
#> | circular_1 (g/l), circular_2 (g/l)
#> + edges from bd5210e:
#>  [1] 9--10 8--10 8-- 9 7--10 7-- 9 7-- 8 6--10 6-- 9 6-- 8 6-- 7 5--10 5-- 9
#> [13] 5-- 8 5-- 7 5-- 6 4--10 4-- 9 4-- 8 4-- 7 4-- 6 4-- 5 3--10 3-- 9 3-- 8
#> [25] 3-- 7 3-- 6 3-- 5 3-- 4 2--10 2-- 9 2-- 8 2-- 7 2-- 6 2-- 5 2-- 4 2-- 3
#> [37] 1--10 1-- 9 1-- 8 1-- 7 1-- 6 1-- 5 1-- 4 1-- 3 1-- 2
isomorphic(gu, make_full_graph(vcount(g)))
#> [1] TRUE