基于元胞自动机的城市规划

来源:互联网 发布:js 字符串对象转数组 编辑:程序博客网 时间:2024/05/19 15:41
                      元胞自动机-城市规划

1、城市规模设计
雄安新区占地总面积约为2000平方公里,涉及河北省雄县、容城、安新3个县及周边部分区域,地处北京、天津、保定腹地,通过ArcGIS地图软件搜索该区域并从中提取出来,区域图如下所示。
雄安新区区域图
为对雄安新区进行更好的仿真模拟,首先先在地图中截取雄安新区地图,然后进行边缘轮廓提取和白洋淀等不可开发地区的剔除,获得预处理图像。最后用MATlAB进行图像灰度化、二值化处理如下图所示。为后续元胞自动机提供演变地图。
Matlab识别图
城市规划 模型总步骤:
首先确定其组成的主要元素:元胞、元胞空间、元胞状态、元胞邻域及转变规则
分析模拟城市空间结构;
确定模型的参数:繁殖参数、扩散参数、传播参数及受规划约束参数
确定模型所需元胞转换规则的定义
进行城市发展模拟。

2、城市规模仿真模拟
初始阶段:
这里写图片描述
中期阶段
这里写图片描述
远期阶段
这里写图片描述

程序1:  基于MATLAB2014a编程clear;close allI=imread('city.png');level=graythresh(I);   % 图像灰度处理bw=im2bw(I,level);  % 图像二值化处理I=bw;cells=double(I);%定义 buttonplotbutton=uicontrol('style','pushbutton',...'string','Run',...'fontsize',12,...'position',[100,400,50,20],...'callback','run=1;');erasebutton=uicontrol('style','pushbutton',...'string','Stop',...'fontsize',12,...'position',[300,400,50,20],...'callback','freeze=1;');number=uicontrol('style','text',...'string','1',...'fontsize',12,...'position',[20,400,50,20]);%初始化cells(33,44)=2;cells(88,31)=2;cells(33,80)=2;%参数定义kuosan=0.2;fanzhi=0.2;chuanbo=0.2;chengshihua=0.0004;sch=[];skz=[];t=1;[x,y]=size(cells);run=0;freeze=0;stop=0;while (stop==0)    if(run==1)for i=1:x    for j=1:y        if(cells(i,j)~=1)        if(cells(i,j)==0) %自然增长            if(rand<chengshihua)                cells(i,j)=2;            end            if(aroundcenter(i,j,cells))                if(rand<chuanbo)                    cells(i,j)=2;                end            end         end        if(cells(i,j)==2 && rand<kuosan)  %边界增长               if(exist1(i,j,cells))                      m=1+3*rand;                   switch  m                       case 1                          ii=i-1;jj=j;                       case 2                          ii=i;jj=j-1;                       case 3                          ii=i;jj=j+1;                       otherwise 4                           ii=i+1;jj=j;                   end               if(cancity(ii,jj,cells))                     cells(ii,jj)=2;               end               end        end       if(cells(i,j)==2 && exist1(i,j,cells)) %新扩展中心型           if(rand<fanzhi)               if(cancity(i,j,cells))                   cells(i,j)=3;               end           end       end        end    endendch=0;kzch=0;for i=1:x    for j=1:y        if(cells(i,j)==2) ch=ch+1;end        if(cells(i,j)==3) kzch=kzch+1;end    endendsch(t)=ch;skz(t)=kzch;t=t+1;[A,B]=size(cells);Area(1:A,1:B,1)=zeros(A,B);Area(1:A,1:B,2)=zeros(A,B);Area(1:A,1:B,3)=zeros(A,B);for i=1:Afor j=1:Bif cells(i,j)==1Area(i,j,:)=[1,1,1];elseif cells(i,j)==0Area(i,j,:)=[255,255,255];elseif cells(i,j)==3Area(i,j,:)=[255,0,0];elseif cells(i,j)==2Area(i,j,:)=[255,177,0];endendendpause(0.0005);Area=uint8(Area);Area=imagesc(Area);axis equal;axis tight;%计步stepnumber=1+str2num(get(number,'string'));set(number,'string',num2str(stepnumber));    endif freeze==1run=0;freeze=0;enddrawnowend
function a=aroundcenter(i,j,cells)a=0;if(cells(i-1,j)==3)  a=1; endif(cells(i,j-1)==3)  a=1;endif(cells(i,j+1)==3)  a=1;endif(cells(i+1,j)==3)  a=1;endend
function result= exist1(i,j,cells)a=0;if(cells(i-1,j)==2)  a=a+1; endif(cells(i,j-1)==2)  a=a+1;endif(cells(i,j+1)==2)  a=a+1;endif(cells(i+1,j)==2)  a=a+1;endif(a>=2)    result=1;else    result=0;endend
function result=cancity(i,j,cells)s=0if(cells(i-1,j-1)==1)   s=s+1;endif(cells(i-1,j)==1)   s=s+1;endif(cells(i-1,j+1)==1)   s=s+1;endif(cells(i,j-1)==1)   s=s+1;endif(cells(i,j+1)==1)   s=s+1;endif(cells(i+1,j-1)==1)   s=s+1;endif(cells(i+1,j)==1)   s=s+1;endif(cells(i+1,j+1)==1)   s=s+1;endfunction result=cancity(i,j,cells)s=0if(cells(i-1,j-1)==1)   s=s+1;endif(cells(i-1,j)==1)   s=s+1;endif(cells(i-1,j+1)==1)   s=s+1;endif(cells(i,j-1)==1)   s=s+1;endif(cells(i,j+1)==1)   s=s+1;endif(cells(i+1,j-1)==1)   s=s+1;endif(cells(i+1,j)==1)   s=s+1;endif(cells(i+1,j+1)==1)   s=s+1;endif(s>=4)    result=0;else     result=1;endend