我试图将两个图与相同的节点组合起来,但这样新的图边权重是两个原始图的总和(但当然希望解决方案扩展到 N 个图):
g1 <- graph.empty(directed=FALSE) + vertices(letters[1:2])
g1 <- g1 + edge("a", "b")
E(g1)$weight <- 1
g2 <- graph.empty(directed=FALSE) + vertices(letters[1:2])
g2 <- g2 + edge("a", "b")
E(g2)$weight <- 2
g3 <- g1 %u% g2
E(g3)$weight_1 #this is 1
E(g3)$weight_2 #this is 2
但我希望 E(g3)$weight 为 3。
有没有比之后对边权重 _1, _2, ... 求和更优雅的方法?类似于简化/合同的东西?
只需添加weight_1
and weight_2
。 igraph 目前没有办法组合来自多个图的顶点/边属性,除非手动。这通常不是一个大问题,因为它只是一行额外的代码(每个属性)。好吧,如果你想删除的话,三行_1
, _2
属性。所以你需要做的就是:
E(g3)$weight <- E(g3)$weight_1 + E(g3)$weight_2
并有可能
g3 <- remove.edge.attribute(g3, "weight_1")
g3 <- remove.edge.attribute(g3, "weight_2")
我在 igraph 问题跟踪器中为此创建了一个问题,但不要指望很快就能解决它:https://github.com/igraph/igraph/issues/800 https://github.com/igraph/igraph/issues/800
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)