PX=xlsread('longitude.xlsx');
PY=xlsread('latitude.xlsx');
[m,n]=size(PX);
RandomX=randperm(m);
RandomY=randperm(n);
indexX=RandomX(1:1);
indexY=RandomY(1:1);
while 1
if PX(indexX,indexY)~=0
P={PX(indexX,indexY),PY(indexX,indexY)};break;
else
RandomX=randperm(m);
RandomY=randperm(n);
indexX=RandomX(1:1);
indexY=RandomY(1:1);
end
end
P;
%找出所有的轨迹坐标中距离P的距离在1KM范围之内的点
for i=1:1:m
for j=1:1:n
if (abs(P{1}-PX(i,j))<=0.0119161 && abs(P{2}-PY(i,j))<=0.0089932)
PXXX(i,j)=PX(i,j);
PYYY(i,j)=PY(i,j);
else
PXXX(i,j)=0;
PYYY(i,j)=0;
end
end
end
%在随机选出10个坐标作为10个司机的精确位置
Drivers=cell(1,10);
for times=1:1:10
RandomX=randperm(m);
RandomY=randperm(n);
indexX=RandomX(1:1);
indexY=RandomY(1:1);
while 1
if PXXX(indexX,indexY)~=0
D={PXXX(indexX,indexY),PYYY(indexX,indexY)};break;
else
RandomX=randperm(m);
RandomY=randperm(n);
indexX=RandomX(1:1);
indexY=RandomY(1:1);
end
end
Drivers{1,times}=D;
end
Drivers;
%找出所有的轨迹坐标中距离Drivers在3KM范围之内的点
for i=1:1:m
for j=1:1:n
if (abs(P{1}-PX(i,j))<=0.0357483 && abs(P{2}-PY(i,j))<=0.0269796 )
PXXX(i,j)=PX(i,j);
PYYY(i,j)=PY(i,j);
else
PXXX(i,j)=0;
PYYY(i,j)=0;
end
end
end
%在P附近选择N个建筑物作为乘客的上报位置
%1)计算所有坐标与P的距离
N=1000;
POIsX=xlsread('POIX.xlsx');
POIsY=xlsread('POIY.xlsx');
x=PXXX(indexX,indexY);
y=PYYY(indexX,indexY);
[m1,n1]=size(POIsX);
Distance=ones(m1,n1)*nan;
for i=1:1:m1
for j=1:1:n1
if POIsX(i,j)~=0
Distance(i,j)=sqrt((x-POIsX(i,j))^2+(y-POIsY(i,j))^2);
else
Distance(i,j)=0;
end
end
end
Distance;
%2)从Distance中找出距离最小的N个元素
ReportP=[];
for i=1:1:m1
for j=1:1:n1
if Distance(i,j)~=0
ReportP=[ReportP,Distance(i,j)];
end
end
end
ReportP;
ReportP=sort(ReportP);
ReportP=ReportP(1:N);
%3)上报的是距离,将其转换为坐标在矩阵中的位置
LocationP=cell(1,N);
for i=1:1:N
[r,l]=find(Distance==ReportP(i));
LocationP{1,i}=[r(1),l(1)];
end
LocationP;
%在Driver(i)附近选择N个建筑物作为乘客的上报位置
%1)计算所有坐标与Driver(i)的距离,并从Distance中找出距离最小的5O个元素,存在一个10*50的元胞数组中
% POIsX=xlsread('POIX.xlsx');
% POIsY=xlsread('POIY.xlsx');
% [m1,n1]=size(POIsX);
ReportD=ones(10,N)*nan;
LocationD=cell(10,N);
for times=1:1:10
x=Drivers{times}{1};
y=Drivers{times}{2};
Distance1=ones(m1,n1)*nan;
for i=1:1:m1
for j=1:1:n1
if POIsX(i,j)~=0
Distance1(i,j)=sqrt((x-POIsX(i,j))^2+(y-POIsY(i,j))^2);
else
Distance1(i,j)=0;
end
end
end
Distance1;
Min1=[];
for i=1:1:m1
for j=1:1:n1
if Distance1(i,j)~=0
Min1=[Min1,Distance1(i,j)];
end
end
end
Min1;
Min1=sort(Min1);
Min1=Min1(1:N);
ReportD(times,:)=Min1;
ReportD;
for i=1:1:N
[r,l]=find(Distance1==ReportD(times,i));
LocationD{times,i}=[r(1),l(1)];
end
end
LocationD;
tic
for times=1:1:10
sum=0;
for i=1:1:N
for j=1:1:N
if (LocationP{i}(1)==LocationD{times,j}(1)&& LocationP{i}(2)==LocationD{times,j}(2))
sum=sum+1;break;
end
end
end
Asim(times)=sum/(N+N-sum);
end
Asim;
toc