在Modeling Cellular automata Simulations with mathematica一书中,作者使用以下代码在二维晶格中模拟元胞自动机,
来自摩尔邻里的更新规则是
update[site, N, E, S, W, NE, SE, SW, NW]
其中N =北,E=东,S=南,W=西,NE=东北,SE=东南,SW=东南,NW=西北。这些参数代表了 Moor 社区中最近邻居的值。为了应用这些规则,它使用下面的代码,
Moore[func_, lat_]:= MapThread[func,Map[RotateRight[lat,#]&,
{{0,0},{1,0},{0,-1},{-1,0},{0,1},
{1,-1},{-1,-1},{-1,1},{1,1}}],2]
对于如下表(本书第 144 页)
pasture= Table[Floor[Random[]+(preyDensity+predDensity)]*
Floor[1+Random[]+predDensity/(preyDensity+predDensity)],{n},{n}]/.
2:>{RND,Random[Integer, {1,3}],Random[Integer,{1,5}]}
RND:= Random[Integer, {1,4}]
他正在使用以下更新规则
update[{_,0,0},_,_,_,_,_,_,_,_] := {RND, 3,5}
我的问题是:通过使用如下的四维表?我还可以应用以下更新规则吗?
InitialMatrix[x_, y_, age_, disease_] :=
ReplacePart[
Table[3, {x}, {y}, {age}, {disease}], {{_, _, 1, _} ->
0, {_, _, 2, 1} ->
Floor[dogpopulation*0.2/cellsno], {_, _, 2, 3} ->
Floor[dogpopulation*0.05/cellsno], {_, _, 3, 1} ->
Floor[dogpopulation*0.58/cellsno], {_, _, 3, 3} ->
Floor[dogpopulation*0.15/cellsno]}] /.
3 :> If[RandomReal[] > 0.2, 0, RandomInteger[{1, 2}]];
update[{{x_,0,0},{y_,z_,w_},{a_,b_,c_}},_,_,_,_,_,_,_,_] :=
{{x-1,0,0},{y+z,0,w},{a,b,c}}
这是我认为我可以如何使用我的表来处理元胞自动机的一个例子。我可以做这样的事情吗?还是我错了?
编辑我的表格
通过将我的表格更改为下面的代码,我可以使用上面的更新规则吗?
MyMatrix[x_, y_, age_, disease_] :=
Table[0, {x}, {y}] /.
0 :> ReplacePart[
Table[3, {age}, {disease}], {{1, _} -> 0, {2, 1} ->
Floor[dogpopulation*0.2/cellsno], {2, 3} ->
Floor[dogpopulation*0.05/cellsno], {3, 1} ->
Floor[dogpopulation*0.58/cellsno], {3, 3} ->
Floor[dogpopulation*0.15/cellsno]}] /.
3 :> If[RandomReal[] > 0.2, 0, RandomInteger[{1, 2}]];