Class CA

java.lang.Object
  extended byAbstract1DGrid
      extended byCA

public class CA
extends Abstract1DGrid

This cellular automata (CA) is a grid of cells, particularly its states. This implementation is 1 dimensional.
State can be true=1 or false=0.

Since:
1.0
Version:
1.1, 2007-05-29
Author:
TineL

Field Summary
private  boolean[] ca
          Array of cell states.
 
Fields inherited from class Abstract1DGrid
 
Constructor Summary
CA(boolean[] states)
          Creates CA with the given cell states.
CA(int size)
          Creates CA with the specified size.
 
Method Summary
static CA generateRandomCA(int size, double onesRatio)
          Generates a CA with random cell states considering the ratio of 1s that occur in the CA.
 boolean get(int index)
           
 boolean getLeft(int index)
           
 boolean getRight(int index)
           
 boolean moreOnes()
           
 boolean moreZeros()
           
 int onesCount()
           
 double onesRatio()
           
 void set(int index, boolean state)
          Sets the state of the cell.
 java.lang.String toString()
           
 int zerosCount()
           
 double zerosRatio()
           
 
Methods inherited from class Abstract1DGrid
getLeftIndex, getRightIndex, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ca

private boolean[] ca
Array of cell states.

Constructor Detail

CA

public CA(int size)
Creates CA with the specified size. All cell states are set to 0 (false).

Parameters:
size - the CA size.
Since:
1.0

CA

public CA(boolean[] states)
Creates CA with the given cell states.

Parameters:
states - the cell states (null not permitted).
Since:
1.0
Method Detail

generateRandomCA

public static CA generateRandomCA(int size,
                                  double onesRatio)
Generates a CA with random cell states considering the ratio of 1s that occur in the CA.

Parameters:
size - the CA size.
onesRatio - the ratio of 1s that occur in the CA beside the 0s.
Returns:
a random generated CA (null not possible).
Since:
1.0

get

public boolean get(int index)
Parameters:
index - the cell index.
Returns:
the cell state.
Since:
1.0

set

public void set(int index,
                boolean state)
Sets the state of the cell.

Parameters:
index - the cell index.
state - the cell new state.
Since:
1.0

getLeft

public boolean getLeft(int index)
Parameters:
index - the cell index.
Returns:
the state of the left cell.
Since:
1.0

getRight

public boolean getRight(int index)
Parameters:
index - the cell index.
Returns:
the state of the right cell.
Since:
1.0

onesCount

public int onesCount()
Returns:
the number of 1s (true states) in the CA.
Since:
1.0

onesRatio

public double onesRatio()
Returns:
the ratio of 1s (true states) according to 0s in the CA.
Since:
1.0

moreOnes

public boolean moreOnes()
Returns:
true if CA has more or equal half 1s (true states) according to 0s.
Since:
1.0

zerosCount

public int zerosCount()
Returns:
the number of 0s (false states) in the CA.
Since:
1.0

zerosRatio

public double zerosRatio()
Returns:
the ratio of 0s (false states) according to 1s in the CA.
Since:
1.0

moreZeros

public boolean moreZeros()
Returns:
true if CA has more or equal half 0s (false states) according to 1s.
Since:
1.0

toString

public java.lang.String toString()