好日子给大家。
我有一个非常简单的问题,我是不是能够找到一个答案,因为缺乏术语我很害怕。 R中的包的igraph如何考虑的权重? 难道他们认为成本,从而降低了边缘的能力,或者他们确实认为是边缘的能力?
非常感谢你
好日子给大家。
我有一个非常简单的问题,我是不是能够找到一个答案,因为缺乏术语我很害怕。 R中的包的igraph如何考虑的权重? 难道他们认为成本,从而降低了边缘的能力,或者他们确实认为是边缘的能力?
非常感谢你
在的igraph,权重是边缘的属性表示所述摩擦或行驶该边缘在一个PARTH,边缘的不容量或带宽的成本 。 低重量使一个路径和的低重总和 get.shortest.paths()
时不会对加权图禁用权重运行返回具有最低权重求和的路径。
此代码示例示出了具有加权和非加权模式不同的最短路径的曲线图,解释了为什么路径的计算方法不同。
library(igraph)
# Colours for the weighted edges
N <- 22
set.seed(7890123)
# Make a random graph with randomly weighted edges coloured in gray
g <- erdos.renyi.game(N, .2, type="gnp", directed=F, loops=F, weighted=T)
E(g)$weight <- sample(1:40, length(E(g)), replace=T)
#E(g)$weight <- E(g)$weight/10
E(g)$color <- "gray"
V(g)$size <- 4
V(g)$size[c(1,N)] <- 12
# Look how the shortest path is calculated differently when taken the graph weihgt into acocunt
(weighted.path <- unlist(get.shortest.paths(g, 1, N)$vpath) )
(unweighted.path <- unlist(get.shortest.paths(g, 1, N, weights=NA)$vpath) )
# Set weights and colours of shortest paths to visualise them
E(g, path=weighted.path)$color <- "red"
E(g, path=unweighted.path)$color <- "green"
# plot the graph with red shortest weighted path, and green shortest path
same.sahpe <- layout_with_fr(g)
plot(g, vertex.color="white", vertex.label=NA, edge.weight=2, edge.width=(E(g)$weight/5), layout=same.sahpe)
# The two paths look like this. Even though path-length might be longer, a weighted
# shortest path is determined using the sum of path-weights. As with path-lengths, the
# lowest value is the path most easily travelled by. In this case, the weighted alternative
# has a longer path but with lower friction.
data.frame(path.length=c(length(weighted.path),
length(unweighted.path)
),
weight.sum=c(sum(E(g, path=unlist(weighted.path))$weight),
sum(E(g, path=unlist(unweighted.path))$weight)
)
)
看到两个较大的顶点之间的最短路径未加权为4的长度,但行进经过而厚厚地加权绿色边缘。 最短路径加权具有最低权重之和行进多个步骤(5),但在具有更低重量楔导致更低的重量总和,或行驶PARTH,如果你喜欢的成本更低 。
如果你看一下在R的igraph包的官方文档- https://igraph.org/r/doc/strength.html
你会发现,权重被称为:
“权重向量。如果图形具有重量边缘属性,则这是通过默认使用。如果图形不具有重量边缘属性和该参数为NULL,则一个警告,并给出度被称为”。
但是也:
https://igraph.org/r/doc/edge_attr.html
解释说,边缘被给定为一个权重属性