Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 基于遗传算法的车辆路径选择_R_Optimization_Genetic Algorithm_Heuristics_Simulated Annealing - Fatal编程技术网

R 基于遗传算法的车辆路径选择

R 基于遗传算法的车辆路径选择,r,optimization,genetic-algorithm,heuristics,simulated-annealing,R,Optimization,Genetic Algorithm,Heuristics,Simulated Annealing,我有以下问题: 1辆车收取7个停车收费表的最大利润 每个停车收费表的利润在一个向量中是固定的 profit<-c(0,249,289,381,325,338,216,757) 有人能帮我吗?请也许最好尝试置换而不是二进制类型 我有另一个选择,就是通过模拟退火得到一个解。这是更好的方法吗 请看一看! 谢谢大家 row_names<-c(0,1,2,3,4,5,6,7) col_names<-c(0,1,2,3,4,5,6,7) d_max<-120 #maximum di

我有以下问题:

1辆车收取7个停车收费表的最大利润

每个停车收费表的利润在一个向量中是固定的

profit<-c(0,249,289,381,325,338,216,757)
有人能帮我吗?请也许最好尝试置换而不是二进制类型

我有另一个选择,就是通过模拟退火得到一个解。这是更好的方法吗

请看一看! 谢谢大家

row_names<-c(0,1,2,3,4,5,6,7)
col_names<-c(0,1,2,3,4,5,6,7)
d_max<-120 #maximum distance available for the vehicle

Dist<-matrix(c(0,17,19,50,64,33,57,97,
               + 15,0,2,43,72,20,64,92,
               + 20,2,0,42,74,18,70,89,
               + 53,43,42,0,63,28,67,51,
               + 64,72,74,63,0,76,18,68,
               + 36,20,18,28,74,0,76,79,
               + 57,68,72,70,18,76,0,84,
               + 92,92,92,51,68,80,84,0),nrow=8, byrow=T)
dimnames(Dist)<- list(row_names,col_names)
#Function to calculate tour length 

tourLength <- function(tour, distMatrix) {
  tour <- c(tour, tour[1])
  route <- embed(tour, 2)[,2:1]
  sum(distMatrix[route])<=120    #maximum distance available 
}


#function to maximize
func <- function(tour, ...) profit*tourLength(tour, ...)   

That's my fitness function, I guess isn't appropriated. Any idea? 

GA <- ga(type = "binary", fitness = func, distMatrix = Dist,
         min = 1, max = sqrt(length(Dist)), popSize = 50, maxiter = 5000,
         run = 500, pmutation = 0.2, nBits=8)
summary(GA)
> summary(GA)
    +-----------------------------------+
    |         Genetic Algorithm         |
    +-----------------------------------+

GA settings: 
Type                  =  binary 
Population size       =  50 
Number of generations =  5000 
Elitism               =  2 
Crossover probability =  0.8 
Mutation probability  =  0.2 

GA results: 
Iterations             = 500 
Fitness function value = 0 
Solutions = 
      x1 x2 x3 x4 x5 x6 x7 x8
[1,]   0  1  0  1  0  0  1  0
[2,]   0  1  1  1  0  1  0  0
[3,]   1  0  1  1  0  1  1  0
[4,]   0  1  1  1  0  1  1  1
[5,]   1  1  0  1  0  1  1  0
[6,]   1  0  1  0  1  0  1  0
[7,]   0  1  1  1  1  1  0  1
[8,]   0  0  1  0  1  1  0  1
[9,]   1  1  1  1  0  0  1  1
[10,]  1  0  1  0  1  1  0  1
...                          
[43,]  1  1  1  1  0  0  1  0