import CA from 'Artistoo/src/models/CA.js'
public class | source

CA

Extends:

GridBasedModel → CA

Extension of the GridBasedModel class suitable for a Cellular Automaton (CA). Currently only supports synchronous CAs.

Example:

Conway's Game of Life
let CPM = require( "path/to/build" )
let C = new CPM.CA( [200,200], {
	"UPDATE_RULE": 	function(p,N){
		let nalive = 0
		for( let pn of N ){
			nalive += (this.pixt(pn)==1)
		}	
		if( this.pixt(p) == 1 ){
			if( nalive == 2 || nalive == 3 ){
				return 1
			}
		} else {
			if( nalive == 3 ) return 1
		}
		return 0
	}
})
let initialpixels = [ [100,100], [101,100], [102,100], [102,101], [101,102] ]
for( p of initialpixels ){
	C.setpix( p, 1 )
	}
// Run it.
for( let t = 0; t < 10; t++ ){ C.timeStep() }

TODO:

  • Include asynchronous updating scheme?

Constructor Summary

Public Constructor
public

constructor(extents: GridSize, conf: object, seed: number)

The constructor of class CA.

Member Summary

Public Members
public

Cached values of these stats.

public

Bind the supplied updaterule to the object.

Method Summary

Public Methods
public

A timestep in a CA just applies the update rule and clears any cached stats after doing so.

Inherited Summary

From class GridBasedModel
public

cellvolume: *[]

This tracks the volumes of all non-background cells on the grid.

public

Input parameter settings; see the constructor of subclasses documentation.

public

Size of the grid.

public

Size of the grid in object format.

public

grid: *

public

Midpoint of the grid.

public

Attach a random number generation with a seed.

public

Dimensionality of the grid

public

The Grid2D#neighi or Grid3D#neighi iterator function of the underlying grid.

public

The Grid2D#pixels or Grid3D#pixels iterator function of the underlying grid.

public

The Grid#pixti iterator function of the underlying grid.

public

Cached values of these stats.

public

Objects of class Stat that have been computed on this model.

public

Tracks the elapsed time in MCS

public

Iterator for all the CellIds that are currently on the grid.

public

Get the CellKind of the cell with CellId t.

public

getStat(s: Stat): anything

Compute a statistic on this model.

public

neigh(p: ArrayCoordinate, torus: boolean[]): *

Get neighbourhood of position p, using neighborhood functions of the underlying grid class.

public

Get CellId of the pixel at coordinates p.

public

ran(incl_min: number, incl_max: number): number

Get a random integer number between incl_min and incl_max, uniformly sampled.

public

Get a random number from the seeded number generator.

public

Change the pixel at position p into CellId t.

public

Change the pixel at position i into CellId t.

public abstract

Update the grid in one timestep.

Public Constructors

public constructor(extents: GridSize, conf: object, seed: number) source

The constructor of class CA.

Override:

GridBasedModel#constructor

Params:

NameTypeAttributeDescription
extents GridSize

the size of the grid of the model.

conf object

configuration options.

conf.torus boolean
  • optional
  • default: [true,true,...]

should the grid have linked borders?

seed number
  • optional

seed for the random number generator. If left unspecified, a random number from the Math.random() generator is used to make one.

conf.UPDATE_RULE updatePixelFunction

the update rule of the CA.

Public Members

public stat_values: object source

Cached values of these stats. Object with stat name as key and its cached value as value. The cache must be cleared when the grid changes!

Override:

GridBasedModel#stat_values

public updateRule: updatePixelFunction source

Bind the supplied updaterule to the object.

Public Methods

public timeStep() source

A timestep in a CA just applies the update rule and clears any cached stats after doing so.

Override:

GridBasedModel#timeStep