i've compared the two forest fire programs, MySmokey and smokeyTheBear.
please excuse any formatting problems. doing 'copy and paste' from a notebook into this area causes a variety of problems (btw - the often-stated claim that most programs written in an early version of Mathematica run without difficulty in a later version of Matematica is simply untrue. even doing a simple 'copy and paste' of cells from a notebook created in an early version of Mathematica into a notebook in a later versions of Matematica is sometimes problematic.
In[1]:= Clear[MySmokey]
MySmokey[nInteger (units), p (plant probability), f_ (fire probability), m_Integer (steps)] :=
With[{fcomp = Compile[{rand}, Evaluate[Floor[2 + f - rand]]],
pcomp = Compile[{rand}, Evaluate[Floor[1 + p - rand]]]},
Module[{forestPreserve, forestIgnite, spreadFire, treeGrowIgnite},
forestPreserve = Table[Random[Integer], {n}];
SetAttributes[treeGrowIgnite, Listable];
treeGrowIgnite[0] := pcomp[Random[]];
treeGrowIgnite[1] := fcomp[Random[]];
forestIgnite[{path?(# === 1 &), 2, rem,
1}] := {spreadFire[path, 2], spreadFire[rem, 2]} /. 2 -> 0;
forestIgnite[{1, rem, 2,
path?(# === 1 &)}] := {spreadFire[2, rem],
spreadFire[2, path]} /. 2 -> 0;
forestIgnite[{rem__}] := {spreadFire[rem]} /. 2 -> 0;
spreadFire[l, 2, 1, r] :=
Sequence[spreadFire[l, 2], spreadFire[2, r]];
spreadFire[l, 1, 2, r] :=
Sequence[spreadFire[l, 2], spreadFire[2, r]];
spreadFire[rem__] := rem;
(Stopping criterion)
NestList[forestIgnite[treeGrowIgnite[#]] &, forestPreserve, m]]]
In[3]:= Timing[MySmokey[100, 0.3, 0.2, 999];]
Out[3]= {0.252269, Null}
In[4]:= Clear[smokeyTheBear]
smokeyTheBear[n, p, f, m] :=
Module[{}, forestPreserve = Table[Random[Integer], {n}];
pyro = (treeGrowIgnite = # /. {0 :> Floor[1 + p - Random[]],
1 :> Floor[2 + f - Random[]]};
forestIgnite =
treeGrowIgnite //. {{2, c, 1} -> {2, c, 2}, {1, c,
2} -> {2, c, 2}, {a, 2, 1, b} -> {a, 2, 2, b}, {a,
1, 2, b} -> {a, 2, 2, b}};
forestIgnite /. 2 -> 0) &;
NestList[pyro, forestPreserve, m]]
In[6]:= Timing[smokeyTheBear[100, 0.3, 0.2, 999];]
Out[6]= {0.386244, Null}
In[7]:= (SeedRandom[6];
smokeyTheBear[100, 0.3, 0.2, 0]) == (SeedRandom[6];
MySmokey[100, 0.3, 0.2, 0])
Out[7]= True
In[8]:= (SeedRandom[6];
smokeyTheBear[100, 0.3, 0.2, 1]) == (SeedRandom[6];
MySmokey[100, 0.3, 0.2, 1])
Out[8]= True
In[9]:= (SeedRandom[6];
smokeyTheBear[100, 0.3, 0.2, 25]) == (SeedRandom[6];
MySmokey[100, 0.3, 0.2, 25])
Out[9]= True
In[10]:= (SeedRandom[6]; smokeyTheBear[100, 0.3, 0.2, 26]) ==
(SeedRandom[6]; MySmokey[100, 0.3, 0.2, 26])
Out[10]= True
In[11]:= (SeedRandom[6]; smokeyTheBear[100, 0.3, 0.2, 27]) ==
(SeedRandom[6]; MySmokey[100, 0.3, 0.2, 27])
Out[11]= False
In[12]:= (SeedRandom[6]; smokeyTheBear[100, 0.3, 0.2, 28]) ==
(SeedRandom[6]; MySmokey[100, 0.3, 0.2, 28])
Out[12]= False
comments:
(1) MySmokey runs about 50% faster than smokeyTheBear (the speed difference is expected to vary with the size of the CA and possibly the number of time steps as well).
(2) it is unclear to me why using the same SeedRandom for the two programs produces the same result for 26 or fewer time steps as expected but from 27 time steps on, the results of the two programs differ (i assume it has something to do with the Random function calls in the two programs but i haven't check this).
note: i was able to locate a forest fire CA written using CellularAutomaton
http://forum.wolframscience.com/showthread.php?s=&threadid=720
ForestFireRule[pGrowth_ /; 0 <= pGrowth <= 1, pBurn_ /; 0 <= pBurn <= 1] :=
Function[Switch[#[[2, 2]], 0, If[Random[] <= pGrowth, 1, 0], 1,
Which[Count[#, 2, {2}] > 0, 2, Random[] <= pBurn, 2, True, 1], 2, 0]]
data = CellularAutomaton[{ForestFireRule[0.02, 0.001], {}, {1, 1}},
Table[If[Random[Integer, 5] == 0, 1, 0], {100}, {100}], 100];
notes:
(1) the above CA is two-dimensional and needs to be altered to a one-dimensional CA in order to do speed comparisons with the programs above. i didn't do this becuase i'm still confused as to the meanings of the various arguments in CellularAutomaton. perhaps, Dent, you might want to do this.
(2) the term Table[If[Random[Integer, 5] == 0, 1, 0] which represents the initial state of the forest preserve should be changed to be the same as the forestPreserve term used in the smokeyTheBear and MySmokey programs.
(3) the program using CellularAutomaton does not use pattern matching which was the original question i had about using CellularAutomaton though your response indicates it only applies to CA rules based on neighbors
(4) all of these programs are unrealistic because they use wrap-around boundary conditions and this corresponds to a burning tree at one side of the grid igniting a tree at the other side of the grid. if this was realistic, it might provide comfort for a person living in a house along the border of a state that is adjacent to a state in which a forest fire is raging but it would be uncomfortable for a person living in a house along the border of the state in which the forest fire is raging - i hope that's clear. if not, think of it this way: i live in chicago. if my dog, Ada - named after the world's first programmer - gets loose and runs all the way to new jersey i don't ask my nephew in california - he's a professional computer programmer - to keep an eye out for Ada to appear in california (actually, if Ada were bright, she'd have run away to california, rather than new jersey, in the first place). i don't understand the use of wrap-around boundary conditions in CA's that model most realistic physical systems (it would have been nice if Cecil the lion, when he was lured off his preserve turned up on the other side of the preserve, out of the gun range of the evil dentist who killed him but alas that's not the way it works).
Finally, let me say that CA's can produce nice abstract pictures but Sw has stated in NKS that they are not useful for modeling either neural nets or the universe. and i would add that they are not very useful for ABM's because in today's world, spatial distance is often not important foe modeling social or economic interactions - social networks are, and the use of social media and cellphones replace the importancee of physical distance (although many social scientists continue to use CA's and grids in their models) . in fact, IMO, the CA is not a fundamental representation of reaity at all; the graph is.
Attachments: