问题描述
我有如下距离矩阵。我想找到旅行长度最短的排列。
library(GA)
x <- c(0,5,6,4,3,0)
dim(x) <- c(4,4)
x
[,1] [,2] [,3] [,4]
[1,] 0 5 6 4
[2,] 5 0 4 3
[3,] 6 4 0 5
[4,] 4 3 5 0
tourLength <- function(tour,distMatrix) {
route <- embed(tour,2)[,2:1]
sum(distMatrix[route])
}
这是适应度函数。
tspfitness <- function(tour,...) 1/tourLength(tour,...)
GA <- ga(type = "permutation",fitness = tspfitness,distMatrix = x,lower = 1,upper = 4,popSize=50,maxiter=1000,run=100,pmutation=0.2)
如何添加此约束?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)