一、VRP简介
1 VRP基本原理 车辆路径规划问题(Vehicle Routing Problem,VRP)是运筹学里重要的研究问题之一。VRP关注有一个供货商与K个销售点的路径规划的情况,可以简述为:对一系列发货点和收货点,组织调用一定的车辆,安排适当的行车路线,使车辆有序地通过它们,在满足指定的约束条件下(例如:货物的需求量与发货量,交发货时间,车辆容量限制,行驶里程限制,行驶时间限制等),力争实现一定的目标(如车辆空驶总里程最短,运输总费用最低,车辆按一定时间到达,使用的车辆数最小等)。 VRP的图例如下所示: 2 问题属性与常见问题 车辆路径问题的特性比较复杂,总的来说包含四个方面的属性: (1)地址特性包括:车场数目、需求类型、作业要求。 (2)车辆特性包括:车辆数量、载重量约束、可运载品种约束、运行路线约束、工作时间约束。 (3)问题的其他特性。 (4)目标函数可能是总成本极小化,或者极小化最大作业成本,或者最大化准时作业。
3 常见问题有以下几类: (1)旅行商问题 (2)带容量约束的车辆路线问题(CVRP) 该模型很难拓展到VRP的其他场景,并且不知道具体车辆的执行路径,因此对其模型继续改进。 (3)带时间窗的车辆路线问题 由于VRP问题的持续发展,考虑需求点对于车辆到达的时间有所要求之下,在车辆途程问题之中加入时窗的限制,便成为带时间窗车辆路径问题(VRP with Time Windows, VRPTW)。带时间窗车辆路径问题(VRPTW)是在VRP上加上了客户的被访问的时间窗约束。在VRPTW问题中,除了行驶成本之外, 成本函数还要包括由于早到某个客户而引起的等待时间和客户需要的服务时间。在VRPTW中,车辆除了要满足VRP问题的限制之外,还必须要满足需求点的时窗限制,而需求点的时窗限制可以分为两种,一种是硬时窗(Hard Time Window),硬时窗要求车辆必须要在时窗内到达,早到必须等待,而迟到则拒收;另一种是软时窗(Soft Time Window),不一定要在时窗内到达,但是在时窗之外到达必须要处罚,以处罚替代等待与拒收是软时窗与硬时窗最大的不同。 模型2(参考2017 A generalized formulation for vehicle routing problems): 该模型为2维决策变量 (4)收集和分发问题 (5)多车场车辆路线问题 参考(2005 lim,多车场车辆路径问题的遗传算法_邹彤, 1996 renaud) 由于车辆是同质的,这里的建模在变量中没有加入车辆的维度。 (6)优先约束车辆路线问题 (7)相容性约束车辆路线问题 (8)随机需求车辆路线问题
4 解决方案 (1)数学解析法 (2)人机交互法 (3)先分组再排路线法 (4)先排路线再分组法 (5)节省或插入法 (6)改善或交换法 (7)数学规划近似法 (8)启发式算法
5 VRP与VRPTW对比
二、遗传算法简介
1 引言 2 遗传算法理论 2.1 遗传算法的生物学基础 2.2 遗传算法的理论基础 2.3 遗传算法的基本概念 2.4 标准的遗传算法 2.5 遗传算法的特点 2.6 遗传算法的改进方向 3 遗传算法流程 4 关键参数说明
三、部分源代码
%遗传算法 VRP 问题 Matlab实现
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;clc;close all;
load location.mat %数据库中的data数组载入,后面可以通过data调用
cost=zeros();
Sup_Parent=[3 6 7 17 18 5 8 16 19 15 26 25 4 27 29 2 9 14 20 28 30 31 13 22 21 24 11 12 23 10 32 1];
G=100;%种群大小
Parent=rand(G,32);%随机父代 30-100均匀分布
for i=1:G %【实际上就是把parent G×30矩阵每行用1~30乱序数填充,每行都是1~30】
[m n]=sort(Parent(i,:)); %parent第i行升序排列后结果存到m,m中元素在parent中的原脚标存到n %初始化数据
Parent(i,:)=n; %把乱序脚标按行存到parent
end
Pc=0.99;%交叉比率
Pm=0.0001;%变异比率
species=[Sup_Parent;Parent];%种群
children=[];%子代
%fitness_value(4070,1)=0;%适应值
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
g=input('迭代次数');
for generation=1:g
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Parent=species;%子代变成父代
children=[];%子代
%选择交叉父代
[n m]=size(Parent);
% select=rand(1,n)<Pc;
% select=find(select==1);
%交叉
for i=1:n
for j=i:n
if i~=j & rand<Pc
jiaocha
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:n
if rand<Pm
parent=Parent(i,:);%变异个体
X=floor(rand*32)+1;
Y=floor(rand*32)+1;
Z=parent(X); %当前个体Parent(i,:)的第X和Y元素交换
parent(X)=parent(Y);
parent(Y)=Z; %变异
children=[children;parent];%变异个体加到种群
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%计算子代适应值
[m n]=size(children);
fitness_value_c=zeros(m,1);%子代适应值
for i=1:m
L1=1;
for L2=1:n
if sum(data(children(i,L1:L2),3))>100 %适应函数;data的第
end
end
end
%计算父代适应值
[m n]=size(Parent);
fitness_value_P=zeros(m,1);%父代适应值
for i=1:m
L1=1;
for L2=1:n
if sum(data(Parent(i,L1:L2),3))>100
fitness_P
L1=L2;
end
if L2==n
L2=L2+1;
fitness_P
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%淘汰子代
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
XX=species(1,:); %最优路线
for i=1:32
YY(i,:)=data(XX(i),:);
end
figure;
plot(YY(:,1),YY(:,2),'bo-');
hold on;
plot(data(1,1),data(1,2),'r*');%中心库
legend('值班点','中心库')
title(['第',num2str(generation),'次迭代,费用最低为',num2str(fitness_value(1))]);
cost(generation)=fitness_value(1);%最优费用
generation
fitness_value(1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
figure;
plot(cost,'b*-');
title('费用优化收敛情况');
path=children(i,L1:L2-1);
L=length(path);
data(path,3);
sum(data(path,3));
for k=1:L
if k==1
fitness_value_c(i)=fitness_value_c(i)+sum(data(path,3))*dis(1,path(1))*3;
else
fitness_value_c(i)=fitness_value_c(i)+sum(data(path(k:L),3))*dis(path(k-
end
fitness_value_c(i)=fitness_value_c(i)+dis(path(L),1)*2;
%OX顺序交叉策略
P1=Parent(i,:);
P2=Parent(j,:);
%选择切点,交换中间部分 并且 修复基因
X=floor(rand*30)+2;
Y=floor(rand*30)+2;
if X<Y
change1=P1(X:Y); %P1X至Y元素存入changge1
change2=P2(X:Y);
%P1(X:Y)=change2;
%P2(X:Y)=change1;
%开始修复 Order Crossover
%1.列出基因
p1=[P1(Y+1:end),P1(1:X-1),change1];
p2=[P2(Y+1:end),P2(1:X-1),change2];
%2.1删除已由基因 P1
for i=1:length(change2)
p1(find(p1==change2(i)))=[]; %交叉删除p1中的change2元素
end
%2.2删除已由基因 P2
for i=1:length(change1)
p2(find(p2==change1(i)))=[]; %交叉删除p2中的change1元素
end
%3.1修复 P1
P1=[p1(32-Y+1:end),change2,p1(1:32-Y)];
%3.1修复 P2
P2=[p2(32-Y+1:end),change1,p2(1:32-Y)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
else
change1=P1(Y:X);
change2=P2(Y:X);
%P1(Y:X)=change2;
p1=[P1(X+1:end),P1(1:Y-1),change1];
p2=[P2(X+1:end),P2(1:Y-1),change2];
%2.1删除已由基因 P1
for i=1:length(change2)
p1(find(p1==change2(i)))=[];
end
%2.2删除已由基因 P2
for i=1:length(change1)
p2(find(p2==change1(i)))=[];
%加入子代
children=[children;P1;P2];
四、运行结果
五、matlab版本及参考文献
1 matlab版本 2014a
2 参考文献 [1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016. [2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
今天的文章【CVRP】基于matlab遗传算法求解带容量的车辆路径规划问题【含Matlab源码 1280期】分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/15832.html