0

I am trying to built some rules about cellular automata. In every cell I don't have one element (predator/prey) I have a number of population. To achieve movement between my population can I compare every cell with one of its neighbours every time? or do I have to compare the cell with all of its neighbours and add some conditions.

I am using Moore neighbourhood with the following update function

update[site,_,_,_,_,_,_,_,_]

I tried to make them move according to all of their neighbours but it's very complicated and I am wondering if by simplify it and check it with all of its neighbours individually it will be wrong.

Thanks

noni
  • 67
  • 1
  • 9
  • CAs usually assume that the space wraps around at the edge, so that position 1 is a neighbor of position N in a N- length 1 dimensional CA. Is this really what you want? – Verbeia Jul 12 '11 at 02:38
  • @Verbeia Actually I have a two dimensional lattice, I want the population in every cell to move every timestep according to which cell arount it has less population that the current cell. I have dome my codes but in my codes I am checking every cell with one of its neigbours, I have 8 rules for example and each one is checking the movements between the cell with one of its neigbours but I am not sure if this is correct or if I have to write 1 rule for all the neigbours – noni Jul 12 '11 at 02:53
  • @Verbeia, the wrap around at the boundary is just a choice, and for many CA that can cause issues. Theoretical CA lie in infinite planes... – JeremyKun Jul 12 '11 at 05:40

2 Answers2

2

Before I give my best attempted answer, you have to realize that your question is oddly phrased. The update rules of your cellular automaton are specified by you, so I wouldn't know whether you have additional conditions you need to implement.

I think you're asking what is the best way to select a neighborhood, and you can do this with Part:

(* We abbreviate 'nbhd' for neighborhood *)

getNbhd[A_, i_Integer?Positive, j_Integer?Positive] := 
    A[[i - 1 ;; i + 1, j - 1 ;; j + 1]];

This will select the appropriate Moore neighborhood, including the additional central cell, which you can filter out when you call your update function.

Specifically, to perform the update step of a cellular automaton, one must update all cells simultaneously. In the real world, this means creating a separate array, and placing the updated values there, scrapping the original array afterward.

For more details, see my blog post on Cellular Automata, which includes an implementation of Conway's Game of Life in Mathematica.

JeremyKun
  • 2,987
  • 2
  • 24
  • 44
  • If I understand correctly A is the current cell and i,j represent the neigborhood of it. But how can I use it with the update rule? – noni Jul 12 '11 at 02:33
  • @Bean If you worked with Conway's, you may be interested in improving this Code Golf answer :) http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life/3513212#3513212 – Dr. belisarius Jul 12 '11 at 03:04
  • @noni, you could do something which specifically matches the form of the array: update[{{upperLeft_, upperMid_, upperRight_},{midLeft_, center_, midRight_},{lowerLeft_, lowerMid_, lowerRight_}}, otherArgs_, ...], and then call it as cellInNewMatrix = update[getNbhd[cellInOldMatrix], otherArgs_, ...]; – JeremyKun Jul 12 '11 at 05:42
2

As a general advice I would recommend against going down the pattern recognition technique in Mathematica for specifying the rule table in CA, they tend to get out of hand very quickly.

Doing a predator-prey kind of simulation with CA is a little tricky since in each step, (unlike in traditional CA) the value of the center cell changes ALONG WITH THE VALUE OF THE NEIGHBOR CELL!

This will lead to issues since when the transition function is applied on the neighbor cell it will again compute a new value for itself, but it also needs to "remember" the changes done to it previously when it was a neighbor.

In fluid dynamics simulations using CA, they encounter problems like this and they use a different neighborhood called Margolus neighborhood. In a Margolus neighborhood, the CA lattice is broken into distinct blocks and the update rule applied on each block. In the next step the block boundaries are changed and the transition rules applied on the new boundary, hence information transfer occurs across block boundaries.

stats
  • 71
  • 1
  • Thank you very much, but I think I manage to do what I needed with the moore neigbourhood but I will keep in mind all the informations you said – noni Jul 14 '11 at 19:13