-1

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}]];
4

2 回答 2

1

Modeling Cellular automata Simulations with mathematica 这本书写于 15 多年前,因此建议查看 Mathematica 中的 CellularAutomaton[] 函数。

函数 CellularAutomaton[] 有点复杂,但如果你想做 2D Moore CA,你可以这样调用这个函数:

CellualrAutomaton[{func[#]&,{},{1,1}},initialMatrixVal, numIterations];

上面的代码将调用函数 func[],将 Moore 邻域作为“numIterations”次的 initialMatrixVal 中每个节点的 fn 参数。

CellularAutomaton[] 函数假定周期性边界条件。

希望有帮助!

于 2011-07-11T00:35:37.603 回答
1

在 Wolfram 网站 (library.wolfram.com ?) 中可以找到“Modelling Cellular automata Simulations with mathematica”一书的大部分代码。如果您搜索作者的姓名,您将找到本书中涵盖的大多数主题的示例代码。

我可能有本书中大多数示例的代码,如果您有兴趣,请告诉我。

祝你好运!

于 2011-07-11T00:40:29.087 回答