CA
Extends:
Extension of the GridBasedModel class suitable for a Cellular Automaton (CA). Currently only supports synchronous CAs.
Example:
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 |
timeStep() 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 | ||
public |
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 |
pixt(p: ArrayCoordinate): CellId Get CellId of the pixel at coordinates p. |
|
public |
Get a random integer number between incl_min and incl_max, uniformly sampled. |
|
public |
Get a random number from the seeded number generator. |
|
public |
setpix(p: ArrayCoordinate, t: CellId) Change the pixel at position p into CellId t. |
|
public |
setpixi(i: IndexCoordinate, t: CellId) Change the pixel at position i into CellId t. |
|
public abstract |
timeStep() Update the grid in one timestep. |
Public Constructors
public constructor(extents: GridSize, conf: object, seed: number) source
The constructor of class CA.
Override:
GridBasedModel#constructorParams:
Name | Type | Attribute | Description |
extents | GridSize | the size of the grid of the model. |
|
conf | object | configuration options. |
|
conf.torus | boolean |
|
should the grid have linked borders? |
seed | number |
|
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_valuesPublic Methods
public timeStep() source
A timestep in a CA just applies the update rule and clears any cached stats after doing so.