cacatoo
Version:
Building, exploring, and sharing spatially structured models
2,692 lines (606 loc) • 31.5 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: Flockmodel</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: Flockmodel</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>Flockmodel<span class="signature">(name, config, rng)</span><span class="type-signature"></span></h2>
<div class="class-description">Flockmodel is the second modeltype in Cacatoo, which uses Boids that can interact with a @Gridmodel</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="Flockmodel"><span class="type-signature"></span>new Flockmodel<span class="signature">(name, config, rng)</span><span class="type-signature"></span></h4>
<div class="description">
The constructor function for a @Flockmodl object. Takes the same config dictionary as used in @Simulation
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The name of your model. This is how it will be listed in @Simulation 's properties</td>
</tr>
<tr>
<td class="name"><code>config</code></td>
<td class="type">
<span class="param-type">dictionary</span>
</td>
<td class="description last">A dictionary (object) with all the necessary settings to setup a Cacatoo GridModel.</td>
</tr>
<tr>
<td class="name"><code>rng</code></td>
<td class="type">
<span class="param-type">MersenneTwister</span>
</td>
<td class="description last">A random number generator (MersenneTwister object)</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1625">line 1625</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="colourGradient"><span class="type-signature"></span>colourGradient<span class="signature">(property, n)</span><span class="type-signature"></span></h4>
<div class="description">
Initiate a gradient of colours for a property.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>property</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The name of the property to which the colour is assigned</td>
</tr>
<tr>
<td class="name"><code>n</code></td>
<td class="type">
<span class="param-type">int</span>
</td>
<td class="description last">How many colours the gradient consists off
For example usage, see colourViridis below</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1854">line 1854</a>
</li></ul></dd>
</dl>
<h4 class="name" id="colourGradientArray"><span class="type-signature"></span>colourGradientArray<span class="signature">(property, n)</span><span class="type-signature"></span></h4>
<div class="description">
Initiate a gradient of colours for a property (return array only)
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>property</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The name of the property to which the colour is assigned</td>
</tr>
<tr>
<td class="name"><code>n</code></td>
<td class="type">
<span class="param-type">int</span>
</td>
<td class="description last">How many colours the gradient consists off
For example usage, see colourViridis below</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1817">line 1817</a>
</li></ul></dd>
</dl>
<h4 class="name" id="colourViridis"><span class="type-signature"></span>colourViridis<span class="signature">(property, n, rev)</span><span class="type-signature"></span></h4>
<div class="description">
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)
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>property</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="default">
</td>
<td class="description last">The name of the property to which the colour is assigned</td>
</tr>
<tr>
<td class="name"><code>n</code></td>
<td class="type">
<span class="param-type">int</span>
</td>
<td class="default">
</td>
<td class="description last">How many colours the gradient consists off</td>
</tr>
<tr>
<td class="name"><code>rev</code></td>
<td class="type">
<span class="param-type">bool</span>
</td>
<td class="default">
false
</td>
<td class="description last">Reverse the viridis colour gradient</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1881">line 1881</a>
</li></ul></dd>
</dl>
<h4 class="name" id="flock"><span class="type-signature"></span>flock<span class="signature">(i)</span><span class="type-signature"></span></h4>
<div class="description">
Flocking of individuals, based on X, Y, Z (TODO)
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>i</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">The individual to be updates</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1896">line 1896</a>
</li></ul></dd>
</dl>
<h4 class="name" id="load_flock"><span class="type-signature"></span>load_flock<span class="signature">(file)</span><span class="type-signature"></span></h4>
<div class="description">
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.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>file</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Path to the json file</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1748">line 1748</a>
</li></ul></dd>
</dl>
<h4 class="name" id="perfectMix"><span class="type-signature"></span>perfectMix<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
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.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line2507">line 2507</a>
</li></ul></dd>
</dl>
<h4 class="name" id="plotArray"><span class="type-signature"></span>plotArray<span class="signature">(graph_labels, graph_values, cols, title, opts)</span><span class="type-signature"></span></h4>
<div class="description">
Adds a dygraph-plot to your DOM (if the DOM is loaded)
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>graph_labels</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Array of strings for the graph legend</td>
</tr>
<tr>
<td class="name"><code>graph_values</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Array of floats to plot (here plotted over time)</td>
</tr>
<tr>
<td class="name"><code>cols</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Array of colours to use for plotting</td>
</tr>
<tr>
<td class="name"><code>title</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Title of the plot</td>
</tr>
<tr>
<td class="name"><code>opts</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">dictionary-style list of opts to pass onto dygraphs</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line2527">line 2527</a>
</li></ul></dd>
</dl>
<h4 class="name" id="plotPoints"><span class="type-signature"></span>plotPoints<span class="signature">(graph_values, title, opts)</span><span class="type-signature"></span></h4>
<div class="description">
Adds a dygraph-plot to your DOM (if the DOM is loaded)
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>graph_values</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Array of floats to plot (here plotted over time)</td>
</tr>
<tr>
<td class="name"><code>title</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Title of the plot</td>
</tr>
<tr>
<td class="name"><code>opts</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">dictionary-style list of opts to pass onto dygraphs</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line2553">line 2553</a>
</li></ul></dd>
</dl>
<h4 class="name" id="plotPopsizes"><span class="type-signature"></span>plotPopsizes<span class="signature">(property, values)</span><span class="type-signature"></span></h4>
<div class="description">
Easy function to add a pop-sizes plot (wrapper for plotArrays)
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>property</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">What property to plot (needs to exist in your model, e.g. "species" or "alive")</td>
</tr>
<tr>
<td class="name"><code>values</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Which values are plotted (e.g. [1,3,4,6])</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line2628">line 2628</a>
</li></ul></dd>
</dl>
<h4 class="name" id="plotXY"><span class="type-signature"></span>plotXY<span class="signature">(graph_labels, graph_values, cols, title, opts)</span><span class="type-signature"></span></h4>
<div class="description">
Adds a dygraph-plot to your DOM (if the DOM is loaded)
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>graph_labels</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Array of strings for the graph legend</td>
</tr>
<tr>
<td class="name"><code>graph_values</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Array of 2 floats to plot (first value for x-axis, second value for y-axis)</td>
</tr>
<tr>
<td class="name"><code>cols</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Array of colours to use for plotting</td>
</tr>
<tr>
<td class="name"><code>title</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Title of the plot</td>
</tr>
<tr>
<td class="name"><code>opts</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">dictionary-style list of opts to pass onto dygraphs</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line2606">line 2606</a>
</li></ul></dd>
</dl>
<h4 class="name" id="populateSpot"><span class="type-signature"></span>populateSpot<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Populates the space with individuals in a certain radius from the center
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1695">line 1695</a>
</li></ul></dd>
</dl>
<h4 class="name" id="rouletteWheel"><span class="type-signature"></span>rouletteWheel<span class="signature">(individuals, property, non)</span><span class="type-signature"></span></h4>
<div class="description">
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
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>individuals</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="default">
</td>
<td class="description last">Array of individuals to sample from (e.g. living individuals in neighbourhood)</td>
</tr>
<tr>
<td class="name"><code>property</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="default">
</td>
<td class="description last">The property used to weigh gps (e.g. fitness)</td>
</tr>
<tr>
<td class="name"><code>non</code></td>
<td class="type">
<span class="param-type">float</span>
</td>
<td class="default">
0
</td>
<td class="description last">Scales the probability of not returning any gp.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line2486">line 2486</a>
</li></ul></dd>
</dl>
<h4 class="name" id="save_flock"><span class="type-signature"></span>save_flock<span class="signature">(filename)</span><span class="type-signature"></span></h4>
<div class="description">
TODO
Saves the current flock a JSON object
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>filename</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The name of of the JSON file</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1738">line 1738</a>
</li></ul></dd>
</dl>
<h4 class="name" id="set_update_order"><span class="type-signature"></span>set_update_order<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
If called for the first time, make an update order (list of ints), otherwise just shuffle it.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line2391">line 2391</a>
</li></ul></dd>
</dl>
<h4 class="name" id="setupColours"><span class="type-signature"></span>setupColours<span class="signature">(object)</span><span class="type-signature"></span></h4>
<div class="description">
Initiate a dictionary with colour arrays [R,G,B] used by Graph and Canvas classes
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>object</code></td>
<td class="type">
<span class="param-type">statecols</span>
</td>
<td class="description last">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</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1759">line 1759</a>
</li></ul></dd>
</dl>
<h4 class="name" id="update"><span class="type-signature"></span>update<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
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)
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line2386">line 2386</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Canvas.html">Canvas</a></li><li><a href="Flockmodel.html">Flockmodel</a></li><li><a href="Graph.html">Graph</a></li><li><a href="Gridmodel.html">Gridmodel</a></li><li><a href="Gridpoint.html">Gridpoint</a></li><li><a href="ODE.html">ODE</a></li><li><a href="QuadTree.html">QuadTree</a></li><li><a href="Simulation.html">Simulation</a></li></ul><h3>Global</h3><ul><li><a href="global.html#CopyGridODEs">CopyGridODEs</a></li><li><a href="global.html#MakeGrid">MakeGrid</a></li><li><a href="global.html#copy">copy</a></li><li><a href="global.html#default_colours">default_colours</a></li><li><a href="global.html#dict_reverse">dict_reverse</a></li><li><a href="global.html#get2DFromCanvas">get2DFromCanvas</a></li><li><a href="global.html#hexToRGB">hexToRGB</a></li><li><a href="global.html#nameToRGB">nameToRGB</a></li><li><a href="global.html#parseColours">parseColours</a></li><li><a href="global.html#pause">pause</a></li><li><a href="global.html#random_colours">random_colours</a></li><li><a href="global.html#shuffle">shuffle</a></li><li><a href="global.html#stringToRGB">stringToRGB</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Mar 20 2026 07:30:45 GMT+0100 (Central European Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>