next up previous contents
Next: 3.2 CDL Up: 3. Languages for Cellular Previous: 3. Languages for Cellular   Contents

3.1 Specification of CA in Java

The language Java is certainly powerful enough to simulate a cellular automaton. In the system CASim, the task of coordinating the cells, handling boundaries, drawing cells and interacting with the user is handled by the simulations system. The user only needs to describe the state of one cell, and its transition function. In the CASim system, this means that the user needs to create a subclass of the class ``State''. This class has the following methods that the user needs to implement:

void transition (Cell c) 
void copy (State s)

The first of these is really the core of the description of a cell. The state of the cell is stored in fields of the class that the user defines. These fields should be copied by the copy-method which is used to avoid the creation of new State-objects in every time step. The state can change depending on the state of the neighbors. Access to the neighbors (which should be only read, if usual CA operations are to be achieved) is available from the parameter c of type Cell, which provides the methods

State[] getNeighbors()
to get a list of neighbors according to the current neighborhood, or the function

state getNeighborRelative (int x, int y)
which gives access to the neighbor of the cell which is a (relative!) distance (x, y) away from the current cell. The simulation environment takes care of the boundary conditions so that neighbor accesses can be transparently mapped to the correct cell for periodic or reflective boundaries, or to a constant boundary value.

A number of other methods of the class State many (but need not necessarily be) implemented by the user. These are

Color getColor()
which should be implemented if colors should be used to visualize the cell state. If getColor() returns null, as is the default, another method

can be used to return an icon which is used to represent the state (in one and two dimensions). The simulation system also provides support for managing icons in the class IconManager described below.

A textual representation of the cell state can be returned by


Note that only the method transition should access the state of the neighbors and change the state of the cell. The methods getColor, getIcon, and toString should not access the neighbors and not change the state. These restrictions are not enforced by the simulation system, but should be observed by any user wishing to simulate cellular automata.

For block-CA the interface is slightly different. In this case a block of cells change state together, so there is not truly one object with which the state transition is associated, but several. Therefore in this case a method

transition (State [])

is called, which is supposed to change all the states in the block. The states are passed as an array of states which is really an array of the user defined states.

next up previous contents
Next: 3.2 CDL Up: 3. Languages for Cellular Previous: 3. Languages for Cellular   Contents
Jörg R. Weimar