toxi.sim.automata
Class CAWolfram1D

java.lang.Object
  extended by toxi.sim.automata.CAWolfram1D
All Implemented Interfaces:
CARule, MatrixEvolver

public class CAWolfram1D
extends java.lang.Object
implements CARule

An extended & customized implementation of 1D Wolfram automata, fully compatible with the classic definition, yet supporting flexible kernel sizes/rule systems and n-ary cell states. The algorithm can be configured to automatically expire cells when they've reached their maximum state/age. This is a varying behaviour to the traditional CA approach, but can produce very interesting results.


Constructor Summary
CAWolfram1D(int kernelWidth, boolean isTiling)
           
CAWolfram1D(int kernelWidth, int states, boolean isTiling)
           
 
Method Summary
 void evolve(EvolvableMatrix m)
           
 int getNumRuleBits()
           
 boolean[] getRuleArray()
           
 java.math.BigInteger getRuleAsBigInt()
           
 int getStateCount()
           
 boolean isAutoExpire()
           
 boolean isTiling()
           
 void randomize()
           
 void setAutoExpire(boolean isAutoexpire)
          Sets the auto expiration behaviour.
 CAWolfram1D setRuleArray(boolean[] r)
          Updates the rules using the given array.
 CAWolfram1D setRuleID(java.math.BigInteger id)
           Uses the BigInteger value to define the new rules.
 CAWolfram1D setRuleID(long id)
           
 void setStateCount(int num)
           
 void setTiling(boolean state)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CAWolfram1D

public CAWolfram1D(int kernelWidth,
                   boolean isTiling)

CAWolfram1D

public CAWolfram1D(int kernelWidth,
                   int states,
                   boolean isTiling)
Method Detail

evolve

public void evolve(EvolvableMatrix m)
Specified by:
evolve in interface MatrixEvolver

getNumRuleBits

public final int getNumRuleBits()
Returns:
the number of rule bits used for the current kernel size.

getRuleArray

public final boolean[] getRuleArray()
Returns:
the rules as boolean array.

getRuleAsBigInt

public final java.math.BigInteger getRuleAsBigInt()
Returns:
the rules packed into a single BigInteger value.

getStateCount

public int getStateCount()
Specified by:
getStateCount in interface CARule

isAutoExpire

public boolean isAutoExpire()
Specified by:
isAutoExpire in interface CARule
Returns:
the isAutoexpire

isTiling

public boolean isTiling()
Specified by:
isTiling in interface CARule

randomize

public void randomize()
Specified by:
randomize in interface CARule

setAutoExpire

public void setAutoExpire(boolean isAutoexpire)
Sets the auto expiration behaviour.

Specified by:
setAutoExpire in interface CARule
Parameters:
isAutoexpire - true, if cells expire automatically when their max. state is reached (i.e. state reverts back to 0)

setRuleArray

public CAWolfram1D setRuleArray(boolean[] r)
Updates the rules using the given array. The new array needs to be of the same size as the length returned by getNumRuleBits().

Parameters:
r - new rules
Returns:
itself

setRuleID

public CAWolfram1D setRuleID(java.math.BigInteger id)

Uses the BigInteger value to define the new rules. Only the lowest N bits of the value are used. The value of N depends on the current kernel size and can be queried via getNumRuleBits(). The top most bit used corresponds with the left most kernel window item.

For example:


setRuleID

public CAWolfram1D setRuleID(long id)

setStateCount

public void setStateCount(int num)
Specified by:
setStateCount in interface CARule

setTiling

public void setTiling(boolean state)
Specified by:
setTiling in interface CARule