码迷,mamicode.com
首页 > 其他好文 > 详细

交通巡警调度

时间:2018-07-29 13:11:10      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:marker   pat   ace   path   hold   连线   6.4   rect   定时   

que1

file=‘cmm.xls‘;
AbiaoX=xlsread(file,1,‘B2:B93‘);%A区路口节点标号横坐标
AbiaoY=xlsread(file,1,‘C2:C93‘);%A区路口节点标号纵坐标
Anfalv=xlsread(file,1,‘E2:E93‘);%案发率表格
% plot(AbiaoX,AbioaY,‘g*‘);
S=xlsread(file,2,‘A2:A144‘);%路线起点标号
T=xlsread(file,2,‘B2:B144‘);%路线终点标号

%去除A区以外的点
ex=find(T>92);
S(ex)=[];T(ex)=[];

%画相邻点的连线
figure(1);
x1=[];y1=[];x2=[];y2=[];%起终点坐标
bS=[];bT=[];bW=[];%构造稀疏矩阵需要的起终点标号及权值
for bh=1:140;
%     x1=[x1 AbiaoX(S(bh))];y1=[y1 AbiaoY(S(bh))];
%     x2=[x2 AbiaoX(T(bh))];y2=[y2 AbiaoY(T(bh))];
     x1=AbiaoX(S(bh)); y1=AbiaoY(S(bh));
     x2=AbiaoX(T(bh)); y2=AbiaoY(T(bh));
     bS=[bS S(bh)];bT=[bT T(bh)];
     dis=sqrt((x1-x2)^2+(y1-y2)^2);bW=[bW dis];
     h=plot([x1,x2],[y1,y2],‘b-d‘,‘LineWidth‘,2,‘MarkerSize‘,3);
%      if bh<21%设置交巡警点标号
%          set(h,‘Marker‘,‘o‘,‘MarkerSize‘,8,‘MarkerEdgeColor‘,‘r‘);
%      end
%      if ismember(bh,churuA)
%          set(h,‘Marker‘,‘*‘,MarkerSize‘,6,‘MarkerEdgeColor‘,‘r‘);
%      end
     hold on;
end

%标号交巡警位置
c=‘A‘;tc=[];
for i=1:20
    tc=num2str(i);
    tc=[c tc];
    h=plot([AbiaoX(i)],[AbiaoY(i)]);
    set(h,‘Marker‘,‘o‘,‘MarkerSize‘,8,‘MarkerEdgeColor‘,‘r‘);
    text(AbiaoX(i),AbiaoY(i),tc,‘Color‘,‘m‘,‘horizontalalignment‘,‘left‘);
%     alpha=linspace(0,2*pi);
%     rx=30*cos(alpha)+AbiaoX(i);
%     ry=30*sin(alpha)+AbiaoY(i);
%     plot(rx,ry,‘g.‘,‘LineWidth‘,0.2);
end

for i=21:92
        ttc=num2str(i);
        text(AbiaoX(i),AbiaoY(i),ttc);
end

churuA=[12 14 16 21 22 23 24 28 29 30 38 48 62];%标号出入A区的路口
for i=12:62
    if ismember(i,churuA)
        ttc=num2str(i);
        h=plot([AbiaoX(i)],[AbiaoY(i)]);
        set(h,‘Marker‘,‘*‘,‘MarkerSize‘,7,‘MarkerEdgeColor‘,‘r‘);
    end
end

%求任意A区两点间最短路
DG=sparse(bS,bT,bW,92,92);
UG=tril(DG+DG‘);
[dist]=graphallshortestpaths(UG,‘Directed‘,false);
save afile.txt -ascii dist;
fid=fopen(‘afile.txt‘,‘wt‘); %写入的文件
a=dist;
[m,n]=size(a);
 for i=1:1:m
    for j=1:1:n
       if j==n
         fprintf(fid,‘%g\n‘,a(i,j));
       else
        fprintf(fid,‘%g\t‘,a(i,j));
       end
    end
 end
fclose(fid);


pdist=zeros(20,13);
for i=1:20
    for j=1:13
        pdist(i,j)=dist(i,churuA(j));
    end
end
save bfile.txt -ascii pdist;
fid=fopen(‘bfile.txt‘,‘wt‘); %写入的文件
a=pdist;
[m,n]=size(a);
 for i=1:1:m
    for j=1:1:n
       if j==n
         fprintf(fid,‘%g\n‘,a(i,j));
       else
        fprintf(fid,‘%g\t‘,a(i,j));
       end
    end
 end
fclose(fid);

cango=[];
for i=21:92
    for j=1:20
        if dist(i,j)<30
            cango=[cango i];
            break;
        end
    end
end
ungo=setdiff(21:92,cango);%规定时间不能到达的点


d32=[];
for i=1:92
   if dist(32,i)<=30
       d32=[d32 i];
   end
end


g1=[];g2=[];g3=[];g4=[];g5=[];g6=[];g7=[];g8=[];g9=[];g10=[];
g11=[];g12=[];g13=[];g14=[];g15=[];g16=[];g17=[];g18=[];g19=[];g20=[];

for j=21:90
        if dist(1,j)<30 g1=[g1 j]; end;
end;
for j=21:90
        if dist(2,j)<30 g2=[g2 j]; end;
end;
for j=21:90
        if dist(3,j)<30 g3=[g3 j]; end;
end;
for j=21:90
        if dist(4,j)<30 g4=[g4 j]; end;
end;
for j=21:90
        if dist(5,j)<30 g5=[g5 j]; end;
end;
for j=21:90
        if dist(6,j)<30 g6=[g6 j]; end;
end;
for j=21:90
        if dist(7,j)<30 g7=[g7 j]; end;
end
for j=21:90
        if dist(8,j)<30 g8=[g8 j]; end;
end
for j=21:90
        if dist(9,j)<30 g9=[g9 j]; end;
end
for j=21:90
        if dist(10,j)<30 g10=[g10 j]; end;
end
for j=21:90
        if dist(11,j)<30 g11=[g11 j]; end;
end
for j=21:90
        if dist(12,j)<30 g12=[g12 j]; end;
end
for j=21:90
        if dist(13,j)<30 g13=[g13 j]; end;
end
for j=21:90
        if dist(14,j)<30 g14=[g14 j]; end;
end
for j=21:90
        if dist(15,j)<30 g15=[g15 j]; end;
end
for j=21:90
        if dist(16,j)<30 g16=[g16 j]; end;
end
for j=21:90
        if dist(17,j)<30 g17=[g17 j]; end;
end
for j=21:90
        if dist(18,j)<30 g18=[g18 j]; end;
end
for j=21:90
        if dist(19,j)<30 g19=[g19 j]; end;
end
for j=21:90
        if dist(20,j)<30 g20=[g20 j]; end;
end
            
% l1=Anfalv(1);l2=Anfalv(2);l3=Anfalv(3);l4=Anfalv(4);l5=Anfalv(5);
% l6=Anfalv(6);l7=Anfalv(7);l8=Anfalv(8);l9=Anfalv(9);l10=Anfalv(10);
% l11=Anfalv(11);l12=Anfalv(12);l13=Anfalv(13);l14=Anfalv(14);
% l15=Anfalv(15);l16=Anfalv(16);l17=Anfalv(17);l18=Anfalv(18);
% l19=Anfalv(19);l20=Anfalv(20);
%  
% for i=1:size(g1,2)
%     l1=l1+Anfalv(g1(i));
% end
% for i=1:size(g2,2)
%     l2=l2+Anfalv(g2(i));
% end
% for i=1:size(g3,2)
%     l3=l3+Anfalv(g3(i));
% end
% for i=1:size(g4,2)
%     l4=l4+Anfalv(g4(i));
% end
% for i=1:size(g5,2)
%     l5=l5+Anfalv(g5(i));
% end
% for i=1:size(g6,2)
%     l6=l6+Anfalv(g6(i));
% end
% for i=1:size(g7,2)
%     l7=l7+Anfalv(g7(i));
% end
% for i=1:size(g8,2)
%     l8=l8+Anfalv(g8(i));
% end
% for i=1:size(g9,2)
%     l9=l9+Anfalv(g9(i));
% end
% for i=1:size(g10,2)
%     l10=l10+Anfalv(g10(i));
% end
% for i=1:size(g11,2)
%     l11=l11+Anfalv(g11(i));
% end
% for i=1:size(g12,2)
%     l12=l12+Anfalv(g12(i));
% end
% for i=1:size(g13,2)
%     l13=l13+Anfalv(g13(i));
% end
% for i=1:size(g14,2)
%     l14=l14+Anfalv(g14(i));
% end
% for i=1:size(g15,2)
%     l15=l15+Anfalv(g15(i));
% end
% for i=1:size(g16,2)
%     l16=l16+Anfalv(g16(i));
% end
% for i=1:size(g17,2)
%     l17=l17+Anfalv(g17(i));
% end
% for i=1:size(g18,2)
%     l18=l18+Anfalv(g18(i));
% end
% for i=1:size(g19,2)
%     l19=l19+Anfalv(g19(i));
% end
% for i=1:size(g20,2)
%     l20=l20+Anfalv(g20(i));
% end

%  [l1;l2;l3;l4;l5;l6;l7;l8;l9;l10;l11;l12;l13;l14;l15;l16;l17;l18;l19;l20]
   
Lv=[6.20 7.7  7.6   6.6  7.3 6.3 5.1 7 7.5 2.8 3.4 4 7.1 3.9 6.4 5.2 7.5 8.6 6.1 7.1];

  

交通巡警调度

标签:marker   pat   ace   path   hold   连线   6.4   rect   定时   

原文地址:https://www.cnblogs.com/zxhyxiao/p/9384770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!