徐伟
元胞自动机之退火规则
2021-11-25 08:55
阅读:2274

本规则是元胞自动机的退火规则,不是智能算法中的模拟退火法。

%元胞自动机退火规则(参见《物理系统的元胞自动机模拟》P28)

clear;clc;close all

n=200;

p=0.5;

P=rand(n)>p;

P0=zeros(n+2);

imh=imshow(1-P);

ti=title('迭代次数:','Fontsize',14,'Fontname','Times New Roman');

for t=1:n*2

    P0(2:end-1,2:end-1)=P;

    for i=2:n+1

        for j=2:n+1

            Sum(i,j)=P0(i-1,j-1)+P0(i-1,j+1)+P0(i-1,j)...

                +P0(i,j-1)+P0(i,j)+P0(i,j+1)...

                +P0(i+1,j-1)+P0(i+1,j)+P0(i+1,j+1);

            switch Sum(i,j)

                case {4,6,7,8,9}

                    P(i-1,j-1)=1;

                otherwise

                    P(i-1,j-1)=0;

            end

        end

    end

    set(imh,'cdata',1-P)

    set(ti,'String',['迭代次数:',num2str(t)]);

    drawnow

    pause(0.01)

    if t==1

        A=P;

    elseif t==72

        B=P;

    elseif t==270

        C=P;

    end

end

figure

subplot(131)

imshow(1-A)

title('初始构形')

subplot(132)

imshow(1-B)

title('t=72')

subplot(133)

imshow(1-C)

title('t=270')


转载本文请联系原作者获取授权,同时请注明本文来自徐伟科学网博客。

链接地址:https://wap.sciencenet.cn/blog-216525-1313806.html?mobile=1

收藏

分享到:

当前推荐数:1
推荐人:
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?