de.tubs.cs.sc.casim
Class CALocal

java.lang.Object
  |
  +--de.tubs.cs.sc.casim.CALocal
All Implemented Interfaces:
CellularAutomaton, java.io.Serializable

public final class CALocal
extends java.lang.Object
implements java.io.Serializable, CellularAutomaton

The class CALocal represents and capsulates a Cellular Automaton. It has a lattice, the state class and a generation counter as it's members.

A Cellular Automaton is characterized by it's lattice construction and the transition function The lattice contains the collection of cells of the automaton. It's structure depends on the construction parameters of the automaton. The CALocal holds only a reference to the base class Lattice of all lattices. The behaviour of the lattice is implemented in derived classes. You define a new lattice using setLatticeDefinition. You can create the lattice using initialize.

The transition function is defined by State class. You can define the state class of the automaton using setState or setStateSetDefinition. Using setState you must provide a class derived from State, which overrides at least the transition method of State to define your own transition function. Using setStateSetDefinition you can use StateSetDefinition for your automaton. The automat uses TableState as the from State derived class. StateSetDefinition provides two tables. One table provides a function from the integer state of the cell to a Color in which the cell will be painted. The other table contains transition rules for the transition of the cellular automaton.

Steps to create and execute an CA

  1. Instantiate a CALocal
  2. Call setStateClass to define the State class.
  3. Call setLatticeDefinition to define the lattice.
  4. Call initialize to create the lattice.
  5. Call step to execute the CA.one ore more generations.
  6. Call reset to set the lattice back to it's initial configuration.

Author:
Uwe Freiwald
See Also:
Lattice, State, LatticeDefinition, StateSetDefinition, Serialized Form

Field Summary
 
Fields inherited from interface de.tubs.cs.sc.casim.CellularAutomaton
HEXAGONAL, SQUARE, TRIANGLE
 
Constructor Summary
CALocal()
          Constructor I Creates an empty CA.
CALocal(de.tubs.cs.sc.casim.CADescription desc)
           
CALocal(de.tubs.cs.sc.casim.LatticeDefinition ldef, java.lang.Class cls)
          Constructor II Creates a CA with the given parameters.
CALocal(de.tubs.cs.sc.casim.LatticeDefinition ldef, de.tubs.cs.sc.casim.StateSetDefinition ssd)
          Constructor III Creates a CA with the given parameters.
 
Method Summary
 void backup()
          after waiting for all boundary handlers readyForBackup.
 void doBackStep()
          executes one generation step back of the Block CA.
 void doNSteps(int n)
          Steps the CA n generations forward.
 void doStep()
          executes one generation step of the CA.
 de.tubs.cs.sc.casim.BoundaryHandler getBoundaryHandler(int dim, boolean dir)
           
 int getDimension()
           
 int getGeneration()
           
 int getGeometry()
           
 de.tubs.cs.sc.casim.Lattice getLattice()
           
 de.tubs.cs.sc.casim.LatticeDefinition getLatticeDefinition()
           
 de.tubs.cs.sc.casim.State getOldState(int x)
           
 de.tubs.cs.sc.casim.State getOldState(int x, int y)
           
 de.tubs.cs.sc.casim.State getOldState(int x, int y, int z)
           
 java.lang.String getSizeString()
           
 de.tubs.cs.sc.casim.State getState(int x)
           
 de.tubs.cs.sc.casim.State getState(int x, int y)
           
 de.tubs.cs.sc.casim.State getState(int x, int y, int z)
           
 java.lang.Class getStateClass()
           
 de.tubs.cs.sc.casim.StateSetDefinition getStateSetDefinition()
           
 int getX()
           
 int getY()
           
 int getZ()
           
 void initialize()
          initializes the CA.
 boolean isBlockCA()
          checks wether the state class implements the BlockState interface or not.
 boolean isInitialized()
           
 void out(java.io.PrintWriter p)
          prints out the whole lattice in {} format
 void reset()
          Resets the CA into start condition by resetting the lattice and generation counter.
 void setDescription(de.tubs.cs.sc.casim.CADescription desc)
          Every class that implements this interface can inherit his own CADescription, use this method to configure the respective class with his configuration.
 void setLatticeDefinition(de.tubs.cs.sc.casim.LatticeDefinition ldef)
          setLatticeDefinition is used to define a new lattice.
 void setStateClass(java.lang.Class cls)
          Sets the state class for the CA.
 void setStateSetDefinition(de.tubs.cs.sc.casim.StateSetDefinition ssd)
          setStateSetDefinition is used to create a table driven CA.
 void transition()
          after waiting for all boundary handlers readyForTransition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CALocal

public CALocal()
Constructor I Creates an empty CA. You must use the methods setLatticeDefinition and setState or setStateDefinition and initialize.

See Also:
setLatticeDefinition(de.tubs.cs.sc.casim.LatticeDefinition), setStateClass(java.lang.Class), setStateSetDefinition(de.tubs.cs.sc.casim.StateSetDefinition), initialize()

CALocal

public CALocal(de.tubs.cs.sc.casim.CADescription desc)

CALocal

public CALocal(de.tubs.cs.sc.casim.LatticeDefinition ldef,
               java.lang.Class cls)
Constructor II Creates a CA with the given parameters. You must call initialize to really create the lattice. Only after calling initialize you are able to execute the CA.

Parameters:
ldef - the Lattice definition parameters
cls - the state class
See Also:
LatticeDefinition, State, initialize()

CALocal

public CALocal(de.tubs.cs.sc.casim.LatticeDefinition ldef,
               de.tubs.cs.sc.casim.StateSetDefinition ssd)
Constructor III Creates a CA with the given parameters. You must call initialize to really create the lattice. Only after calling initialize you are able to execute the CA.

Parameters:
ldef - the Lattice definition parameters
ssd - the State set definition
See Also:
StateSetDefinition, LatticeDefinition, State
Method Detail

getLatticeDefinition

public de.tubs.cs.sc.casim.LatticeDefinition getLatticeDefinition()
Specified by:
getLatticeDefinition in interface CellularAutomaton
Returns:
the current lattice definition, if the automatons lattice definition is already defined, otherwise null.
See Also:
LatticeDefinition

setStateClass

public void setStateClass(java.lang.Class cls)
Sets the state class for the CA.

Specified by:
setStateClass in interface CellularAutomaton
See Also:
CellularAutomaton.setStateClass(java.lang.Class), setLatticeDefinition(de.tubs.cs.sc.casim.LatticeDefinition), setStateSetDefinition(de.tubs.cs.sc.casim.StateSetDefinition), State, BlockState

setDescription

public void setDescription(de.tubs.cs.sc.casim.CADescription desc)
Description copied from interface: CellularAutomaton
Every class that implements this interface can inherit his own CADescription, use this method to configure the respective class with his configuration.

Specified by:
setDescription in interface CellularAutomaton
See Also:
CADescription

setStateSetDefinition

public void setStateSetDefinition(de.tubs.cs.sc.casim.StateSetDefinition ssd)
setStateSetDefinition is used to create a table driven CA.

Specified by:
setStateSetDefinition in interface CellularAutomaton
See Also:
initialize(), setLatticeDefinition(de.tubs.cs.sc.casim.LatticeDefinition), setStateClass(java.lang.Class), StateSetDefinition

getStateSetDefinition

public de.tubs.cs.sc.casim.StateSetDefinition getStateSetDefinition()
Specified by:
getStateSetDefinition in interface CellularAutomaton
Returns:
the StateSetDefinition currently used, or null.
See Also:
StateSetDefinition

setLatticeDefinition

public void setLatticeDefinition(de.tubs.cs.sc.casim.LatticeDefinition ldef)
setLatticeDefinition is used to define a new lattice. You can define the dimensions and the kind of the lattice. A new lattice is created after calling initialize.

Specified by:
setLatticeDefinition in interface CellularAutomaton
See Also:
initialize(), LatticeDefinition, Lattice, doStep()

getLattice

public de.tubs.cs.sc.casim.Lattice getLattice()
Returns:
the currently used lattice
See Also:
Lattice

getStateClass

public java.lang.Class getStateClass()
Specified by:
getStateClass in interface CellularAutomaton
Returns:
the currently used state class
See Also:
State, BlockState

getState

public de.tubs.cs.sc.casim.State getState(int x)
Specified by:
getState in interface CellularAutomaton
Returns:
the current State at position x of the CA
See Also:
State

getState

public de.tubs.cs.sc.casim.State getState(int x,
                                          int y)
Specified by:
getState in interface CellularAutomaton
Returns:
the current State at position x,y of the CA
See Also:
State

getState

public de.tubs.cs.sc.casim.State getState(int x,
                                          int y,
                                          int z)
Specified by:
getState in interface CellularAutomaton
Returns:
the current State at position x,y,z of the CA
See Also:
State

getOldState

public de.tubs.cs.sc.casim.State getOldState(int x)
Specified by:
getOldState in interface CellularAutomaton
Returns:
the old State at position x of the CA
See Also:
State

getOldState

public de.tubs.cs.sc.casim.State getOldState(int x,
                                             int y)
Specified by:
getOldState in interface CellularAutomaton
Returns:
the old State at position x,y of the CA
See Also:
State

getOldState

public de.tubs.cs.sc.casim.State getOldState(int x,
                                             int y,
                                             int z)
Specified by:
getOldState in interface CellularAutomaton
Returns:
the old State at position x,y,z of the CA
See Also:
State

backup

public void backup()
after waiting for all boundary handlers readyForBackup. Lattice calls backup for each cell of the lattice. Cell.backup calls State.copy to save current state data in old state, to prepare the next generation step. Block CA's don't perform a backup.

Specified by:
backup in interface CellularAutomaton
See Also:
Lattice.backup(), Cell.backup(), State.copy(de.tubs.cs.sc.casim.State), BoundaryHandler.readyForBackup(int)

transition

public void transition()
                throws java.lang.IllegalStateException
after waiting for all boundary handlers readyForTransition. Lattice calls transition for each cell of the lattice. Cell.transition calls State.transition to calculate the new state of each cell with transition function of the CA implemented in the subclass of State. Block CA's perform a transition by calling BlockState.transition for all blocks of the lattice. A IllegalStateException is thrown if backup was not called before. If you want to handle backup and transition automatically use doStep.

Specified by:
transition in interface CellularAutomaton
java.lang.IllegalStateException
See Also:
backup(), doStep(), Lattice.transition(), Cell.transition(), State.transition(de.tubs.cs.sc.casim.Cell), BlockState.transition(de.tubs.cs.sc.casim.BlockState[]), BoundaryHandler.readyForTransition(int)

doStep

public void doStep()
executes one generation step of the CA. step waits for all boundary handlers of the lattice to be readyForBackup, after that the backup of current states to old states is done. In the next step will wait for all boundary handlers readyForTransition, then the transition is done for all states to calculate the new one.

Specified by:
doStep in interface CellularAutomaton
See Also:
Lattice.backup(), Lattice.transition(), BoundaryHandler.readyForBackup(int), BoundaryHandler.readyForTransition(int)

doBackStep

public void doBackStep()
executes one generation step back of the Block CA. doBackStep is only allowed for block CA's. the BlockState.reversetransition is called for all blocks.

Specified by:
doBackStep in interface CellularAutomaton
See Also:
isBlockCA(), BlockState.reversetransition(de.tubs.cs.sc.casim.BlockState[])

doNSteps

public void doNSteps(int n)
Steps the CA n generations forward. Does not redraw the automaton.

Specified by:
doNSteps in interface CellularAutomaton
See Also:
CellularAutomaton.initialize()

reset

public void reset()
           throws CAException
Resets the CA into start condition by resetting the lattice and generation counter. CA's with probabilistic start values will not achieve exactly the same start position.

Specified by:
reset in interface CellularAutomaton
CAException
See Also:
CellularAutomaton.initialize()

initialize

public void initialize()
                throws CAException
initializes the CA. Creates a Lattice with the given LatticeDefinition. setLatticeDefinition and setStateClass or setStateSetDefinition must be called before calling initialize, otherwise a CAException is thrown. A CAException will be also thrown, if any parameter for the CA or the State class implementation is not correct.

Specified by:
initialize in interface CellularAutomaton
CAException
See Also:
setLatticeDefinition(de.tubs.cs.sc.casim.LatticeDefinition), setStateClass(java.lang.Class), setStateSetDefinition(de.tubs.cs.sc.casim.StateSetDefinition)

isInitialized

public boolean isInitialized()
Specified by:
isInitialized in interface CellularAutomaton
Returns:
true if the CA is initialized with initialize, otherwise false
See Also:
initialize()

getDimension

public int getDimension()
Specified by:
getDimension in interface CellularAutomaton
Returns:
the dimension of the CellularAutomaton 1 .. one dimensional 2 .. two dimensional 3 .. three dimensional

getSizeString

public java.lang.String getSizeString()
Specified by:
getSizeString in interface CellularAutomaton
Returns:
a string for the size of the cellular automaton. For a two dimensional CA a sample would be 10x10.

getX

public int getX()
Specified by:
getX in interface CellularAutomaton
Returns:
the width of the CellularAutomaton

getY

public int getY()
Specified by:
getY in interface CellularAutomaton
Returns:
the height of the CellularAutomaton

getZ

public int getZ()
Specified by:
getZ in interface CellularAutomaton
Returns:
the depth of the CellularAutomaton

getGeometry

public int getGeometry()
Specified by:
getGeometry in interface CellularAutomaton
Returns:
the geometry of the CA. SQUARE TRIANGLE HEXAGONAL

getBoundaryHandler

public de.tubs.cs.sc.casim.BoundaryHandler getBoundaryHandler(int dim,
                                                              boolean dir)
Specified by:
getBoundaryHandler in interface CellularAutomaton
Returns:
the BoundaryHandler at the given dimension and direction.
See Also:
BoundaryHandler

getGeneration

public int getGeneration()
Specified by:
getGeneration in interface CellularAutomaton
Returns:
the current generation or time step of the CA
See Also:
CellularAutomaton.doStep()

isBlockCA

public boolean isBlockCA()
checks wether the state class implements the BlockState interface or not.

Specified by:
isBlockCA in interface CellularAutomaton
Returns:
true if this is a block CA, otherwise false

out

public void out(java.io.PrintWriter p)
prints out the whole lattice in {} format