1 简介
(VRP)车辆路线问题在物流业中对于节约汽车资源起到了决定性作用,为控制成本起了建设性作用. 遗传算法应用自然界优胜劣汰的规律.运用遗传算法求解车辆路径问题,可以从初始解开始计算,在计算过程中逐渐解出可行解及最优解,并淘汰不可行解.而模拟退火算法的应用,为求解车辆路径问题提供了新的方法,它能有效的防止陷入局部最优的情况.因此本文将遗传算法和模拟退火算法结合,利用各自的优点更快更高效的生成最优解.并在此过程中加入了记忆装置,在解的生成过程中记录下最优解,防止其在进化过程中遗失. 本文是通过遗传算法和模拟退火算法来研究带有时间窗口的车辆路径问题(客户要求将需求的货物在规定的时间窗内送到,也称有时限问题),利用一汽丰田产前物流管理系统提供的数据,运用有记忆的模拟退火遗传算法进行研究和试验,并能很好的产生最优解,达到了预期的效果.
1.1 vrp问题
1.2 模拟退火算法
2 部分代码
clc;
clear;
close all;
T0 = 0.4 ; % initial temperature
r = 0.997 ;%0.997 ; % temperature damping rate
Ts = 0.001 ; % stop temperature
iter = 300;
model = initModel();
% set(gcf,'unit','normalized','position',[0,0.35,1,0.7]);
flag = 0;
% initialization
load ini2.txt
route = ini2;
%route = randomSol(model);
while(1)
if(isFeasible(route,model))
break;
end
mode = randi([1 3]);
route = createNeibor(route,model,mode);
end
cost = calculateCost(route,model);
T = T0;
cnt = 1;
minCost = cost;
minRoute = route;
maxIterate = 2100;
costArray = zeros(maxIterate,1);
% SA
while(T > Ts)
for k = 1:iter
mode = randi([1 3]);
newRoute = createNeibor(route,model,mode);
newCost = calculateCost(newRoute,model);
delta = newCost(4) - cost(4);
if(delta < 0)
cost = newCost;
route = newRoute;
else
p=exp(-delta/T);
if rand() <= p
cost = newCost;
route = newRoute;
end
end
end
costArray(cnt) = cost(4);
if cost(4)<minCost(4)
minCost = cost;
minRoute = route;
flag = 1;
end
T = T*r; % annealing
disp(['Iteration ' num2str(cnt) ': BestCost = ' num2str(minCost) ': CurrentCost = ' num2str(cost) ' T = ' num2str(T)]);
cnt = cnt+1;
% figure(1);
% if(flag == 1)
% plotSolution(minRoute,model);
% flag = 0;
% end
% % figure(2);
% subplot(1,2,2)
% plot(costArray);
% pause(0.0001);
end
plotSolution(minRoute,model);
3 仿真结果
4 参考文献
[1]郎茂祥. 装卸混合车辆路径问题的模拟退火算法研究[J]. 系统工程学报, 2005, 20(005):485-491.
部分理论引用网络文献,若有侵权联系博主删除。
5 MATLAB代码与数据下载地址
见博客主页