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

时间:2017-05-30 11:30:46

标签: 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 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)

我一直试图使用通用算法解决它,使用R上的库(GA)。

这是我在其中的一些帖子中构建的其余代码:

#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

有人可以帮助我吗?请!尝试排列而不是二进制类型可能会更好吗?

我通过模拟退火获得解决方案的另一种选择。这是一个更好的方法吗?

请尝试观看! 谢谢大家!

0 个答案:

没有答案