Class CAWolfram1D

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

public class CAWolfram1D extends 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 Details

    • CAWolfram1D

      public CAWolfram1D(int kernelWidth, boolean isTiling)
    • CAWolfram1D

      public CAWolfram1D(int kernelWidth, int states, boolean isTiling)
  • Method Details

    • 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 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(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:

      • kernelWidth = 1 -> number of bits 2*(4^1)=8
      • kernelWidth = 2 -> number of bits 2*(4^2)=32
      • kernelWidth = 3 -> number of bits 2*(4^2)=128
      Parameters:
      id -
      Returns:
      itself
    • 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