Code Monkey home page Code Monkey logo

calab's Introduction

CAlab - A labratory for Cellular Automata

This is a series of programs that can compute/simulate different kinds of Cellular Automata (CA).

At the moment only one-dimensional CA's can be computed, with the CA1.java file, but I plan to work on 2 and 3 dimensional CA programs in the future.

A bit of CA theory

All cellular automata can the thought of as a 5 tuple:

  1. A set of cells called the grid
  2. A set of states (which the cells can have)
  3. A starting grid
  4. A rule that specifies how certain subsets of cells should change over time
  5. A neighbourhood specifying the subset of cells in the grid to which the rule applies

A CA computes when the rule is applied to each cell in the gird, and after the new state of each cell has been determined, all cells are updated at once. This can be repeated as many times an one wants.

An interesing fact to note is that the number of possible rules a CA can have is determined by:

nr. of possible rules = kks

where

k = nr. of states, and
s = nr. of cells in the neighbourhood

Guide: CA1.java

The code should be pretty well documented, but if anything is unclear please let me know.

CA1.java can be used to simulate any 1-dimensional CA. To see how this is done, let's look at an example:

public static void main(String[] args)
{
  /* A grid is defined, represented by an array of integers. In this case the grid consists of only 145 cells */
  int[] state= new int[145];
  /* The number of states is defined and the gird is initialized. In this case we will represent 
  the first state with a 0 (int) and the second state with a 1 (int) */
  int nrOfStates = 2;
  /* The starting grid is is initialized */
  state[73] = 1;
  /* A rule is represented by a number corresponding to the same number in the base of nrOfStates (binary in this case) */
  int[] ruleA = {0, 1, 1, 1, 1, 0, 0, 0};
  /* The neighbourhood indicates which cells are used by the rule when applied to a specific cell
  by indicating the distance to the cell in the neighbourhood, relative to the cell to which the 
  rule is currently being applied. In this case the neighbourhood will be the cell to the current 
  cell's immediate left, itself, and its immediate right */
  int[] neighbourhood = {-1, 0, 1};

  /* We can now combine these things into an object of the CA1 class, which makes a 1-dimensional CA */
  CA1 rule_30 = new CA1(neighbourhood, nrOfStates, ruleA, state);
}

To see what happens when the CA computes, one can add the following code:

char[] printChars = {' ', '#'}; // ' ' represents 0, and
                                // '#' represents 1
/* This computes and prints rule_30 for 30 timesteps */
for (int generation = 0; generation <30; generation++) {
    rule_30.printState(printChars);
    System.out.println();
    rule_30.updateState();
}

This will be the result:

imagename

calab's People

Contributors

willieloea avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.