博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
交通巡警调度
阅读量:6432 次
发布时间:2019-06-23

本文共 10073 字,大约阅读时间需要 33 分钟。

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);endfor i=21:92        ttc=num2str(i);        text(AbiaoX(i),AbiaoY(i),ttc);endchuruA=[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');    endend%求任意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 endfclose(fid);pdist=zeros(20,13);for i=1:20    for j=1:13        pdist(i,j)=dist(i,churuA(j));    endendsave 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 endfclose(fid);cango=[];for i=21:92    for j=1:20        if dist(i,j)<30            cango=[cango i];            break;        end    endendungo=setdiff(21:92,cango);%规定时间不能到达的点d32=[];for i=1:92   if dist(32,i)<=30       d32=[d32 i];   endendg1=[];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;endfor j=21:90        if dist(8,j)<30 g8=[g8 j]; end;endfor j=21:90        if dist(9,j)<30 g9=[g9 j]; end;endfor j=21:90        if dist(10,j)<30 g10=[g10 j]; end;endfor j=21:90        if dist(11,j)<30 g11=[g11 j]; end;endfor j=21:90        if dist(12,j)<30 g12=[g12 j]; end;endfor j=21:90        if dist(13,j)<30 g13=[g13 j]; end;endfor j=21:90        if dist(14,j)<30 g14=[g14 j]; end;endfor j=21:90        if dist(15,j)<30 g15=[g15 j]; end;endfor j=21:90        if dist(16,j)<30 g16=[g16 j]; end;endfor j=21:90        if dist(17,j)<30 g17=[g17 j]; end;endfor j=21:90        if dist(18,j)<30 g18=[g18 j]; end;endfor j=21:90        if dist(19,j)<30 g19=[g19 j]; end;endfor 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];

  graph2_diaodu

file='cmm.xls';AbiaoX=xlsread(file,1,'B2:B93');%A区路口节点标号横坐标AbiaoY=xlsread(file,1,'C2:C93');%A区路口节点标号纵坐标% 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)=[];%画相邻点的连线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',4,'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);endchuruA=[12 14 16 21 22 23 24 28 29 30 28 48 62];%标号出入A区的路口for i=21:92        ttc=num2str(i);        if ismember(i,churuA)            text(AbiaoX(i),AbiaoY(i),ttc,'Color',[1 0 0]);        else             text(AbiaoX(i),AbiaoY(i),ttc);        endendfor i=12:62    if ismember(i,churuA)        ttc=num2str(i);        h=plot([AbiaoX(i)],[AbiaoY(i)]);        set(h,'Marker','*','MarkerSize',10,'MarkerEdgeColor',[1 0 0]);    endend%求任意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 endfclose(fid);cango=[];for i=21:92    for j=1:20        if dist(i,j)<30            cango=[cango i];            break;        end    endendungo=setdiff(21:92,cango);%规定时间不能到达的点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;endfor j=21:90        if dist(8,j)<30 g8=[g8 j]; end;endfor j=21:90        if dist(9,j)<30 g9=[g9 j]; end;endfor j=21:90        if dist(10,j)<30 g10=[g10 j]; end;endfor j=21:90        if dist(11,j)<30 g11=[g11 j]; end;endfor j=21:90        if dist(12,j)<30 g12=[g12 j]; end;endfor j=21:90        if dist(13,j)<30 g13=[g13 j]; end;endfor j=21:90        if dist(14,j)<30 g14=[g14 j]; end;endfor j=21:90        if dist(15,j)<30 g15=[g15 j]; end;endfor j=21:90        if dist(16,j)<30 g16=[g16 j]; end;endfor j=21:90        if dist(17,j)<30 g17=[g17 j]; end;endfor j=21:90        if dist(18,j)<30 g18=[g18 j]; end;endfor j=21:90        if dist(19,j)<30 g19=[g19 j]; end;endfor j=21:90        if dist(20,j)<30 g20=[g20 j]; end;end

 graph3

clc;file='cmm.xls';allX=xlsread(file,1,'B2:B583');%路口节点标号横坐标allY=xlsread(file,1,'C2:C583');%路口节点标号纵坐标allS=xlsread(file,2,'A2:B929');allT=xlsread(file,2,'B2:B929');Jiaoxun=xlsread(file,3,'B2:B81');% allJiao=xlsread(file,3,'A2:A81');figure(2);long=size(allS,1);for i=1:long    px1=allX(allS(i));px2=allX(allT(i));    py1=allY(allS(i));py2=allY(allT(i));    h=plot([px1,px2],[py1,py2],'b-d','LineWidth',2);    hold on;endlong=size(allX,1);for i=1:long    px=allX(i);py=allY(i);    c=num2str(i);    if ismember(i,Jiaoxun)        plot(px,py,'m.','MarkerSize',19);    end    text(px,py,c,'Color','r');endx1=[];y1=[];x2=[];y2=[];%起终点坐标allbS=[];allbT=[];allbW=[];%构造稀疏矩阵需要的起终点标号及权值for bh=1:928;     x1=allX(allS(bh)); y1=allY(allS(bh));     x2=allX(allT(bh)); y2=allY(allT(bh));     allbS=[allbS allS(bh)];allbT=[allbT allT(bh)];     alldis=sqrt((x1-x2)^2+(y1-y2)^2);allbW=[allbW alldis];end%求任意A区两点间最短路DG=sparse(allbS,allbT,allbW,582,582);UG=tril(DG+DG');[distt]=graphallshortestpaths(UG,'Directed',false);dis=distt;

  LINGO程序

model:!求解围堵 13 条要道的方案 ;sets:AA/1..20/;cross/1..13/;links(AA,cross): dis, x;Endsets!数据的定义部分 ;data: dis = @FILE(F:\bfile.txt);enddata!目标函数 ;min=@max(links(i,j):x(i,j)*dis(i,j));!需求约束 ;@for(cross(j):@sum(AA(i): x(i,j))=1);@for(AA(i):@sum(cross(j): x(i,j))<=1);!整数约束 ;@for(links(i,j):@bin(x(i,j)));

  

转载于:https://www.cnblogs.com/zxhyxiao/p/9384770.html

你可能感兴趣的文章
剑指offer 66通关纪念
查看>>
医疗信息化 医学 医院管理 医疗器械 资料下载
查看>>
nginx.conf 示例配置
查看>>
在办公电脑上设置日志服务器监控思科和华为设备
查看>>
python 字符串替换
查看>>
我的友情链接
查看>>
Linux之常用网络命令
查看>>
linux php 安装 curl
查看>>
思科rip、dhcp、vlan
查看>>
tomcat nginx默许的post大小限制
查看>>
OSI七层模型
查看>>
去除工程的.svn隐藏文件夹
查看>>
Python24 终端如何输出彩色字体
查看>>
XSS跨站脚本***
查看>>
linux 挂载光驱
查看>>
ASP.NET MVC Area操作
查看>>
CSS颜色代码大全
查看>>
LINQ之路10:LINQ to SQL 和 Entity Framework(下)
查看>>
circle area
查看>>
怎么改变按钮的图标
查看>>