1 简介

车辆路径问题(Vehicle Routing Problem, VRP)是物流配送过程中的关键问题之一,随着物流配送行业竞争日益激烈和客户对物流配送时效性要求越来越高,对车辆路径问题的研究,尤其是对带时间窗车辆路径问题(Vehicle Routing Problem With Time Windows, VRPTW)的研究,不仅可以帮助运输企业提高服务水平,为客户提供快捷,准时,安全,舒适的服务,而且有助于企业节约运输成本,提高车辆利用效率,缩短生产周期,加速资金周转,实现资源的合理配置,汲取"第三利润源泉"的财富,因此研究带时间窗车辆路径问题具有重要的现实意义. 本文正是基于以上背景对带时间窗的车辆路径优化问题进行了相关研究.论文从旅行商问题出发,通过分析带时问窗车辆路径优化问题的基本理论,对可用于求解VRPTW的各种优化算法进行了对比,确定了遗传算法作为本文VRPTW求解算法.在此基础上,考虑配送距离,配送及时性以及配送车辆数对配送成本的影响,构建了以配送总成本最小化为目标的带有惩罚函数的VRPTW优化模型,并设计了适合于该模型求解的染色体编码方式以及遗传算子等.最后,应用算例进行了仿真试验,利用MATLAB软件分别计算出基于改进遗传算法和基本遗传算法的最优目标函数值与最优配送路径方案,通过对试验结果的对比分析,验证了本文所建模型及求解算法的合理性和有效性.

【VRP问题】基于模拟退火算法结合遗传算法求解带时间窗仓库拣货小车最优路径规划matlab代码_优化问题

【VRP问题】基于模拟退火算法结合遗传算法求解带时间窗仓库拣货小车最优路径规划matlab代码_优化算法_02

【VRP问题】基于模拟退火算法结合遗传算法求解带时间窗仓库拣货小车最优路径规划matlab代码_优化问题_03

【VRP问题】基于模拟退火算法结合遗传算法求解带时间窗仓库拣货小车最优路径规划matlab代码_优化问题_04

【VRP问题】基于模拟退火算法结合遗传算法求解带时间窗仓库拣货小车最优路径规划matlab代码_优化算法_05

2 部分代码

clear all;

clc;

tic

%%

load D;%数据,包括L长度,最大行数,最大列数,一个小车最大载重量

load time;%加载各个货物的时间范围

load GoodPosition;

load weight;%各个货物的重量;

Good_N = size(Good_P,1); %货物坐标矩阵一维得出货物数量

for i=1:Good_N

    if(mod(Good_P(i,2),2)==0)

        if(Good_P(i,3)>(Good_P(i,2)/2-1)*3+1)

            if(Good_P(i,1)==1)

                Good_P(i,1)=4;

            else Good_P(i,1)=3;

            end

        end

    else

         if(Good_P(i,3)>(Good_P(i,2)-1)/2*3)

            if(Good_P(i,1)==1)

                Good_P(i,1)=4;

            else Good_P(i,1)=3;

            end

        end

    end

end

%% 遗传参数

POP = 100; %种群大小

MAXGEN = 250;%迭代次数

GAP = 0.9;

PC = 0.6;%交叉概率

%PM = 0.9;%变异概率

PM = 0.05;%变异概率

PM_dec = PM/MAXGEN;%变异概率逐渐减小,保证算法收敛

temper = 90;%模拟退火温度

temper_dec =0.99;%温度下降比例

record_length = zeros(MAXGEN,1);

%约束条件及其费用

t = 1.5; %行驶单位距离所用时间s

Cr = 500; %单位小车基本费用角

Cd =0.04; %单位路程油耗角

Cw = 0.02;%单位载重附加油耗角

xlim([0,MAXGEN])

plot(record_length,'r');

title('优化过程')

xlabel('代数')

ylabel('路径长度值')

hold on;

plot(record_mean_length,'b');

hold on;

plot(money_route_length,'k');

legend('每代最短路径','平均路径','每代最优成本路径');

hold off;

figure(2);

xlim([0,MAXGEN])

plot(record_money,'r');

title('优化过程')

xlabel('代数')

ylabel('总成本')

hold on;

plot(record_mean_money,'b');

legend('每代最优成本值','平均成本');

hold off;

display(best_route);

display(best_length);

display(money_route_length(MAXGEN,:));

display(best_money);

toc

figure(3)

sz=100;

R=best_route;

coordinate=Good_P(:,2:3);

coordinate=[10 10;coordinate];

% scatter(coordinate(:,1),coordinate(:,2),50);%客户位置

hold on

n=Good_N;%节点个数

for i=2:n

    plot(coordinate(i,1),coordinate(i,2),'ro','MarkerSize',5,'MarkerEdgeColor','k','MarkerFaceColor','b');

    text(coordinate(i,1)-0.001,coordinate(i,2)+0.005,[num2str(i-1)],'Fontsize',10);hold on

end

hold on

plot(coordinate(1,1),coordinate(1,2),'p','MarkerSize',30,'MarkerEdgeColor','k','MarkerFaceColor','y');hold on%发货中心

ss=0;

for j=1:length(R)-1

    if R(j)==0

        ss=ss+1;

    end

    switch ss

        case 1

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'linewidth',2);hold on%%画出车辆1的路程

        case 2

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color','r','linewidth',2);hold on%%画出车辆2的路程

        case 3

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color','g','linewidth',2);hold on %%画出车辆3的路程

        case 4

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color','k','linewidth',2);hold on %%画出车辆3的路程

        case 5

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color','y','linewidth',2);hold on %%画出车辆3的路程

        case 6

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color','m','linewidth',2);hold on %%画出车辆3的路程

        case 7

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color',[1 0.6 0.3],'linewidth',2);hold on %%画出车辆3的路程

        case 8

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color',[0.5 0.5 0.5],'linewidth',2);hold on %%画出车辆3的路程

        case 9

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color',[0.6 0.4 0.7],'linewidth',2);hold on %%画出车辆3的路程

        case 10

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color',[0.8 0.4 0.7],'linewidth',2);hold on %%画出车辆3的路程

        case 11

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color',[0.6 0.6 0.7],'linewidth',2);hold on %%画出车辆3的路程

        case 12

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color',[0.6 0.4 0.7],'linewidth',2);hold on %%画出车辆3的路程

        otherwise

            line([coordinate(R(j)+1,1),coordinate(R(j+1)+1,1)],[coordinate(R(j)+1,2),coordinate(R(j+1)+1,2)],'Color','c','linewidth',2);hold on %%画出车辆4的路程

    end

end

xlabel('横坐标');

ylabel('纵坐标')

3 仿真结果

【VRP问题】基于模拟退火算法结合遗传算法求解带时间窗仓库拣货小车最优路径规划matlab代码_优化算法_06

【VRP问题】基于模拟退火算法结合遗传算法求解带时间窗仓库拣货小车最优路径规划matlab代码_优化算法_07

4 参考文献

[1]邓爱民, 毛超, and 周彦霆. "带软时间窗的集配货一体化VRP改进模拟退火算法优化研究." 系统工程理论与实践 5(2009):7.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

【VRP问题】基于模拟退火算法结合遗传算法求解带时间窗仓库拣货小车最优路径规划matlab代码_遗传算法_08