menu

Mixing events

Grid events are functions that can be called before or after updating the grid points. For example, after individuals have reproduced, you may want to apply some random mixing by using the Toffoli-Margolus diffusion algorithm:

this.MargolusDiffusion()

Other available "mixing" functions are:
this.perfectMix()
this.diffuseStates(state,rate)
this.diffuseODEstates() // Uses diffusion rates as defined in ODE system

Custom events


Or you can define your own functions, for example a bottleneck where a fraction of the population dies:

    sim.model.bottleneck = function(fraction){
    for (let i = 0; i < this.nc; i++) {
    for (let j = 0; j < this.nr; j++) {
    if(this.rng.genrand_real1() < fraction){
    this.grid[i][j].alive = 0
    this.grid[i][j].helping_rate = 0
    }
    }
    }
    }
Which you can then call to kill 95% of the population within the "update" loop, every 100 time steps:
    sim.model.update = function() {
    sim.model.synchronous()
    if(sim.time%100==0) sim.model.bottleneck(0.95)
    }