de.tubs.cs.sc.casim
Class Lattice2D

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

public abstract class Lattice2D
extends CALattice

represents a two dimensional Lattice of cells. All cells are arranged in rows and columns. The data structure is a two dimensional array of Cells. Lattice2D is the common base class for all tow dimensional lattices like triangular, square and hexagonal. These subclasses use the same data structure but different mappings for drawing and neighborhood conditions.

See Also:
Lattice, Cell, Serialized Form

Field Summary
protected  boolean backingUp
          the current state of transitioning.
protected  de.tubs.cs.sc.casim.Cell[][] cells
           
protected  boolean transitioning
           
 
Fields inherited from class de.tubs.cs.sc.casim.CALattice
neighborhoodIndexes
 
Fields inherited from class de.tubs.cs.sc.casim.Lattice
boundaryHandler, lx, ly, lz
 
Constructor Summary
Lattice2D(java.lang.Class state, de.tubs.cs.sc.casim.LatticeDefinition ldef)
          Constructor creates the two dimensional array of cells and 4 BoundaryHandler calls reset to initialize all cells
 
Method Summary
protected  void backup()
          calls backup for each cell
 int getDimension()
           
protected  de.tubs.cs.sc.casim.State getNeighborRelative(de.tubs.cs.sc.casim.Cell cell, int x, int y, int z)
          returns the relative neighbor of cell with given relative coordinates.
protected  de.tubs.cs.sc.casim.State[] getNeighborsArbitrary(de.tubs.cs.sc.casim.Cell cell)
          returns a previously defined arbitrary neighborhood.
 de.tubs.cs.sc.casim.State getOldState(int x, int y, int z)
          returns the old state at the given coordinates.
 de.tubs.cs.sc.casim.State getState(int x)
          always throws a RuntimeException
 de.tubs.cs.sc.casim.State getState(int x, int y)
          returns the current state at the given coordinates.
 de.tubs.cs.sc.casim.State getState(int x, int y, int z)
          returns the current state at the given coordinates.
protected  void reset()
          reallocates all cells and calls again State.initialize for one cell
protected  void setIs(int i1, int i2)
          Set the position in the lattice for neighborhood accesses.
 java.lang.String toString()
           
 void transition()
          calls transition for each cells state
 
Methods inherited from class de.tubs.cs.sc.casim.CALattice
defineNeighborsArbitrary, getNeighbors, getNeighborsMoore, getNeighborsMoore, getNeighborsvonNeumann, getNeighborsvonNeumann, getNrOfNeighbors, reversetransition
 
Methods inherited from class de.tubs.cs.sc.casim.Lattice
addBoundaryHandler, beginBlock, callAnalyze, callInitialize, endBlock, finish, getBoundaryHandler, getDefinition, getStateClass, getX, getY, getZ, setNeighborhood, waitForReadyForBackup, waitForReadyForTransition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cells

protected de.tubs.cs.sc.casim.Cell[][] cells

backingUp

protected boolean backingUp
the current state of transitioning. Used for selecting which cell to display for a repaint during calculation.


transitioning

protected boolean transitioning
Constructor Detail

Lattice2D

public Lattice2D(java.lang.Class state,
                 de.tubs.cs.sc.casim.LatticeDefinition ldef)
          throws CAException
Constructor creates the two dimensional array of cells and 4 BoundaryHandler calls reset to initialize all cells

Parameters:
state - the Java class of the State of the cells of the lattice
ldef - the LatticeDefinition with further lattice parameters
Method Detail

getDimension

public final int getDimension()
Specified by:
getDimension in class Lattice
Returns:
the dimension of the lattice

reset

protected void reset()
              throws CAException
reallocates all cells and calls again State.initialize for one cell

Specified by:
reset in class Lattice
CAException

getState

public de.tubs.cs.sc.casim.State getState(int x)
always throws a RuntimeException

Specified by:
getState in class Lattice
Returns:
the current state at position x
See Also:
Lattice1D.getState(int)

getState

public de.tubs.cs.sc.casim.State getState(int x,
                                          int y)
returns the current state at the given coordinates. 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.

Specified by:
getState in class Lattice
Returns:
the current state at position x,y

getState

public de.tubs.cs.sc.casim.State getState(int x,
                                          int y,
                                          int z)
Description copied from class: Lattice
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.

Specified by:
getState in class Lattice
Returns:
the current state at position x,y,z
See Also:
Lattice3D.getState(int)

getOldState

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

Specified by:
getOldState in class Lattice
Returns:
the old state at position x,y
See Also:
Cell.getNeighbors(), BoundaryHandler.getOutsideState(int)

getNeighborRelative

protected de.tubs.cs.sc.casim.State getNeighborRelative(de.tubs.cs.sc.casim.Cell cell,
                                                        int x,
                                                        int y,
                                                        int z)
returns the relative neighbor of cell with given relative coordinates.

Specified by:
getNeighborRelative in class CALattice
Returns:
a State, the reference must be casted to the State subclass.
See Also:
CALattice.getNeighbors(de.tubs.cs.sc.casim.Cell)

getNeighborsArbitrary

protected de.tubs.cs.sc.casim.State[] getNeighborsArbitrary(de.tubs.cs.sc.casim.Cell cell)
returns a previously defined arbitrary neighborhood.

Specified by:
getNeighborsArbitrary in class CALattice
Returns:
an array of States, all references must be casted to the State subclass.
See Also:
CALattice.getNeighbors(de.tubs.cs.sc.casim.Cell)

backup

protected void backup()
calls backup for each cell

Specified by:
backup in class Lattice
See Also:
Lattice.backup()

transition

public void transition()
calls transition for each cells state

Specified by:
transition in class Lattice
See Also:
Lattice.transition()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setIs

protected void setIs(int i1,
                     int i2)
Set the position in the lattice for neighborhood accesses. This is used for subclasses that implement transition directly, but need to access th eoriginal trnasition function at the borders.