急求matlab车辆调度遗传算法代码,需求车辆行驶最优路径。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了急求matlab车辆调度遗传算法代码,需求车辆行驶最优路径。相关的知识,希望对你有一定的参考价值。
车辆行驶的距离最短,车辆从配送中心出发最终回到配送中心
参考技术A function [path,lmin]=ga(data,d) %data为点集,d为距离矩阵,即赋权图tic
%======================
sj0=data;%开环最短路线
%=================================
% sj0=[data;data(1,:)]; %闭环最短路线
%=========================
x=sj0(:,1);y=sj0(:,2);
N=length(x);
%=========================
% d(N,:)=d(1,:);%闭环最短路线
% d(:,N)=d(:,1);%距离矩阵d
%======================
L=N; %sj0的长度
w=800;dai=1000;
%通过改良圈算法选取优良父代A
for k=1:w
c=randperm(L-2);
c1=[1,c+1,L];
flag=1;
while flag>0
flag=0;
for m=1:L-3
for n=m+2:L-1
if d(c1(m),c1(n))+d(c1(m+1),c1(n+1))<d(c1(m),c1(m+1))+d(c1(n),c1(n+1))
flag=1;
c1(m+1:n)=c1(n:-1:m+1);
<a href="https://www.baidu.com/s?wd=end&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">end</a>
<a href="https://www.baidu.com/s?wd=end&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">end</a>
<a href="https://www.baidu.com/s?wd=end&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">end</a>
end
J(k,c1)=1:L;
end
J=J/L;
J(:,1)=0;J(:,L)=1;
rand('state',sum(clock));
%遗传算法实现过程
A=J;
for k=1:dai %产生0~1 间随机数列进行编码
B=A;
c=randperm(w);
%交配产生子代B
for i=1:2:w
F=2+floor(100*rand(1));
temp=B(c(i),F:L);
B(c(i),F:L)=B(c(i+1),F:L);
B(c(i+1),F:L)=temp;
end;
%变异产生子代C
by=find(rand(1,w)<0.1);
if length(by)==0
by=floor(w*rand(1))+1;
end
C=A(by,:);
L3=length(by);
for j=1:L3
<a href="https://www.baidu.com/s?wd=bw&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">bw</a>=floor(1+fix(rand(1,3)*N)); %产生1-N的3个随机数
<a href="https://www.baidu.com/s?wd=bw&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">bw</a>=sort(<a href="https://www.baidu.com/s?wd=bw&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">bw</a>);
C(j,:)=C(j,[1:bw(1)-1,bw(2)+1:bw(3),bw(1):bw(2),bw(3)+1:L]);
end
G=[A;B;C];
<a href="https://www.baidu.com/s?wd=TL&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">TL</a>=size(G,1);
%在父代和子代中选择优良品种作为新的父代
[<a href="https://www.baidu.com/s?wd=dd&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">dd</a>,IX]=sort(G,2);
temp=[];
temp(1:<a href="https://www.baidu.com/s?wd=TL&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">TL</a>)=0;
for j=1:<a href="https://www.baidu.com/s?wd=TL&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">TL</a>
for i=1:L-1
temp(j)=temp(j)+d(IX(j,i),IX(j,i+1));
end
end
[DZ,IZ]=sort(temp);
A=G(IZ(1:w),:);
end
path=IX(IZ(1),:)
% for i=1:length(path)
% path(i)=path(i)-1;
% end
% path=path(2:end-1);
lmin=0;l=0;
for j=1:(length(path)-1)
<a href="https://www.baidu.com/s?wd=t1&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">t1</a>=path(j);t2=path(j+1);
l=d(<a href="https://www.baidu.com/s?wd=t1&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3PvF-rjf1rj6LryD3Pjm30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnHmvrHcYnWTYnjn4rHb3Ps" target="_blank" class="baidu-highlight">t1</a>,t2);
lmin=lmin+l;
end
xx=sj0(path,1);yy=sj0(path,2);
plot(xx,yy,'r-o');
axis equal
toc 参考技术B 这个要具体的问题才好设计,你的太泛
MDVRP基于matlab遗传算法求解多仓库车辆路径规划问题含Matlab源码 1481期
一、VRP简介
1 VRP基本原理
车辆路径规划问题(Vehicle Routing Problem,VRP)是运筹学里重要的研究问题之一。VRP关注有一个供货商与K个销售点的路径规划的情况,可以简述为:对一系列发货点和收货点,组织调用一定的车辆,安排适当的行车路线,使车辆有序地通过它们,在满足指定的约束条件下(例如:货物的需求量与发货量,交发货时间,车辆容量限制,行驶里程限制,行驶时间限制等),力争实现一定的目标(如车辆空驶总里程最短,运输总费用最低,车辆按一定时间到达,使用的车辆数最小等)。
VRP的图例如下所示:
2 问题属性与常见问题
车辆路径问题的特性比较复杂,总的来说包含四个方面的属性:
(1)地址特性包括:车场数目、需求类型、作业要求。
(2)车辆特性包括:车辆数量、载重量约束、可运载品种约束、运行路线约束、工作时间约束。
(3)问题的其他特性。
(4)目标函数可能是总成本极小化
以上是关于急求matlab车辆调度遗传算法代码,需求车辆行驶最优路径。的主要内容,如果未能解决你的问题,请参考以下文章
MDVRP基于matlab遗传算法求解多仓库车辆路径规划问题含Matlab源码 1481期
MDVRP基于matlab遗传算法求解多仓库车辆路径规划问题含Matlab源码 1481期
CVRP基于matlab遗传算法求解带容量的车辆路径规划问题含Matlab源码 1280期
SDPVRP基于matlab遗传算法求解同时取送货的车辆路径问题含Matlab源码 1487期