Constructor
new Flockmodel(name, config, rng)
The constructor function for a @Flockmodl object. Takes the same config dictionary as used in @Simulation
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of your model. This is how it will be listed in @Simulation 's properties |
config |
dictionary | A dictionary (object) with all the necessary settings to setup a Cacatoo GridModel. |
rng |
MersenneTwister | A random number generator (MersenneTwister object) |
- Source:
Methods
colourGradient(property, n)
Initiate a gradient of colours for a property.
Parameters:
Name | Type | Description |
---|---|---|
property |
string | The name of the property to which the colour is assigned |
n |
int | How many colours the gradient consists off For example usage, see colourViridis below |
- Source:
colourGradientArray(property, n)
Initiate a gradient of colours for a property (return array only)
Parameters:
Name | Type | Description |
---|---|---|
property |
string | The name of the property to which the colour is assigned |
n |
int | How many colours the gradient consists off For example usage, see colourViridis below |
- Source:
colourViridis(property, n, rev)
Initiate a gradient of colours for a property, using the Viridis colour scheme (purpleblue-ish to green to yellow) or Inferno (black to orange to yellow)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
property |
string | The name of the property to which the colour is assigned | |
n |
int | How many colours the gradient consists off | |
rev |
bool | false | Reverse the viridis colour gradient |
- Source:
flock(i)
Flocking of individuals, based on X, Y, Z (TODO)
Parameters:
Name | Type | Description |
---|---|---|
i |
Object | The individual to be updates |
- Source:
load_flock(file)
Reads a JSON file and loads a JSON object onto this flockmodel. Reading a local JSON file will not work in browser.
Gridmodels 'addCheckpointButton' instead, which may be implemented for flocks at a later stage.
Parameters:
Name | Type | Description |
---|---|---|
file |
string | Path to the json file |
- Source:
perfectMix()
Assign each individual a new random position in space. This simulated mixing,
but does not guarantee a "well-mixed" system per se (interactions are still local)
calculated based on neighbourhoods.
- Source:
plotArray(graph_labels, graph_values, cols, title, opts)
Adds a dygraph-plot to your DOM (if the DOM is loaded)
Parameters:
Name | Type | Description |
---|---|---|
graph_labels |
Array | Array of strings for the graph legend |
graph_values |
Array | Array of floats to plot (here plotted over time) |
cols |
Array | Array of colours to use for plotting |
title |
String | Title of the plot |
opts |
Object | dictionary-style list of opts to pass onto dygraphs |
- Source:
plotPoints(graph_values, title, opts)
Adds a dygraph-plot to your DOM (if the DOM is loaded)
Parameters:
Name | Type | Description |
---|---|---|
graph_values |
Array | Array of floats to plot (here plotted over time) |
title |
String | Title of the plot |
opts |
Object | dictionary-style list of opts to pass onto dygraphs |
- Source:
plotPopsizes(property, values)
Easy function to add a pop-sizes plot (wrapper for plotArrays)
Parameters:
Name | Type | Description |
---|---|---|
property |
String | What property to plot (needs to exist in your model, e.g. "species" or "alive") |
values |
Array | Which values are plotted (e.g. [1,3,4,6]) |
- Source:
plotXY(graph_labels, graph_values, cols, title, opts)
Adds a dygraph-plot to your DOM (if the DOM is loaded)
Parameters:
Name | Type | Description |
---|---|---|
graph_labels |
Array | Array of strings for the graph legend |
graph_values |
Array | Array of 2 floats to plot (first value for x-axis, second value for y-axis) |
cols |
Array | Array of colours to use for plotting |
title |
String | Title of the plot |
opts |
Object | dictionary-style list of opts to pass onto dygraphs |
- Source:
populateSpot()
Populates the space with individuals in a certain radius from the center
- Source:
rouletteWheel(individuals, property, non)
From a list of individuals, e.g. this.individuals, sample one weighted by a property. This is analogous
to spinning a "roulette wheel". Also see a hard-coded versino of this in the "cheater" example
Parameters:
Name | Type | Default | Description |
---|---|---|---|
individuals |
Array | Array of individuals to sample from (e.g. living individuals in neighbourhood) | |
property |
string | The property used to weigh gps (e.g. fitness) | |
non |
float | 0 | Scales the probability of not returning any gp. |
- Source:
save_flock(filename)
TODO
Saves the current flock a JSON object
Parameters:
Name | Type | Description |
---|---|---|
filename |
string | The name of of the JSON file |
- Source:
set_update_order()
If called for the first time, make an update order (list of ints), otherwise just shuffle it.
- Source:
setupColours(object)
Initiate a dictionary with colour arrays [R,G,B] used by Graph and Canvas classes
Parameters:
Name | Type | Description |
---|---|---|
object |
statecols | given object can be in two forms | either {state:colour} tuple (e.g. 'alive':'white', see gol.html) | or {state:object} where objects are {val:'colour}, | e.g. {'species':{0:"black", 1:"#DDDDDD", 2:"red"}}, see cheater.html |
- Source:
update()
Apart from flocking itself, any updates for the individuals are done here.
By default, nextState is empty. It should be defined by the user (see examples)
- Source: