⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rulegen2.m

📁 一个利用元胞自动机进行生态仿真的matlab程序
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RULEGEN2
% User interface for definition of 2-dimensional CA rules
%
%	Fist Coded			17  April    1997
%	Last Modefied		28 December     1998
%
%	Copyright (c)
%	T. Suzudo JAERI-CAIL
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Read saved rules
load c:\ecody\rule2
rc2save='save c:\ecody\rule2 tr_code225 tr_code229 otr_code225 otr_code229 sym_code225; ';
cleanup='clear tr_hand* title2;';

% Read the stored parameters
load c:\ecody\stepfp
lnei=nei(2); % Number of neighbors
lns=ns(2); % number of cell states
tnr=lnei+1; % Number of Totalistic Rules
otnr=lnei*2; % Number of Outer Totalistic Rules

if tot(2)==3
	if lnei==5
		snr=12;
		if (~(exist('sym_code225')) | snr~=size(sym_code225,2) ) sym_code225=...
                                                                            [0 0 1 0 0 0 0 0 0 0 1 1]; end
	else 
		error('*** No symmetric rules can be used for this neighborhood');
	end
end

if (~(exist('tr_code225')) | tnr~=size(tr_code225,2) ) tr_code225=[0 0 0 1 0 0]; end
if (~(exist('tr_code229')) | tnr~=size(tr_code229,2) ) tr_code229=[0 0 1 0 0 0 0 0 0 0]; end
if (~(exist('otr_code225')) | otnr~=size(otr_code225,2) ) otr_code225=[0 0 0 1 1 0 1 1 0 0]; end
if (~(exist('otr_code229')) | otnr~=size(otr_code229,2) ) otr_code229=...
                                                                            [0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0]; end

figure(11);
fig11=gcf;
clf;

x0=0.1;
y0=0.95;
dx=0.012;
dy=0.05;
wx=0.4;

% Title of UI screen

x=x0;
y=y0;
eval(...
'title2=[''Rule Generator for 2 dimension K='' num2str(lns) '' N='' num2str(lnei)];'...
);
uicontrol(fig11,'Style','text','String',title2,...
		'Fontsize',12,...
		'foregroundcolor','red',...
		'Units','normalized',...
		'position',[0,y,1,dy]);

x=x0+0.6;
y=y0-dy;

%%
%%totalistic rule
%%
if tot(2)==1
   if lnei==5
		tr_hand=zeros(lnei+1,1);
		for ii=1:lnei+1
			x=x0+wx;
			y=y0-ii*dy;
			tr_hand(ii)=uicontrol(fig11,'Style','checkbox',...
				'Units','normalized',...
				'Position',[x y wx dy],...
				'String',['Total ' num2str(ii-1)],... 
				'Value',tr_code225(ii),...
				'CallBack','uprule2');
		end
	distot(tr_code225,lnei);
   elseif lnei==9
	tr_hand=zeros(lnei+1,1);
	for ii=1:lnei+1
		x=x0+wx;
		y=y0-ii*dy;
		tr_hand(ii)=uicontrol(fig11,'Style','checkbox',...
			'Units','normalized',...
			'Position',[x y wx dy],...
			'String',['Total ' num2str(ii-1)],... 
			'Value',tr_code229(ii),...
			'CallBack','uprule2');
	end
	distot(tr_code229,lnei);
   else
      error('ERROR : Invalid number of neighbors');
   end
%%
%% Outer Totalistic Rule
%%
elseif tot(2)==2
	tr_hand=zeros(lnei*2,1);
	if lnei==5
		for ii=1:lnei*2
			x=x0+wx;
			y=y0-ii*dy;
			if ii<lnei+1
				string1=['Home 0 Outer Total ' num2str(ii-1)];
			else
				string1=['Home 1 Outer Total ' num2str(ii-1-lnei)];
			end
			tr_hand(ii)=uicontrol(fig11,'Style','checkbox',...
				'Units','normalized',...
				'Position',[x y wx dy],...
				'String',string1,... 
				'Value',otr_code225(ii),...
				'CallBack','uprule2');
		end
		y=disout(otr_code225,lnei,6*dy);
		mu=calcmu2(otr_code225,tot(2),lnei);
		y=y-dy;
		uicontrol(fig11,'Style','text',...
			'String',['mu-paramter = ' num2str(mu)],...
			'Unit','normalized',...
			'position', [0,y,1,dy]);
	elseif lnei==9
		for ii=1:lnei*2
			x=x0+wx;
			y=y0-ii*dy;
			if ii<lnei+1
				x=x0;
				y=y0-ii*dy;
				string1=['Home 0 Outer Total ' num2str(ii-1)];
			else
				x=x0+wx;
				y=y0-(ii-lnei)*dy;
				string1=['Home 1 Outer Total ' num2str(ii-1-lnei)];
			end
			tr_hand(ii)=uicontrol(fig11,'Style','checkbox',...
				'Units','normalized',...
				'Position',[x y wx dy],...
				'String',string1,... 
				'Value',otr_code229(ii),...
				'CallBack','uprule2');
		end
		y=disout(otr_code229,lnei,4*dy);
	end
%%
%% symmetic rule
%%
elseif tot(2)==3
	if lnei==5
		tr_hand=zeros(12,1);
		for ii=1:12
			x=x0;
			y=y0-ii*dy;
			if ii==1 		string1=['Home 0 Outer Total ' num2str(ii-1)];
			elseif ii==2 	string1=['Home 0 Outer Total ' num2str(ii-1)];
			elseif ii==3 	string1=['Home 0 Outer Total ' num2str(ii-1) ' Neighboring'];
			elseif ii==4 	string1=['Home 0 Outer Total ' num2str(ii-2) ' Diagonal'];
			elseif ii==5 	string1=['Home 0 Outer Total ' num2str(ii-2)];
			elseif ii==6 	string1=['Home 0 Outer Total ' num2str(ii-2)];
			elseif ii==7 	string1=['Home 1 Outer Total ' num2str(ii-7)];
			elseif ii==8 	string1=['Home 1 Outer Total ' num2str(ii-7)];
			elseif ii==9 	string1=['Home 1 Outer Total ' num2str(ii-7) ' Neighboring'];
			elseif ii==10 string1=['Home 1 Outer Total ' num2str(ii-8) ' Diagonal'];
			elseif ii==11 string1=['Home 1 Outer Total ' num2str(ii-8)];
			elseif ii==12 string1=['Home 1 Outer Total ' num2str(ii-8)];
			end
			tr_hand(ii)=uicontrol(fig11,'Style','checkbox',...
				'Units','normalized',...
				'Position',[x y wx dy],...
				'String',string1,... 
				'Value',sym_code225(ii),...
				'CallBack','uprule2');
		end
		y=dissym(sym_code225,lnei);
		mu=calcmu2(sym_code225,tot(2),lnei);
		y=y-dy;
		uicontrol(fig11,'Style','text',...
			'String',['mu-paramter = ' num2str(mu)],...
			'Unit','normalized',...
			'position', [0,y,1,dy]);
	else
		error('ERROR : Invalid number of neighbors');	
	end
end

% Determination of the parameters
%
x=0.1;
y=dy;
uicontrol(fig11,'Style','push',...
		'Units','normalized',...
		'Position',[x y 0.15 dy],...
		'String','OK',...
		'CallBack',[rc2save 'close(fig11);' cleanup] );
uicontrol(fig11,'Style','push',...
		'Units','normalized',...
		'Position',[x+1/3 y 0.15 dy],...
		'String','Apply',...
		'CallBack',[rc2save 'close(fig11);' cleanup 'rulegen2;']);
uicontrol(fig11,'Style','push',...
		'Units','normalized',...
		'Position',[x+2/3 y 0.15 dy],...
		'String','RUN',...
		'CallBack',[rc2save 'close(fig11);' cleanup 'figure(1); runeco2;'] );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -