二、部分源代码

clc;
clear all;
close all;

global Qk ax ay Dik tou beta indA indB

%% Intialization
Nnodes=1;
Emax=1000;
Emin=5;
nk=8;
V=20;
Ra=10+(100-10).*rand(1,nk); % data rate
%% New
T=50; %patrolling cycle time constraint
% v,a---velocity and accelration
%% Charging behavior eqn 1
Ptx=10;
Gtx=3;
Grx=2;
lamda=20e-3;
Lp=0.3;
eta=0.9;
beta=0.2316;

tou= ((Gtx.*Grx.*eta./Lp).*(lamda./4.*pi).^2).*Ptx
% Distance4 bw node and chaerger
d=10; %--- Modified

Prx=@(d)(tou./(d+beta).^2)

Prx(2)
% Tx power of Charger


D=15;
itr=5;
for i1=1:itr

noOfNodes=nk;
figure(1);
axis tight manual
clf;
hAx1 = axes;
hold on;

a=1;
b=nk;
r =floor( a + (b-a).*(rand(2,1)));

while(r(1)==r(2))
r =floor( a + (b-a).*(rand(2,1)));
end
sor =r(1);%source node
des=r(2);%destination node
R =5.5; %node transmission range
a=1;
b=noOfNodes;
%X=floor(a + (b-a).*rand(1,noOfNodes));
%Y=floor(a + (b-a).*rand(1,noOfNodes));
X = 1+(30-1)*rand(1,nk);
Y = 1+(30-1)*rand(1,nk);

X1= 10+(20-10)*rand(1,1);
Y1= 10+(20-5)*rand(1,1);
%
X2= 5+(15-5)*rand(1,1);
Y2= 10+(10-5)*rand(1,1);


%Z =[1 0.1 0.6 0.8 0.6 0 0.1 1 1 1];

%plotting network topology
%i2=1;
for i2 = 1:noOfNodes
plot(X(i2),Y(i2),'o','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','y',...
'MarkerSize',8');
xlabel('X in m')
ylabel('Y in m')
text(X(i2), Y(i2), num2str(i2),'FontSize',10);


%% Destination
plot(X2,Y2,'^','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','r',...
'MarkerSize',14');

hold on

end
axis([0 40 -5 40])
M_max = 14; %// number of cells in vertical direction
N_max = 10; %// number of cells in horizontal direction
trans = 1; %// hexagon orientation (0 or 1)

%// Do the plotting:
hold on

C11={};
C={};

ab=1;
ik=1;
for x=0:7%:2;
ik=x;
for y=0:5

if(mod(ik,2))
x0=3+4.3*x;
y0=3+3*2*y;
hexagon(2,x0,y0);
C11{x+1,y+1}=[x0;y0];
% C{ab}=[x0;y0];
hold on
plot(x0,y0,'ok','MarkerFaceColor','k')

cote=2;
x1=cote*sqrt(2)*[-1 -0.5 0.5 1 0.5 -0.5 -1]+x0;
y1=cote*sqrt(9)*[0 -0.5 -0.5 0 0.5 0.5 0]+y0;


else
x0=3+4.3*x;
y0=3*2*y;
hexagon(2,x0,y0);
C11{x+1,y+1}=[3+4.3*x;3*2*y];

hold on
plot(3+4.3*x,3*2*y,'ok', 'MarkerFaceColor','k')


cote=2;
x1=cote*sqrt(2)*[-1 -0.5 0.5 1 0.5 -0.5 -1]+x0;
y1=cote*sqrt(9)*[0 -0.5 -0.5 0 0.5 0.5 0]+y0;


end
C{ab}=[x0,y0];
%% Inside the polygon or not
[in,on] = inpolygon(X,Y,x1,y1);

Nk(ab)=numel(find(in==1));% set of sensor node
ind=[];
ind=find(in==1);
if(isempty(ind))
Dik{ab}=0;
Qk(ab)=0;
else
Dik{ab}=sqrt((X(ind)-x0).^2 +(Y(ind)-y0).^2 ); % distance froom node i to its cell center
Qk(ab)=1;
end
%Tk --> Time stays of WCV

ab=ab+1;


end
end


% axis([0 30 0 30])
% grid
%% Travelling path Model
k=ab-1;
Z=ones(1,k); %% important
aa=cell2mat(C.');
Xa=aa(:,1);
Ya=aa(:,2);


%% WCV
plot(Xa(1)+2,Ya(1)+2,'o','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',12');
plot(Xa(1),Ya(1),'o','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','k',...
'MarkerSize',14');
xlabel('X in m')
ylabel('Y in m')
hold on
text(Xa(1), Ya(1),'Vechile Stay Room','FontSize',10);

hold on


saveas(gcf,'fileint.fig','fig')
% %% Existing Routing
s=cell2mat(C.');
ax=s(:,1);
ay=s(:,2);

%% Routing

indA=find(Qk==1);
indB=find(Qk~=1);
G=randperm(numel(indA));
path1 = indA(G);

%% OPTIMIZATION
% %% Problem Definition
CostFunction=@(x) Sphere(x); % Cost Function

ik=1;
%cost1=1000;
eff1=inf;

while(ik<=4000)
T1=1000.*rand(1);
T=CostFunction(T1);
eff=(T);
if(eff<=eff1)
eff1=eff;
TT=T1;
end
costh1(ik)=eff1;
costh(ik)=eff;
ik=ik+1;
end

三、运行结果

【路径规划】基于matlab无线充电车辆路径和速度预测【含Matlab源码 1473期】_参考文献

【路径规划】基于matlab无线充电车辆路径和速度预测【含Matlab源码 1473期】_优化算法_02

【路径规划】基于matlab无线充电车辆路径和速度预测【含Matlab源码 1473期】_路径规划_03

【路径规划】基于matlab无线充电车辆路径和速度预测【含Matlab源码 1473期】_优化算法_04