【发布时间】:2019-09-09 01:16:00
【问题描述】:
假设我有以下成本矩阵,并且我希望从通过最近插入方法的旅行推销员问题的角度来看从节点 20 开始的路径(和总成本)。
ds.ex <- structure(c(0, Inf, Inf, 1.9, 1.7, Inf, 0, 7.3, 7.4, 7.2, Inf,
7.3, 0, 7.7, 7.8, 1.9, 7.4, 7.7, 0, 9.2, 1.7, 7.2, 7.8, 9.2,
0), .Dim = c(5L, 5L), .Dimnames = list(c("2", "13", "14", "17",
"20"), c("2", "13", "14", "17", "20")))
ds.ex
2 13 14 17 20
2 0.0 Inf Inf 1.9 1.7
13 Inf 0.0 7.3 7.4 7.2
14 Inf 7.3 0.0 7.7 7.8
17 1.9 7.4 7.7 0.0 9.2
20 1.7 7.2 7.8 9.2 0.0
我正在使用TSP包解决:
ds.ex.tsp <- as.TSP(ds.ex)
(a <- solve_TSP(ds.ex.tsp, method = "nearest_insertion", start=5))
object of class ‘TOUR’
result of method ‘nearest_insertion’ for 5 cities
tour length: 25.8
我可以从以下位置获取路径吗:
`attr(a, "names")
[1] "20" "2" "17" "14" "13"
?
如果这确实是路径,为什么路径 20-2-17-13-14 不是结果?访问完节点 20、2 和 17 后,成本较小的是 13 而不是 14。
提前致谢!
【问题讨论】:
标签: r traveling-salesman