igraph中的BFS父属性错误
我正在使用igraph包,我不确定它是否是一个bug,但$father输出有时毫无意义。具体来说,当我重命名顶点属性时igraph中的BFS父属性错误,r,igraph,R,Igraph,我正在使用igraph包,我不确定它是否是一个bug,但$father输出有时毫无意义。具体来说,当我重命名顶点属性时 h<-make_tree(10) #with normal vertex attributes graph.bfs(h, root="1", neimode='out', order=TRUE, father=TRUE,unreachable=FALSE) #father output seems correct plot(h,layout=layout_as_tree
h<-make_tree(10)
#with normal vertex attributes
graph.bfs(h, root="1", neimode='out', order=TRUE, father=TRUE,unreachable=FALSE) #father output seems correct
plot(h,layout=layout_as_tree)
#with renamed vertex attributes
set.seed(1)
h<-set.vertex.attribute(h, "name", value=sample(1:10,10))
plot(h,layout=layout_as_tree)
graph.bfs(h, root="3", neimode='out', order=TRUE, father=TRUE,unreachable=FALSE) #father output seems wrong
我不明白为什么父亲对于重命名顶点属性的情况是错误的。例如,第一个元素应该是NA,但不是NA
有人能解释发生了什么事吗?如果是这样的话,我该如何解决这个问题,使我的父元素反映出与第一种情况类似的东西。这有点奇怪,但出于某种原因,
bfs
函数将顶点名称直接指定给父
向量的名称。请参阅源代码中的54-55行代码:
if (father)
names(res$father) <- V(graph)$name
现在它应该起作用了:
h<-make_tree(10)
set.seed(1)
h<-set_vertex_attr(h, "name", value=sample(1:10,10))
bfs(h, root=1, neimode='out', order=TRUE, rank=TRUE, father=TRUE,unreachable=FALSE)
谢谢你。但是试试这个例子。代码中有一个bug<代码>树这是因为使用
graph\u from\u literal
自动指定顶点名称,这些名称存储为字符。在本例中,root=3
参数调用第三个节点,即节点“6”(V(tree)$name[3]
)。将参数更改为bfs(tree,root='3',neimode=“out”,father=TRUE,order=TRUE,unreachable=FALSE)
。奇怪的是,order
结果和father
结果并不完全匹配。这表明6是2的父亲,而不是4的父亲。可能是个虫子,我同意。我将提交一个github问题。谢谢
> igraph_options()$add.vertex.names
[1] TRUE
> igraph_options(add.vertex.names=F)
> igraph_options()$add.vertex.names
[1] FALSE
h<-make_tree(10)
set.seed(1)
h<-set_vertex_attr(h, "name", value=sample(1:10,10))
bfs(h, root=1, neimode='out', order=TRUE, rank=TRUE, father=TRUE,unreachable=FALSE)
$root
[1] 1
$neimode
[1] "out"
$order
+ 10/10 vertices, named:
[1] 3 4 5 7 2 8 9 6 10 1
$rank
[1] 1 2 3 4 5 6 7 8 9 10
$father
+ 10/10 vertices, named:
[1] <NA> 3 3 4 4 5 5 7 7 2
$pred
NULL
$succ
NULL
$dist
NULL