Rivers分享 http://blog.sciencenet.cn/u/sdssxwfd

博文

元胞自动机之退火规则

已有 2249 次阅读 2021-11-25 08:55 |系统分类:教学心得

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

%元胞自动机退火规则(参见《物理系统的元胞自动机模拟》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://blog.sciencenet.cn/blog-216525-1313806.html

上一篇:[转载]python 合并多个EXCEL文件
下一篇:基于Python的数学专业题库(tex版)选择系统
收藏 IP: 61.179.124.*| 热度|

1 王安良

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-9 10:39

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部