两个图的关系组合。
详细信息
compose()
创建两个图的关系组合。新图将仅包含一个 (a,b) 边,如果存在一个顶点 c,使得边 (a,c) 包含在第一个图中,并且 (c,b) 包含在第二个图中。相应的运算符为 %c%
。
如果一个输入图是有向图,而另一个是无向图,则该函数会给出错误。
如果 byname
参数为 TRUE
(或 auto
且所有图都已命名),则该操作基于符号顶点名称执行。否则,使用数字顶点 ID。
compose()
保留两个图的属性。所有图、顶点和边属性都会被复制到结果中。如果一个属性存在于多个图中,并且会导致名称冲突,则该属性会通过添加后缀重命名:_1、_2 等。
如果操作基于符号顶点名称执行,则 name
顶点属性将被特殊处理。在这种情况下,name
必须存在于两个图中,并且不会在结果图中重命名。
请注意,结果图中的一条边对应于输入中的两条边,一条在第一个图中,一条在第二个图中。此映射不是单射的,结果中的多个边可能对应于第一个(和/或第二个)图中的同一条边。结果图中的边属性会相应地更新。
另请注意,如果存在多种方式在 g1 中找到边 (a,b) 并在 g2 中找到边 (b,c) 用于结果中的边 (a,c),则该函数可能会生成多重图。如果您想摆脱多个边,请参阅 simplify()
。
如果 g1 和 g2 中分别存在边 (a,b) 和 (b,a),则该函数可能会创建环边,则 (a,a) 包含在结果中。如果您想摆脱自环,请参阅 simplify()
。
参见
其他用于操作图结构的函数:+.igraph()
、add_edges()
、add_vertices()
、complementer()
、connect()
、contract()
、delete_edges()
、delete_vertices()
、difference()
、difference.igraph()
、disjoint_union()
、edge()
、igraph-minus
、intersection()
、intersection.igraph()
、path()
、permute()
、rep.igraph()
、reverse_edges()
、simplify()
、union()
、union.igraph()
、vertex()
作者
Gabor Csardi csardi.gabor@gmail.com
示例
g1 <- make_ring(10)
g2 <- make_star(10, mode = "undirected")
gc <- compose(g1, g2)
print_all(gc)
#> IGRAPH a56b15e U--- 10 36 --
#> + attr: name_1 (g/c), name_2 (g/c), mutual (g/l), circular (g/l), mode
#> | (g/c), center (g/n)
#> + edges:
#> 1 -- 1 1 1 1 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
#> 2 -- 1 2 2 3 4 5 6 7 8 9 10 10
#> 3 -- 1 1 2 10
#> 4 -- 1 1 2 10
#> 5 -- 1 1 2 10
#> 6 -- 1 1 2 10
#> 7 -- 1 1 2 10
#> 8 -- 1 1 2 10
#> 9 -- 1 1 2 10
#> 10 -- 1 2 2 3 4 5 6 7 8 9 10 10
print_all(simplify(gc))
#> IGRAPH 122ac87 U--- 10 24 --
#> + attr: name_1 (g/c), name_2 (g/c), mutual (g/l), circular (g/l), mode
#> | (g/c), center (g/n)
#> + edges:
#> 1 -- 2 3 4 5 6 7 8 9 10 2 -- 1 3 4 5 6 7 8 9 10
#> 3 -- 1 2 10 4 -- 1 2 10
#> 5 -- 1 2 10 6 -- 1 2 10
#> 7 -- 1 2 10 8 -- 1 2 10
#> 9 -- 1 2 10 10 -- 1 2 3 4 5 6 7 8 9