约束条件:
%%遗传算法求解vrp问题(为选择操作从新设计后程序)
%D是距离矩阵,n为种群个数
%C为停止代数,遗传到第 C代时程序停止,C的具体取值视问题的规模和耗费的时间而定
%交叉概率Pc,变异概率Pm
%R为最短路径,Rlength为路径长度
function VRP
volume_shangyuan=30; %一架飞机对伤员的载量约束
volume_wuzi=200; %一架飞机对物资的载量约束
sudu_feiji=200; %一架飞机的速度
base_num1=5; %各个仓库的飞机数量
base_num2=5;
base_num3=5;
n=100; %个体数
C=100; %迭代次数
Pc=0.8;
Pm=0.3;
%主程序入口
tab=2 ; %tab=1,则程序跑的是所有点
%tab=2,则程序跑的是有缺失的点
if tab==1
%初始化
load('h.mat');
demand_shangyuan(1,:)=a(:,4);
demand_wuzi(1,:)=a(:,6);
zuobiao(1,:)=a(:,2);zuobiao(2,:)=a(:,3);
timewindow(1,:)=a(:,8);timewindow(2,:)=a(:,9);
D = linjiejuzhen( zuobiao );
[N,NN]=size(D);
%初始化点的出发仓库和回归仓库
for i=1:N;
dis(1,i)=sqrt((zuobiao(1,i)-22)^2+(zuobiao(2,i)-75)^2);
dis(2,i)=sqrt((zuobiao(1,i)-75.8)^2+(zuobiao(2,i)-80.1)^2);
dis(3,i)=sqrt((zuobiao(1,i)-53.4)^2+(zuobiao(2,i)-59.9)^2);
if (dis(1,i)<=dis(2,i))
if (dis(1,i)<=dis(3,i))
dis(4,i)=1;
else
dis(4,i)=3;
end
else
if (dis(2,i)<=dis(3,i))
dis(4,i)=2;
else
dis(4,i)=3;
end
end
end
clear i;
[R,minlen]=geneticVRP(D,dis,timewindow,demand_shangyuan,demand_wuzi,volume_shangyuan,volume_wuzi,sudu_feiji,base_num1,base_num2,base_num3,n,C,Pc,Pm,zuobiao);%运算返回最优路径R和其总距离Rlength
else
%初始化
delete=[49 34 9 10 58];%要删除的点
delete=sort(delete,'descend');
[M,MM]=size(delete);
load('h.mat');
demand_shangyuan(1,:)=a(:,4);
demand_wuzi(1,:)=a(:,6);
zuobiao(1,:)=a(:,2);zuobiao(2,:)=a(:,3);
timewindow(1,:)=a(:,8);timewindow(2,:)=a(:,9);
xiba=0;
for i=1:MM
xiba=xiba+demand_shangyuan(1,delete(i))+demand_wuzi(1,delete(i));
end
[B,BB]=size(demand_shangyuan);
old=(1:BB);
for new=1:MM
old(delete(new))=[];
demand_shangyuan(delete(new))=[ ];
demand_wuzi(delete(new))=[];
zuobiao(:,delete(new))=[];
timewindow(:,delete(new))=[];
end
D = linjiejuzhen( zuobiao );
[N,NN]=size(D);
%初始化点的出发仓库和回归仓库
for i=1:N;
dis(1,i)=sqrt((zuobiao(1,i)-22)^2+(zuobiao(2,i)-75)^2);
dis(2,i)=sqrt((zuobiao(1,i)-75.8)^2+(zuobiao(2,i)-80.1)^2);
dis(3,i)=sqrt((zuobiao(1,i)-53.4)^2+(zuobiao(2,i)-59.9)^2);
if (dis(1,i)<=dis(2,i))
if (dis(1,i)<=dis(3,i))
dis(4,i)=1;
else
dis(4,i)=3;
end
else
if (dis(2,i)<=dis(3,i))
dis(4,i)=2;
else
dis(4,i)=3;
end
end
end
clear i;
[R,minlen]=geneticVRP_delete(old,xiba,D,dis,timewindow,demand_shangyuan,demand_wuzi,volume_shangyuan,volume_wuzi,sudu_feiji,base_num1,base_num2,base_num3,n,C,Pc,Pm,zuobiao);%运算返回最优路径R和其总距离Rlength
end
【模式识别】Matlab指纹识别
【优化求解】A*算法解决三维路径规划问题
【优化求解】模拟退火遗传实现带时间窗的车辆路径规划问题
【数学建模】Matlab实现SEIR模型
【优化求解】基于NSGA-2的求解多目标柔性车间调度算法
【优化求解】蚁群算法求最优值
【图像处理】粒子群算法结合模糊聚类分割算法实现图像的分割
【优化算法】基于粒子群算法的充电站最优布局
【优化求解】粒子群算法之电线布局优化
【优化求解】遗传算法解决背包问题
【优化求解】采用遗传算法编制多物流中心的开放式车辆路径问题Matlab程序
完整代码添加QQ1575304183