de.tubs.cs.sc.casim
Class Lattice

java.lang.Object
  |
  +--de.tubs.cs.sc.casim.Lattice
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BlockLattice, CALattice

public abstract class Lattice
extends java.lang.Object
implements java.io.Serializable

base class of all Lattice's defines abstract interface used by CALocal and common implementation most relevant code is implemented in subclasses.

See Also:
Serialized Form

Field Summary
protected  de.tubs.cs.sc.casim.BoundaryHandler[] boundaryHandler
           
protected  int lx
           
protected  int ly
           
protected  int lz
           
 
Constructor Summary
Lattice(java.lang.Class state, de.tubs.cs.sc.casim.LatticeDefinition ldef)
          Constructor of Lattice A Lattice object cannot be instanciated directly, the subclasses must be used.
 
Method Summary
 void addBoundaryHandler(de.tubs.cs.sc.casim.BoundaryHandler b)
          Adds a boundary handler to the lattice.
protected abstract  void backup()
          is called by CALocal.backup in each generation step after waiting for all boundary handlers readyForBackup.
protected  void beginBlock()
          methods to indicate the begining and the end of a sequence of ( transition(); backup() )* calls.
protected  void callAnalyze()
          call the static method analyze of the user-defined class.
protected  void callInitialize()
          call the static method initialize of the user-defined class.
abstract  void defineNeighborsArbitrary(int[][] indexes)
          defines an arbitrary neighborhood for the CA
protected  void endBlock()
          methods to indicate the begining and the end of a sequence of ( transition(); backup() )* calls.
protected  void finish()
          Possibility to do some cleanup work before the lattice is discarded.
 de.tubs.cs.sc.casim.BoundaryHandler getBoundaryHandler(int dim, boolean dir)
           
protected  de.tubs.cs.sc.casim.LatticeDefinition getDefinition()
           
abstract  int getDimension()
           
abstract  de.tubs.cs.sc.casim.State getOldState(int x, int y, int z)
          returns the old state at the given coordinates.
abstract  de.tubs.cs.sc.casim.State getState(int x)
          returns the current state at the given coordinates.
abstract  de.tubs.cs.sc.casim.State getState(int x, int y)
          returns the current state at the given coordinates.
abstract  de.tubs.cs.sc.casim.State getState(int x, int y, int z)
          returns the current state at the given coordinates.
protected  java.lang.Class getStateClass()
           
 int getX()
           
 int getY()
           
 int getZ()
           
protected abstract  void reset()
          resets the lattice back into start condition of all cells
protected abstract  void reversetransition()
          is called by CALocal.doBackStep in each generation step back Subclasses call reversetransition for each block of States of the lattice.
 void setNeighborhood(int type, int radius)
           
protected abstract  void transition()
          is called by CALocal.doStep in each generation step after waiting for all boundary handlers readyForTransition.
protected  void waitForReadyForBackup(int iGeneration)
          called before any backup, waits for all BoundaryHandler.readyForBackup until a real backup can be processed.
protected  void waitForReadyForTransition(int iGeneration)
          called before any backup, waits for all BoundaryHandler.readyForTransition until a real transition can be processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lx

protected int lx

ly

protected int ly

lz

protected int lz

boundaryHandler

protected de.tubs.cs.sc.casim.BoundaryHandler[] boundaryHandler
See Also:
Lattice1D, Lattice2D, Lattice3D
Constructor Detail

Lattice

public Lattice(java.lang.Class state,
               de.tubs.cs.sc.casim.LatticeDefinition ldef)
        throws CAException
Constructor of Lattice A Lattice object cannot be instanciated directly, the subclasses must be used. The constructor is protected, may be instanciated only in package.

See Also:
Lattice1D.Lattice1D(java.lang.Class, de.tubs.cs.sc.casim.LatticeDefinition), Lattice2DTriangle.Lattice2DTriangle(java.lang.Class, de.tubs.cs.sc.casim.LatticeDefinition), Lattice2DSquare.Lattice2DSquare(java.lang.Class, de.tubs.cs.sc.casim.LatticeDefinition), Lattice2DHexagonal.Lattice2DHexagonal(java.lang.Class, de.tubs.cs.sc.casim.LatticeDefinition), Lattice3D.Lattice3D(java.lang.Class, de.tubs.cs.sc.casim.LatticeDefinition)
Method Detail

addBoundaryHandler

public final void addBoundaryHandler(de.tubs.cs.sc.casim.BoundaryHandler b)
Adds a boundary handler to the lattice. On which side the handler is added depends on the boundary handler itself. Any existing boundary handler will be replaced.

See Also:
Lattice, BoundaryHandler

getBoundaryHandler

public de.tubs.cs.sc.casim.BoundaryHandler getBoundaryHandler(int dim,
                                                              boolean dir)
Returns:
the BoundaryHandler at given dimension and direction

getDimension

public abstract int getDimension()
Returns:
the dimension of the lattice

getStateClass

protected java.lang.Class getStateClass()
Returns:
the State class

getX

public final int getX()
Returns:
the width of the lattice

getY

public final int getY()
Returns:
the height of the lattice The height is 1 for one dimensional lattices.

getZ

public final int getZ()
Returns:
the depth of the lattice The depth is 1 for one and two dimensional lattices.

getDefinition

protected final de.tubs.cs.sc.casim.LatticeDefinition getDefinition()
Returns:
the LatticeDefinition
See Also:
LatticeDefinition

getState

public abstract de.tubs.cs.sc.casim.State getState(int x)
returns the current state at the given coordinates. Two and three dimensional lattices will throw a RuntimeException if the method will be used on them. getState should be used in State's override initialize to init all states of the CA. The returned reference must be casted to a class derived from abstract class State.

Returns:
the current state at position x

getState

public abstract de.tubs.cs.sc.casim.State getState(int x,
                                                   int y)
returns the current state at the given coordinates. One and three dimensional lattices will throw a RuntimeException if the method will be used on them. getState should be used in State's override initialize to init all states of the CA. The returned reference must be casted to a class derived from abstract class State.

Returns:
the current state at position x,y

getState

public abstract de.tubs.cs.sc.casim.State getState(int x,
                                                   int y,
                                                   int z)
returns the current state at the given coordinates. One and two dimensional lattices will throw a RuntimeException if the method will be used on them. getState should be used in State's override initialize to init all states of the CA. The returned reference must be casted to a class derived from abstract class State.

Returns:
the current state at position x,y,z

getOldState

public abstract de.tubs.cs.sc.casim.State getOldState(int x,
                                                      int y,
                                                      int z)
returns the old state at the given coordinates. y and z are ignored for one dimensional lattices, z is ignored for two dimensional lattices. getOldState is used by Cell to calculate the neighborhood set and by BoundaryHandlers.getOutSideState.

Returns:
the old state at position x,y,z
See Also:
Cell.getNeighbors(), BoundaryHandler.getOutsideState(int)

backup

protected abstract void backup()
is called by CALocal.backup in each generation step after waiting for all boundary handlers readyForBackup. Subclasses call 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.

See Also:
Cell.backup(), State.copy(de.tubs.cs.sc.casim.State), BoundaryHandler.readyForBackup(int)

transition

protected abstract void transition()
is called by CALocal.doStep in each generation step after waiting for all boundary handlers readyForTransition. Subclasses call 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.

See Also:
Cell.transition(), State.transition(de.tubs.cs.sc.casim.Cell), BoundaryHandler.readyForTransition(int)

reversetransition

protected abstract void reversetransition()
is called by CALocal.doBackStep in each generation step back Subclasses call reversetransition for each block of States of the lattice.

See Also:
BlockState.reversetransition(de.tubs.cs.sc.casim.BlockState[])

waitForReadyForBackup

protected void waitForReadyForBackup(int iGeneration)
called before any backup, waits for all BoundaryHandler.readyForBackup until a real backup can be processed.

See Also:
backup(), BoundaryHandler.readyForBackup(int)

waitForReadyForTransition

protected void waitForReadyForTransition(int iGeneration)
called before any backup, waits for all BoundaryHandler.readyForTransition until a real transition can be processed.

See Also:
transition(), BoundaryHandler.readyForTransition(int)

defineNeighborsArbitrary

public abstract void defineNeighborsArbitrary(int[][] indexes)
defines an arbitrary neighborhood for the CA


setNeighborhood

public final void setNeighborhood(int type,
                                  int radius)
Returns:
the LatticeDefinition
See Also:
LatticeDefinition

reset

protected abstract void reset()
                       throws CAException
resets the lattice back into start condition of all cells

CAException

beginBlock

protected void beginBlock()
methods to indicate the begining and the end of a sequence of ( transition(); backup() )* calls. This is used for Native Lattice subclasses which need to copy to and from Java structurs at the beginning and at the end of such blocks.


endBlock

protected void endBlock()
methods to indicate the begining and the end of a sequence of ( transition(); backup() )* calls. This is used for Native Lattice subclasses which need to copy to and from Java structurs at the beginning and at the end of such blocks. Also used to call anaylze(Lattice).


callInitialize

protected void callInitialize()
call the static method initialize of the user-defined class. this is a bit complicated because the reflection API must be used.


callAnalyze

protected void callAnalyze()
call the static method analyze of the user-defined class. this is a bit complicated because the reflection API must be used.


finish

protected void finish()
Possibility to do some cleanup work before the lattice is discarded. This is used in Lattice2DThreaded to finish the threads.