Difference between revisions of "Primitive Operators and Properties"

From Numerus
Jump to navigation Jump to search
 
(17 intermediate revisions by the same user not shown)
Line 18: Line 18:
;scope
;scope
:The scope of a simulator (Capsule, CellMatrix, etc.) Used to look up component values (see the section on scopes, coming soon).
:The scope of a simulator (Capsule, CellMatrix, etc.) Used to look up component values (see the section on scopes, coming soon).
</div></div>
<div id="Self">
<div id="Self">
<div id="_cap_">
<div id="_cap_">
Line 23: Line 24:
;_cap_
;_cap_
:Reference from the scope of a simulator to that simulator.
:Reference from the scope of a simulator to that simulator.
 
</div></div>
===Control Primops===
===Control Primops===
<div id="control">
<div id="control">
Line 31: Line 32:
:If optional string b is provided, it is the body of the message.
:If optional string b is provided, it is the body of the message.
:If optional string t is provided, it is the title of the message.
:If optional string t is provided, it is the title of the message.
</div>
<div id="COUNT">
<div id="COUNT">
;COUNT(fn, l)
;COUNT(fn, l)
:''fn'' is a boolean function of one argument and a ''l'' is list.
:''fn'' is a boolean function of one argument and a ''l'' is list.
:'''Returns''': '''COUNT(f, l)''' applies ''f'' to each element of ''l'' and returns the number of times the result is ''true''.
:'''Returns''': '''COUNT(f, l)''' applies ''f'' to each element of ''l'' and returns the number of times the result is ''true''.
</div>
<div id="DELAY">
<div id="DELAY">
;DELAY(comp, x, [y])
;DELAY(comp, x, [y])
:'''Returns''': the value of component comp delayed by ''x'' time units. Comp is a string naming a stateful component (i.e., stock, variable or sequence).
:'''Returns''': the value of component comp delayed by ''x'' time units. Comp is a string naming a stateful component (i.e., stock, variable or sequence).
:Optional ''y'' is returned if the current time is less than ''x''. If ''y'' is omitted then 0 is returned.
:Optional ''y'' is returned if the current time is less than ''x''. If ''y'' is omitted then 0 is returned.
</div>
<div id="PULSE">
<div id="PULSE">
;PULSE(amount, start, interval)
;PULSE(amount, start, interval)
:'''Returns''': amount when current time is ''start'', ''start + interval'', ''start + 2*interval'', etc.; 0 otherwise
:'''Returns''': amount when current time is ''start'', ''start + interval'', ''start + 2*interval'', etc.; 0 otherwise
</div>
<div id="DELAYN">
<div id="DELAYN">
;DELAYN(comp scale shape init)
;DELAYN(comp scale shape init)
:'''Returns''': the n-th order exponentially smooth delay for component ''comp''. ''comp'' should be a string naming a Stock, Sequence or Term.
:'''Returns''': the n-th order exponentially smooth delay for component ''comp''. ''comp'' should be a string naming a Stock, Sequence or Term.
</div>
<div id="STEP">
<div id="STEP">
;STEP(x, y)
;STEP(x, y)
:'''Returns''': the value of ''x'' if the current time is ''y'' or greater; 0 otherwise.
:'''Returns''': the value of ''x'' if the current time is ''y'' or greater; 0 otherwise.
</div>
<div id="TERMINATE">
<div id="TERMINATE">
;TERMINATE()
;TERMINATE()
:Terminates the running simulation.
:Terminates the running simulation.
</div>
<div id="TOTAL">
<div id="TOTAL">
;TOTAL(fn, l)
;TOTAL(fn, l)
:''fn'' is a numerical function of one argument and a ''l'' is list.
:''fn'' is a numerical function of one argument and a ''l'' is list.
:'''Returns''': '''TOTAL(fn, l)''' applies ''fn'' to each element of ''l'' and returns the sum of the results.
:'''Returns''': '''TOTAL(fn, l)''' applies ''fn'' to each element of ''l'' and returns the sum of the results.
</div>
<div id="RESETTING">
<div id="RESETTING">
;RESETTING()
;RESETTING()
:'''Returns''': true when the system is currently resetting.
:'''Returns''': true when the system is currently resetting.
 
</div>
</div>
===Convenience Primops===
===Convenience Primops===
<div id="convenience">
<div id="convenience">
Line 66: Line 76:
:Simulates a Bernoulli trial.
:Simulates a Bernoulli trial.
:'''Returns''': ''true'' with probability ''p'' and ''false'' with probability ''1-p''.
:'''Returns''': ''true'' with probability ''p'' and ''false'' with probability ''1-p''.
</div>
<div id="BOUNCER">
<div id="BOUNCER">
;BOUNCER(angle, x, y, cols, rows)
;BOUNCER(angle, x, y, cols, rows)
:'''Returns''': the expected angle in one step of a projectile moving on a surface bounded by [''x'', ''cols''] and [''y'', ''rows''], deflecting off of the edge according to the standard laws of physics.
:'''Returns''': the expected angle in one step of a projectile moving on a surface bounded by [''x'', ''cols''] and [''y'', ''rows''], deflecting off of the edge according to the standard laws of physics.
</div>
<div id="NORMALIZE">
<div id="NORMALIZE">
<div id="NORMALIZE02PI">
<div id="NORMALIZE02PI">
Line 74: Line 86:
;NORMALIZE02PI(theta)
;NORMALIZE02PI(theta)
:'''Returns''': angle ''theta'' normalized on the interval [''-π'', ''π'' ] and [''0'', ''2π'' ], respectively.
:'''Returns''': angle ''theta'' normalized on the interval [''-π'', ''π'' ] and [''0'', ''2π'' ], respectively.
 
</div></div></div>
===Input/Output Primops===
===Input/Output Primops===
<div id="io">
<div id="io">
Line 80: Line 92:
;BASEDIR()
;BASEDIR()
:'''Returns''': the current model directory.
:'''Returns''': the current model directory.
</div>
<!--
<!--
<div id="LOAD">
<div id="LOAD">
;LOAD(l)
;LOAD(l)
:''l'' is a list of JavaScript or NovaScript filenames contained in the current model directory. Each is loaded into the runtime system. Should be part of simulation initialization.
:''l'' is a list of JavaScript or NovaScript filenames contained in the current model directory. Each is loaded into the runtime system. Should be part of simulation initialization.
</div>
-->
-->
In each of the following ''path'' designates a textfile. if ''path'' begins with “/” it is treated as an absolute pathname; otherwise it is treated as relative to the current model directory.
In each of the following ''path'' designates a textfile. if ''path'' begins with “/” it is treated as an absolute pathname; otherwise it is treated as relative to the current model directory.
Line 89: Line 103:
;OPENREAD(path)
;OPENREAD(path)
:Opens ''path'' for reading and returns a Java <code>BufferedReader</code> object. The latter contains methods read and readLine to perform input. See http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html for complete details.  
:Opens ''path'' for reading and returns a Java <code>BufferedReader</code> object. The latter contains methods read and readLine to perform input. See http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html for complete details.  
</div>
<div id="OPENWRITE">
<div id="OPENWRITE">
;OPENWRITE(path)
;OPENWRITE(path)
:Opens path for writing and returns a Java <code>PrintWriter</code> object. The latter contains methods <tt>print</tt> and <tt>println</tt> to perform output. See http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html for complete details.
:Opens path for writing and returns a Java <code>PrintWriter</code> object. The latter contains methods <tt>print</tt> and <tt>println</tt> to perform output. See http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html for complete details.
</div>
<div id="READDATA">
<div id="READDATA">
;READDATA(path)
;READDATA(path)
:'''Returns''': the content of the file path as a string.
:'''Returns''': the content of the file path as a string.
</div>
<div id="PRINT">
<div id="PRINT">
;PRINT(x0, x1, ...)
;PRINT(x0, x1, ...)
:'''Returns''': nothing; outputs the values of its arguments to the console, separated by spaces.
:'''Returns''': nothing; outputs the values of its arguments to the console, separated by spaces.
</div>
<div id="math">
<div id="math">
<div id="Math">
<div id="Math">
===Mathematical Properties===
===Mathematical Properties===
Line 109: Line 126:
;PIO2
;PIO2
:Constants <code>π</code>, <code>2π</code> and <code>π/2</code>, respectively
:Constants <code>π</code>, <code>2π</code> and <code>π/2</code>, respectively
</div></div></div>
<div id="MPI">
<div id="MPI">
<div id="MPI2">
<div id="MPI2">
Line 125: Line 143:
;LOG2E
;LOG2E
:Constants <code>ln(10)</code>, <code>ln(2)</code>, <code>log<sub>10</sub>(e)</code> and <code>log<sub>2</sub>(e)</code>
:Constants <code>ln(10)</code>, <code>ln(2)</code>, <code>log<sub>10</sub>(e)</code> and <code>log<sub>2</sub>(e)</code>
</div></div></div></div>
<div id="SQRT1_2">
<div id="SQRT1_2">
<div id="SQRT2">
<div id="SQRT2">
Line 130: Line 149:
;SQRT2
;SQRT2
:Constants <code>1/√<span style="text-decoration:overline;">2</span></code> and <code>√<span style="text-decoration:overline;">2</span></code>, respectively.
:Constants <code>1/√<span style="text-decoration:overline;">2</span></code> and <code>√<span style="text-decoration:overline;">2</span></code>, respectively.
 
</div></div>
===Mathematical Primops===
===Mathematical Primops===
<div id="MathXXX">
<div id="MathXXX">
;Math.XXX
;Math.XXX
:The JavaScript Math functions and constants; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math.
:The JavaScript Math functions and constants; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math.
</div>
<div id="DERIVN">
<div id="DERIVN">
;DERIVN(fn, n)
;DERIVN(fn, n)
:'''Returns''': the value of the ''nth'' derivative of ''fn'' at the current time, with precision based on the value of ''dt''. ''fn'' should be a string naming a State (Stock or Sequence) or Term.
:'''Returns''': the value of the ''nth'' derivative of ''fn'' at the current time, with precision based on the value of ''dt''. ''fn'' should be a string naming a State (Stock or Sequence) or Term.
</div>
<div id="DISTANCE">
<div id="DISTANCE">
;DISTANCE(x0, y0, x1, y1)
;DISTANCE(x0, y0, x1, y1)
:'''Returns''': Euclidean distance between points (''x0, y0'') and (''x1, y1'').
:'''Returns''': Euclidean distance between points (''x0, y0'') and (''x1, y1'').
</div>
<div id="RANDOM">
<div id="RANDOM">
;RANDOM()
;RANDOM()
:'''Returns''': a uniformly distributed random number between 0 and 1.
:'''Returns''': a uniformly distributed random number between 0 and 1.
</div>
<div id="SEED">
<div id="SEED">
;SEED(x)
;SEED(x)
:'''Returns''': nothing; sets the seed of the random number generator. Should be part of simulation initialization.
:'''Returns''': nothing; sets the seed of the random number generator. Should be part of simulation initialization.
</div>
<div id="RANDOM_HEADING">
;RANDOM_HEADING()
:'''Returns''': a uniformly distributed random number between ''-&pi;'' and ''&pi;''.
<div id="BINOMIAL">
<div id="BINOMIAL">
;BINOMIAL(n, p)
;BINOMIAL(n, p)
:''n'' is an integer; ''0 ≤ p ≤ 1''
:''n'' is an integer; ''0 ≤ p ≤ 1''
:'''Returns''': a random number from the binomial distribution with ''n'' trials and success probability ''p''.
:'''Returns''': a random number from the binomial distribution with ''n'' trials and success probability ''p''.
</div>
<div id="MULTIBINOMIAL">
<div id="MULTIBINOMIAL">
;MULTIBINOMIAL(n, p, k)
;MULTIBINOMIAL(n, p, k)
:'''Returns''': Sum of ''k'' independent executions of BINOMIAL(''n'', ''p'').
:'''Returns''': Sum of ''k'' independent executions of BINOMIAL(''n'', ''p'').
</div>
<div id="MULTINOMIAL">
<div id="MULTINOMIAL">
;MULTINOMIAL(n, [p0, p1, ... pm])
;MULTINOMIAL(n, [p0, p1, ... pm])
:'''Returns''': an ''m''-element vector of outcomes from performing ''n'' independent generalized Bernoulli trials. ''As of Version 13.5.''
:'''Returns''': an ''m''-element vector of outcomes from performing ''n'' independent generalized Bernoulli trials.
</div>
<div id="SELECT">
;SELECT([s0,...,sm], [p0, .... pm])
:A single generalized Bernoulli trial over the states ''s0, ... sm'' with respective probabilities ''p0, ... pm''.
:'''Returns''': One of the values ''si'' with probability ''pi''. Note:  if the probabilities do not sum to 1, ''pm'' is increased accordingly
</div>
<div id="NORMAL">
<div id="NORMAL">
;NORMAL(x, y)
;NORMAL(x, y)
:'''Returns''': a random number from the normal distribution with mean x and standard deviation y.
:'''Returns''': a random number from the normal distribution with mean x and standard deviation y.
</div>
<div id="POISSON">
<div id="POISSON">
;POISSON(lambda)
;POISSON(lambda)
:'''Returns''': a random number from the Poisson distribution with density lambda.
:'''Returns''': a random number from the Poisson distribution with density lambda.
</div>
<div id="UNIFORM">
<div id="UNIFORM">
;UNIFORM(x, y)
;UNIFORM(x, y)
:'''Returns''': a uniformly distributed random variable between ''x'' and ''y''.
:'''Returns''': a uniformly distributed random variable between ''x'' and ''y''.
</div>
<div id="SIN">
<div id="SIN">
;SIN(x)
;SIN(x)
:'''Returns''': the trigonometric sin of ''x''.
:'''Returns''': the trigonometric sin of ''x''.
</div>
<div id="SINWAVE">
<div id="SINWAVE">
;SINWAVE(x, y)
;SINWAVE(x, y)
:'''Returns''': <code>x*sin(2πt/y)</code>, where ''t'' is the current time.
:'''Returns''': <code>x*sin(2πt/y)</code>, where ''t'' is the current time.
</div>
<div id="COS">
<div id="COS">
;COS(x)
;COS(x)
:'''Returns''': the trigonometric cosine of ''x''.
:'''Returns''': the trigonometric cosine of ''x''.
</div>
<div id="COSWAVE">
<div id="COSWAVE">
;COSWAVE(x)
;COSWAVE(x)
:'''Returns''': <code>x*cos(2πt/y)</code>, where ''t'' is the current time.
:'''Returns''': <code>x*cos(2πt/y)</code>, where ''t'' is the current time.
</div>
<div id="TAN">
<div id="TAN">
;TAN(x)
;TAN(x)
:'''Returns''': the trigonometric tangent of ''x''.
:'''Returns''': the trigonometric tangent of ''x''.
</div>
<div id="ACOS">
<div id="ACOS">
;ACOS(x)
;ACOS(x)
:'''Returns''' the trigonometric arccosine of ''x''.
:'''Returns''' the trigonometric arccosine of ''x''.
</div>
<div id="ASIN">
<div id="ASIN">
;ASIN(x)
;ASIN(x)
:'''Returns''' the trigonometric arcsine of ''x''.
:'''Returns''' the trigonometric arcsine of ''x''.
</div>
<div id="ATAN">
<div id="ATAN">
;ATAN(x)
;ATAN(x)
:'''Returns''': the trigonometric arctangent of ''x''.
:'''Returns''': the trigonometric arctangent of ''x''.
</div>
<div id="ATAN2">
<div id="ATAN2">
;ATAN2(y, x)
;ATAN2(y, x)
:'''Returns''': the trigonometric tangent of <code>y/x</code>.
:'''Returns''': the trigonometric tangent of <code>y/x</code>.
</div>
<div id="MIN">
<div id="MIN">
<div id="MAX">
<div id="MAX">
Line 198: Line 245:
;MAX(x, y, z, ...)
;MAX(x, y, z, ...)
:'''Returns''':, respectively, the lowest or highest value in a list of arguments:
:'''Returns''':, respectively, the lowest or highest value in a list of arguments:
</div>
</div>
<div id="CEIL">
<div id="CEIL">
<div id="FLOOR">
<div id="FLOOR">
Line 205: Line 254:
;ROUND(x);
;ROUND(x);
:'''Returns''':, respectively, ''x'' rounded up, ''x'' rounded down, and ''x'' rounded to the nearest integer.
:'''Returns''':, respectively, ''x'' rounded up, ''x'' rounded down, and ''x'' rounded to the nearest integer.
</div>
</div>
</div>
<div id="SQRT">
<div id="SQRT">
;SQRT(x)
;SQRT(x)
:'''Returns''': <code>&radic;<span style="text-decoration:overline;">x</span></code>
:'''Returns''': <code>&radic;<span style="text-decoration:overline;">x</span></code>
</div>
<div id="ABS">
<div id="ABS">
;ABS(x)
;ABS(x)
:'''Returns''': <code>|x|</code>
:'''Returns''': <code>|x|</code>
</div>
<div id="POW">
<div id="POW">
;POW(x, y)
;POW(x, y)
:'''Returns''': <code>x<sup>y</sup></code>
:'''Returns''': <code>x<sup>y</sup></code>
</div>
<div id="EXP">
<div id="EXP">
;EXP(x)
;EXP(x)
:'''Returns''': <code>e<sup>x</sup></code>
:'''Returns''': <code>e<sup>x</sup></code>
</div>
<div id="LOG">
<div id="LOG">
;LOG(x)
;LOG(x)
:'''Returns''': <code>ln(x)</code>
:'''Returns''': <code>ln(x)</code>
</div>
<div id="LOG2">
<div id="LOG2">
;LOG2(x)
;LOG2(x)
:'''Returns''': <code>log<sub>2</sub>(x)</code>
:'''Returns''': <code>log<sub>2</sub>(x)</code>
</div>
<div id="LOG10">
<div id="LOG10">
;LOG10(x)
;LOG10(x)
:'''Returns''': <code>log<sub>10</sub>(x)</code>
:'''Returns''': <code>log<sub>10</sub>(x)</code>
</div>
<div id="ARRAYSUM">
<div id="ARRAYSUM">
;ARRAYSUM(a)
;ARRAYSUM(a)
:'''Returns''': the sum of the elements in array ''a''.
:'''Returns''': the sum of the elements in array ''a''.
</div>
<div id="ARRAYOF">
<div id="ARRAYOF">
;ARRAYOF(n, x)
;ARRAYOF(n, x)
:'''Returns''': an array of length ''n'' filled with ''x''.
:'''Returns''': an array of length ''n'' filled with ''x''.
</div>
<div id="WRAPXM">
<div id="WRAPXM">
;WRAPXM(v, m)
;WRAPXM(v, m)
:'''Returns''': <code>''v'' mod ''m''</code> normalized to [''0'', ''m''].
:'''Returns''': <code>''v'' mod ''m''</code> normalized to [''0'', ''m''].
</div>
<div id="FIXAT">
<div id="FIXAT">
;FIXAT(n, d)
;FIXAT(n, d)
:'''Returns''': Number ''n'' with at most ''d'' decimal places.
:'''Returns''': Number ''n'' with at most ''d'' decimal places.
</div>
<div id="FACT">
<div id="FACT">
;FACT(n)
;FACT(n)
:'''Returns''': The factorial of ''n'', using Stirling's formula for ''n > 20''.
:'''Returns''': The factorial of ''n'', using Stirling's formula for ''n > 20''.
</div>
<div id="GRAPHFUN">
<div id="GRAPHFUN">
;GRAPHFUN([[x0, y0], [x1, y1], ...])
;GRAPHFUN([[x0, y0], [x1, y1], ...])
;GRAPHFUN([x0, y0], [x1, y1], ...)
;GRAPHFUN([x0, y0], [x1, y1], ...)
:'''Returns''': A function based on the graph defined by the ordered pairs in the argument, interpolated linearly. Acceptable input can be single argument consisting of an array of ordered pairs, or multiple arguments, each an ordered pair. The list need not be in increasing order of ''x''. The returned function maps any value smaller (greater) than the smallest (largest) domain value ''x<sub>k</sub>'' to ''x<sub>k</sub>'' 's value in the range.
:'''Returns''': A function based on the graph defined by the ordered pairs in the argument, interpolated linearly. Acceptable input can be single argument consisting of an array of ordered pairs, or multiple arguments, each an ordered pair. The list need not be in increasing order of ''x''. The returned function maps any value smaller (greater) than the smallest (largest) domain value ''x<sub>k</sub>'' to ''x<sub>k</sub>'' 's value in the range.
</div>


===Matrix Primops===
===Matrix Primops===
Line 251: Line 316:
:''tab'' is a 2-dimensional array derived from a table, where the first row contains column headers.
:''tab'' is a 2-dimensional array derived from a table, where the first row contains column headers.
:'''Returns''': an object in which each property name is a column header with property value an array comprising the corresponding column.
:'''Returns''': an object in which each property name is a column header with property value an array comprising the corresponding column.
</div>
<div id="CSVTOMAT">
<div id="CSVTOMAT">
;CSVTOMAT(csv)
;CSVTOMAT(csv)
:''csv'' is a string where line is a comma separated sequence of values.
:''csv'' is a string where line is a comma separated sequence of values.
:'''Returns''': the matrix in which each row corresponds to a line in ''csv''.
:'''Returns''': the matrix in which each row corresponds to a line in ''csv''.
</div>
<div id="ROWSTOOBJS">
<div id="ROWSTOOBJS">
;ROWSTOOBJS(tab)
;ROWSTOOBJS(tab)
:''tab'' is a 2-dimensional array derived from a table, where the first row contains column headers.
:''tab'' is a 2-dimensional array derived from a table, where the first row contains column headers.
:'''Returns''': an array of objects, one for each non-header row. In each object properties are column headers bound to the entry for that column in the corresponding row.
:'''Returns''': an array of objects, one for each non-header row. In each object properties are column headers bound to the entry for that column in the corresponding row.
</div>
<div id="TRANSPOSE">
<div id="TRANSPOSE">
;TRANSPOSE(mat)
;TRANSPOSE(mat)
:''mat'' is a matrix (i.e. 2-dimensional array)
:''mat'' is a matrix (i.e. 2-dimensional array)
:'''Returns''': the transpose of ''mat''.
:'''Returns''': the transpose of ''mat''.
</div>


===Simulation Primops===
===Simulation Primops===
Line 300: Line 369:
;_.XXX
;_.XXX
:The underscore.js library of useful functions. See http://underscorejs.org.
:The underscore.js library of useful functions. See http://underscorejs.org.
</div>
<div id="ASVALUE">
;ASVALUE(v)
:Required when supplying an array or function value to the input pin of an aggregator. Arrays supplied as input to aggregators are usually interpreted so that each array element is used as input for one of the elements of the aggregator. Similarly, functions are invoked on the id of each element to compute the input value for that element. An array or function wrapped with ASVALUE is sent intact to each element of the aggregator.
</div>
<div id="DEPENDSON">
<div id="DEPENDSON">
;DEPENDSON(comp)
;DEPENDSON(comp)
:'''Returns''': 0. This is used during model construction to assert dependencies.
:'''Returns''': 0. This is used during model construction to assert dependencies.
</div>
<div id="DISTRIBUTE">
<div id="DISTRIBUTE">
;DISTRIBUTE(a)
;DISTRIBUTE(a)
:'''Returns''': if ''a'' is an array of at most 3 dimensions, DISTRIBUTE returns a function ''f'' which takes as many arguments as the dimension of ''a'' and returns the selected value. Otherwise ''f'' is a function of no arguments that return ''a''.
:'''Returns''': if ''a'' is an array of at most 3 dimensions, DISTRIBUTE returns a function ''f'' which takes as many arguments as the dimension of ''a'' and returns the selected value. Otherwise ''f'' is a function of no arguments that return ''a''.
</div>
<div id="LOOKUP_AREA">
<div id="LOOKUP_AREA">
;LOOKUP_AREA(term, lo, hi)
;LOOKUP_AREA(term, lo, hi)
:'''Returns''': the integral of component ''term'' on the interval [''lo'', ''hi'']. ''term'' is a string naming a Term.
:'''Returns''': the integral of component ''term'' on the interval [''lo'', ''hi'']. ''term'' is a string naming a Term.
</div>
<!--
<!--
==Clocked Chip Primops==
==Clocked Chip Primops==
Line 316: Line 393:
;SUPERCLOCK()
;SUPERCLOCK()
:'''Returns''': the clock associated with the container of the Clocked Chip.
:'''Returns''': the clock associated with the container of the Clocked Chip.
</div>
<div id="SUPERTIME">
<div id="SUPERTIME">
;SUPERTIME()
;SUPERTIME()
:'''Returns''': the model time of the container of the Clocked Chip.
:'''Returns''': the model time of the container of the Clocked Chip.
</div>
</div>
-->
-->


Line 331: Line 411:
;coords
;coords
:Object whose row and col properties respectively reference the caller’s row and column coordinates within the CellMatrix.
:Object whose row and col properties respectively reference the caller’s row and column coordinates within the CellMatrix.
</div>
<div id="rows">
<div id="rows">
<div id="cols">
<div id="cols">
Line 336: Line 417:
;cols
;cols
:Bound to the total number of rows and columns, respectively.
:Bound to the total number of rows and columns, respectively.
</div>
</div>
<div id="matrix">
<div id="matrix">
;matrix
;matrix
:Bound to the 2 dimensional array of cells in a CellMatrix
:Bound to the 2 dimensional array of cells in a CellMatrix
</div>


===Primops===
===Primops===
Line 346: Line 430:
;BLOCK(n, [wrap])
;BLOCK(n, [wrap])
:'''Returns''': a list (array) of coordinate objects (i.e., containing row and col properties) comprising the square block of cells ''n'' units away from the caller or less. (if ''wrap'' is true, BLOCK treats the surface as a torus).
:'''Returns''': a list (array) of coordinate objects (i.e., containing row and col properties) comprising the square block of cells ''n'' units away from the caller or less. (if ''wrap'' is true, BLOCK treats the surface as a torus).
</div>
</div>
</div>
<div id="CELL">
<div id="CELL">
;CELL(row, col)
;CELL(row, col)
;CELL(coords)
;CELL(coords)
:'''Returns''' the scope for the cell at the given coordinates, which may be passed either as separate parameters or in a coords object. The fields of the scope bind each of the Stocks, Terms and Flows in the cell to the current value of the corresponding component.
:'''Returns''' the scope for the cell at the given coordinates, which may be passed either as separate parameters or in a coords object. The fields of the scope bind each of the Stocks, Terms and Flows in the cell to the current value of the corresponding component.
</div>
<div id="CELLS">
<div id="CELLS">
;CELLS()
;CELLS()
Line 355: Line 443:


   CELLS()[row][col] == CELL(row, col).
   CELLS()[row][col] == CELL(row, col).
</div>
<div id="CELL_VALUE">
<div id="CELL_VALUE">
;CELL_VALUE(row, col, comp)
;CELL_VALUE(row, col, comp)
Line 361: Line 450:
:'''Returns''': the current value of that component in the cell with the given coordinates.
:'''Returns''': the current value of that component in the cell with the given coordinates.
   CELL VALUE(row, col, comp) == CELL(row, col)[comp]
   CELL VALUE(row, col, comp) == CELL(row, col)[comp]
</div>
<div id="RING">
<div id="RING">
;RING(n, [wrap])
;RING(n, [wrap])
:'''Returns''': a list (array) of coordinate objects (i.e., containing row and col properties) for all cells comprising the square exactly ''n'' units away from the caller. (if ''wrap'' is true, RING treats the surface as a torus).
:'''Returns''': a list (array) of coordinate objects (i.e., containing row and col properties) for all cells comprising the square exactly ''n'' units away from the caller. (if ''wrap'' is true, RING treats the surface as a torus).
</div>
<div id="WRAP">
<div id="WRAP">
;WRAP(row, col)
;WRAP(row, col)
;WRAP(coords)
;WRAP(coords)
:Performs a “wraparound” of the coordinates if they exceed the size of the matrix (or are negative). Returns an array containing the new row and column.
:Performs a “wraparound” of the coordinates if they exceed the size of the matrix (or are negative). Returns an array containing the new row and column.
</div>
</div>


===Hexagonal Primops===
===Hexagonal Primops===
Line 375: Line 468:
;HEXRING(n, [wrap])
;HEXRING(n, [wrap])
:'''Returns''': a list (array) of coordinate objects (i.e., containing ''row'' and ''col'' properties) for all cells comprising the hexagon exactly ''n'' units away from the caller. (If wrap is true, HEXRING treats the surface as a torus.)
:'''Returns''': a list (array) of coordinate objects (i.e., containing ''row'' and ''col'' properties) for all cells comprising the hexagon exactly ''n'' units away from the caller. (If wrap is true, HEXRING treats the surface as a torus.)
</div>
<div id="HEXBLOCK">
<div id="HEXBLOCK">
;HEXBLOCK(n, [wrap])
;HEXBLOCK(n, [wrap])
:'''Returns''': a list (array) of coordinate objects (i.e., containing ''row'' and ''col'' properties) comprising the hexagonal block of cells ''n'' units away from the caller or less. (If wrap is true, HEXBLOCK treats the surface as a torus.)
:'''Returns''': a list (array) of coordinate objects (i.e., containing ''row'' and ''col'' properties) comprising the hexagonal block of cells ''n'' units away from the caller or less. (If wrap is true, HEXBLOCK treats the surface as a torus.)
</div>
<div id="HEXPATH">
<div id="HEXPATH">
<!--
<!--
Line 383: Line 478:
:'''Returns''': a list of coordinates comprising the path of length ''dist'' in the direction indicated by ''dir''. Directions are denoted by compass directions; i.e., “N”, “NE”, “SE”, “S”, “SW”, “NW”.
:'''Returns''': a list of coordinates comprising the path of length ''dist'' in the direction indicated by ''dir''. Directions are denoted by compass directions; i.e., “N”, “NE”, “SE”, “S”, “SW”, “NW”.
-->
-->
 
</div>
</div>
===Convenience Primops===
===Convenience Primops===
<div id="cell_conv">
<div id="cell_conv">
Line 391: Line 487:
:''l'' is a list of cell scopes objects, comp is a string naming a component in those cells (stock, term, flow, etc.), and value is any JavaScript data element.
:''l'' is a list of cell scopes objects, comp is a string naming a component in those cells (stock, term, flow, etc.), and value is any JavaScript data element.
:'''Returns''':  Returns the number of objects in ''l'' for which the current value of comp is value.  
:'''Returns''':  Returns the number of objects in ''l'' for which the current value of comp is value.  
</div>
<div id="ALL_CELLS">
<div id="ALL_CELLS">
<div id="NO_CELL">
<div id="NO_CELL">
Line 399: Line 496:
:''l'' is a list of cell scopes, comp is a string naming a component in those cells (stock, term, flow, etc.), and value is any JavaScript data element.
:''l'' is a list of cell scopes, comp is a string naming a component in those cells (stock, term, flow, etc.), and value is any JavaScript data element.
:'''Returns''':  Respectively returns ''true'' if for all, none or some scopes in ''l'' the current value of comp is value; ''false'' otherwise.
:'''Returns''':  Respectively returns ''true'' if for all, none or some scopes in ''l'' the current value of comp is value; ''false'' otherwise.
</div>
</div>
</div>
</div>


==Agent Properties and Primops==
==Agent Properties and Primops==
Line 409: Line 510:
;birth
;birth
:The point in model time at which the caller was created.
:The point in model time at which the caller was created.
</div>
<div id="myId">
<div id="myId">
;myId
;myId
:The unique agent ID that has been assigned to the caller.
:The unique agent ID that has been assigned to the caller.
</div>
<div id="rows">
<div id="rows">
<div id="cols">
<div id="cols">
Line 420: Line 523:
:Bound to the total number of rows and columns in the space occupied by this AgentVector. Planes returns 0
:Bound to the total number of rows and columns in the space occupied by this AgentVector. Planes returns 0
unless space is 3d.
unless space is 3d.
</div>
</div>
</div>
<div id="vector">
<div id="vector">
;vector
;vector
:Bound to the object mapping agent ids to agents in an AgentVector
:Bound to the object mapping agent ids to agents in an AgentVector
</div>
</div>


===Primops===
===Primops===
Line 429: Line 537:
;ADATA(s)
;ADATA(s)
:'''Returns''': if ''s = "AGENTIDS"'', then ADATA returns the current list of agents; if ''s == "AGENTCOUNT"'', then ADATA returns the current agent count. Used to extract data from AgentVectors.
:'''Returns''': if ''s = "AGENTIDS"'', then ADATA returns the current list of agents; if ''s == "AGENTCOUNT"'', then ADATA returns the current agent count. Used to extract data from AgentVectors.
</div></div>
<div id="AGE">
<div id="AGE">
<div id="MYAGE">
<div id="MYAGE">
Line 434: Line 543:
;MYAGE()
;MYAGE()
:'''Returns''': the age (i.e., time since birth) of agent ''id'', or of the caller, respectively.
:'''Returns''': the age (i.e., time since birth) of agent ''id'', or of the caller, respectively.
</div>
</div>
<div id="AGENT">
<div id="AGENT">
;AGENT(id)
;AGENT(id)
:'''Returns''': the scope of the agent identified by ''id,'' if it exists.
:'''Returns''': the scope of the agent identified by ''id,'' if it exists.
</div>
<div id="AGENTS">
<div id="AGENTS">
;AGENTS()
;AGENTS()
:'''Returns''': the list of live agent scopes.
:'''Returns''': the list of live agent scopes.
</div>
<div id="AGENTS_AT">
<div id="AGENTS_AT">
;AGENTS_AT(row, col)
;AGENTS_AT(row, col)
;AGENTS_AT(coords)
;AGENTS_AT(coords)
:'''Returns''': a list of agents contained in the cell at specified coordinates.
:'''Returns''': a list of agents contained in the cell at specified coordinates.
</div>
<div id="AGENT_COUNT">
<div id="AGENT_COUNT">
;AGENT_COUNT()
;AGENT_COUNT()
:'''Returns''': the total number of agents.
:'''Returns''': the total number of agents.
</div>
<div id="AGENT_IDS">
<div id="AGENT_IDS">
;AGENT_IDS()
;AGENT_IDS()
:'''Returns''': the array of ids for currently living agents.
:'''Returns''': the array of ids for currently living agents.
</div>
<div id="AGENT_VALUE">
<div id="AGENT_VALUE">
;AGENT_VALUE(id, comp)
;AGENT_VALUE(id, comp)
Line 456: Line 572:


     AGENT VALUE(id, comp) == AGENT(id)[comp]
     AGENT VALUE(id, comp) == AGENT(id)[comp]
</div>
<div id="CELL_COORDS">
<div id="CELL_COORDS">
;CELL_COORDS(id)
;CELL_COORDS(id)
:'''Returns''': a coords object containing the ''row/col'' coordinates of the current position of the agent identified by ''id''.  If ''id'' is omitted, returns the ''row/col'' coordinates of the caller.
:'''Returns''': a coords object containing the ''row/col'' coordinates of the current position of the agent identified by ''id''.  If ''id'' is omitted, returns the ''row/col'' coordinates of the caller.
</div>
<div id="CREATE">
<div id="CREATE">
;CREATE([init], [n])
;CREATE([init], [n])
:Schedules the creation of a ''n'' new agents (''n'' is assumed to be 1 if omitted). ''init'' is an initializer object containing bindings for properties in the new agent. These may include ''init_x,'' ''init_ y'' and ''init_heading'', to indicate the new agent’s initial position and direction. It may also include alternate initialization expressions for Stocks, Local Variables and Properties. If ''init'' is omitted, the new agent is a clone of the caller. All new agents are created at the end of the cycle.
:Schedules the creation of a ''n'' new agents (''n'' is assumed to be 1 if omitted). ''init'' is an initializer object containing bindings for properties in the new agent. These may include ''init_x,'' ''init_ y'' and ''init_heading'', to indicate the new agent’s initial position and direction. It may also include alternate initialization expressions for Stocks, Local Variables and Properties. If ''init'' is omitted, the new agent is a clone of the caller. All new agents are created at the end of the cycle.
</div>
<div id="KILL">
<div id="KILL">
;KILL(id)
;KILL(id)
:Schedules the elimination of agent ''id''. All agent eliminations are carried out at the end of the cycle.
:Schedules the elimination of agent ''id''. All agent eliminations are carried out at the end of the cycle.
</div>
<div id="LOCATION">
<div id="LOCATION">
;LOCATION(id)
;LOCATION(id)
:'''Returns''': the cartesian location of the agent identified by id in an object with properties x and y (and z if the space is 3-dimensional), and the current heading of the agent with property theta.  If id is omitted, returns these data for the caller.
:'''Returns''': the cartesian location of the agent identified by id in an object with properties x and y (and z if the space is 3-dimensional), and the current heading of the agent with property theta.  If id is omitted, returns these data for the caller.
</div>
<div id="LWRAP">
<div id="LWRAP">
;LWRAP(x, y)
;LWRAP(x, y)
Line 473: Line 594:
:Performs a “wraparound” of the location if either coordinate exceeds the size of the agent coordinate space (or is negative).
:Performs a “wraparound” of the location if either coordinate exceeds the size of the agent coordinate space (or is negative).
:'''Returns''': an array containing the new ''x'' and ''y'';
:'''Returns''': an array containing the new ''x'' and ''y'';
</div>
<div id="AGENTBLOCK">
<div id="AGENTBLOCK">
;AGENTBLOCK(n, [sort])
;AGENTBLOCK(n, [sort])
:'''Returns''': a list of the scopes of all agents within a block of ''n'' units from the caller. If ''sort'' is true the list is sorted based on distance from the caller.
:'''Returns''': a list of the scopes of all agents within a block of ''n'' units from the caller. If ''sort'' is true the list is sorted based on distance from the caller.
</div>
<div id="HEXAGENTBLOCK">
<div id="HEXAGENTBLOCK">
;HEXAGENTBLOCK(n, [sort])
;HEXAGENTBLOCK(n, [sort])
:'''Returns''': a list of the scopes of all agents within a block of ''n'' units from the caller on a hexagonal surface. If ''sort'' is true the list is sorted based on distance from the caller.
:'''Returns''': a list of the scopes of all agents within a block of ''n'' units from the caller on a hexagonal surface. If ''sort'' is true the list is sorted based on distance from the caller.
</div>
<div id="NEIGHBORS">
<div id="NEIGHBORS">
;NEIGHBORS(n)
;NEIGHBORS(n)
:'''Returns''': a sorted list (based on distance from the caller) of the scopes of all other agents within ''n'' units of the caller.
:'''Returns''': a sorted list (based on distance from the caller) of the scopes of all other agents within ''n'' units of the caller.
</div>
<div id="HEXNEIGHBORS">
<div id="HEXNEIGHBORS">
;HEXNEIGHBORS(n)
;HEXNEIGHBORS(n)
:'''Returns''': a list of the scopes of all agents within ''n'' units of the caller on a hexagonal surface.
:'''Returns''': a list of the scopes of all agents within ''n'' units of the caller on a hexagonal surface.
</div>
<div id="NEAREST_NEIGHBOR">
<div id="NEAREST_NEIGHBOR">
;NEAREST_NEIGHBOR(n)
;NEAREST_NEIGHBOR(n)
:'''Returns''': the scope of the nearest neighbor within ''n'' units of the caller.
:'''Returns''': the scope of the nearest neighbor within ''n'' units of the caller.
</div>
<div id="MOVE">
<div id="MOVE">
<div id="MOVETO">
<div id="MOVETO">
Line 493: Line 620:
;MOVETO(x, y, [z])
;MOVETO(x, y, [z])
:Sets the location of the caller to (''x, y''), or (''x, y, z'') in 3 dimensions. All moves occur at the end of the cycle.
:Sets the location of the caller to (''x, y''), or (''x, y, z'') in 3 dimensions. All moves occur at the end of the cycle.
</div>
</div>
<div id="MOVEPLUS">
<div id="MOVEPLUS">
;MOVEPLUS(x, y, [z])
;MOVEPLUS(x, y, [z])
:Sets the location of the caller to its current location plus (''x, y''), or (''x, y, z'') in 3 dimensions.  
:Sets the location of the caller to its current location plus (''x, y''), or (''x, y, z'') in 3 dimensions.  
</div>
<div id="HEADTO">
<div id="HEADTO">
<div id="SET_HEADING">
<div id="SET_HEADING">
;HEADTO(theta, [phi])
;HEADTO(theta, [phi])
;SET_HEADING(theta, [phi])
;SET_HEADING(theta, [phi])
:Sets the directional heading(s) of the caller to ''theta'' (and ''phi'' in 3 dimensions). Angles are given in radians.<div id="HEADPLUS">
:Sets the directional heading(s) of the caller to ''theta'' (and ''phi'' in 3 dimensions). Angles are given in radians.
</div>
</div>
<div id="HEADPLUS">
;HEADPLUS(theta, [phi])
;HEADPLUS(theta, [phi])
:Sets the directional heading(s) of the caller to its current direction(s) plus ''theta'' (and ''phi'' in 3 dimensions). Angles are given in radians.
:Sets the directional heading(s) of the caller to its current direction(s) plus ''theta'' (and ''phi'' in 3 dimensions). Angles are given in radians.
</div>
<div id="GO">
<div id="GO">
;GO(speed, theta, [,phi])
;GO(speed, theta, [,phi])
:Move the location of the caller to its new location based the given ''speed'' using directional angle(s) ''theta'' (and ''phi'' in 3 dimensions). Angles are given in radians.
:Move the location of the caller to its new location based the given ''speed'' using directional angle(s) ''theta'' (and ''phi'' in 3 dimensions). Angles are given in radians.
<div id="HEXMOVE">
</div>
<div id="GO_BOUNCE">
;GO_BOUNCE(speed, theta)
:Equivalent to <tt>GO(speed, theta)</tt> except that the agent bounces off the edge of the space like a billiard ball. Currently only available in 2 dimensions.
</div><div id="HEXMOVE">
;HEXMOVE(speed, theta)
;HEXMOVE(speed, theta)
:Move the location of the caller to its new location based on the given ''speed'' and direction ''theta''. ''Theta'' is one of ''N'',''NE'',''SE'',''S'',''SW'',''NW''.
:Move the location of the caller to its new location based on the given ''speed'' and direction ''theta''. ''Theta'' is one of ''N'',''NE'',''SE'',''S'',''SW'',''NW''.
</div>


===Convenience Primops===
===Convenience Primops===
<div id="agent_conv">
<div id="agent_conv">
These primops perform useful functions that could otherwise be programmed.
These primops perform useful functions that could otherwise be programmed.
</div>
<div id="COUNT_AGENTS">
<div id="COUNT_AGENTS">
;COUNT_AGENTS(l, comp, value)
;COUNT_AGENTS(l, comp, value)
:''l'' is a list of agent scopes, ''comp'' is a string naming a component in those agents (stock, term, flow, etc.), and ''value'' is any JavaScript data element.
:''l'' is a list of agent scopes, ''comp'' is a string naming a component in those agents (stock, term, flow, etc.), and ''value'' is any JavaScript data element.
:'''Returns''':  Returns the number of objects in ''l'' for which the current value of ''comp'' is ''value''.  
:'''Returns''':  Returns the number of objects in ''l'' for which the current value of ''comp'' is ''value''.  
</div>
<div id="ALL_AGENTS">
<div id="ALL_AGENTS">
<div id="NO_AGENTS">
<div id="NO_AGENT">
<div id="SOME_AGENT">
<div id="SOME_AGENT">
;ALL_AGENTS(l, comp, value)
;ALL_AGENTS(l, comp, value)
Line 525: Line 666:
:''l'' is a list of agent scopes, ''comp'' is a string naming a component in those agents, and ''value'' is any JavaScript data element.
:''l'' is a list of agent scopes, ''comp'' is a string naming a component in those agents, and ''value'' is any JavaScript data element.
:'''Returns''':  Respectively returns ''true'' if for all, none or some scope in ''l'' the current value of  ''comp'' is ''value''; ''false'' otherwise.  
:'''Returns''':  Respectively returns ''true'' if for all, none or some scope in ''l'' the current value of  ''comp'' is ''value''; ''false'' otherwise.  
</div></div></div>
<div id="ALL_NEIGHBORS">
<div id="NO_NEIGHBORS">
<div id="SOME_NEIGHBOR">
;ALL_NEIGHBORS(d, comp, value)
;NO_NEIGHBOR(d, comp, value)
;SOME_NEIGHBOR(d, comp, value)
:Analogous to ALL_AGENTS, etc. except the agents of interest are those within a radius of ''d'' units from the agent making the call. Forms that list of agents and returns ''true'' if for all, none, or some agent scope in that list the current value of ''comp'' is '' value''; ''false'' otherwise.
</div></div></div>
<div id="RANDOM_MOVE">
<div id="RANDOM_MOVE">
;RANDOM_MOVE(loc, [wrap])
;RANDOM_MOVE(loc, [wrap])
:'''Returns''': a location object (i.e., with fields ''x'' and ''y'') representing a random move (wrapping if wrap is true) of one unit from the location object ''loc''. If ''loc'' is omitted it defaults to the location of the caller.
:'''Returns''': a location object (i.e., with fields ''x'' and ''y'') representing a random move (wrapping if wrap is true) of one unit from the location object ''loc''. If ''loc'' is omitted it defaults to the location of the caller.
</div>
<div id="HEX_RANDOM_MOVE">
<div id="HEX_RANDOM_MOVE">
;HEX_RANDOM_MOVE(loc, [wrap])
;HEX_RANDOM_MOVE(loc, [wrap])
:'''Returns''': a location object (i.e., with fields ''x'' and ''y'') representing a random move (wrapping if wrap is true) of one unit from the location object ''loc'' on a hexagonal surface. If ''loc'' is omitted it defaults to the location of the caller.
:'''Returns''': a location object (i.e., with fields ''x'' and ''y'') representing a random move (wrapping if wrap is true) of one unit from the location object ''loc'' on a hexagonal surface. If ''loc'' is omitted it defaults to the location of the caller.
</div>
<div id="INBOUNDS">
<div id="INBOUNDS">
;INBOUNDS(x, y)
;INBOUNDS(x, y)
:'''Returns''': true if ''0 ≤ x < columns'' and ''0 ≤ y < rows'', where [''columns'', ''rows''] is the dimension of the agent landscape.
:'''Returns''': true if ''0 ≤ x < columns'' and ''0 ≤ y < rows'', where [''columns'', ''rows''] is the dimension of the agent landscape.
 
</div>
<div id="simworld">
<div id="simworld">


Line 541: Line 693:
;cellmatrix
;cellmatrix
:Bound to the CellMatrix component in a SimWorld
:Bound to the CellMatrix component in a SimWorld
</div>
<div id="agentvector">
<div id="agentvector">
;agentvector
;agentvector
:Bound to the AgentVector component in a SimWorld
:Bound to the AgentVector component in a SimWorld
</div>


==SimWorld Primops==
==SimWorld Primops==
Line 565: Line 719:
;MYAGENTS()
;MYAGENTS()
:'''Returns''': the list of agents currently contained in the caller.
:'''Returns''': the list of agents currently contained in the caller.
</div>
<div id="MYAGENT_COUNT">
<div id="MYAGENT_COUNT">
;MYAGENT_COUNT()
;MYAGENT_COUNT()
:'''Returns''': the number of agents currently contained in the caller.
:'''Returns''': the number of agents currently contained in the caller.
 
</div>
===Agent Primops in a SimWorld===
===Agent Primops in a SimWorld===


Line 581: Line 736:
;MYCELL()
;MYCELL()
:'''Returns''': the scope of the cell containing the caller.
:'''Returns''': the scope of the cell containing the caller.
 
</div>
===Hexagonal Agent Primop===
===Hexagonal Agent Primop===


Line 588: Line 743:
;HEXMOVE(dist, dir)
;HEXMOVE(dist, dir)
:Moves the calling agent distance dist in the direction dir. Directions are denoted by compass directions; i.e., “N”, “NE”, “SE”, “S”, “SW”, “NW”.
:Moves the calling agent distance dist in the direction dir. Directions are denoted by compass directions; i.e., “N”, “NE”, “SE”, “S”, “SW”, “NW”.
 
</div>
===Convenience Primops===
===Convenience Primops===
These primops perform useful functions that could otherwise be programmed.
These primops perform useful functions that could otherwise be programmed.
Line 599: Line 754:
;AGENTRING(n, ["sort"])
;AGENTRING(n, ["sort"])
;AGENTWRING(n, ["sort"])
;AGENTWRING(n, ["sort"])
:'''Returns''' a list of scopes for all agents in the ring or block (wrapped or otherwise) specified by n. If “sort” is included, the list is sorted in order of increasing distance from the caller.
:'''Returns''': a list of scopes for all agents in the ring or block (wrapped or otherwise) specified by ''n''. If “sort” is included, the list is sorted in order of increasing distance from the caller.
</div></div></div></div>


==Node Properties and Primops==
==Node Properties and Primops==
Line 609: Line 765:
;myId
;myId
:Bound to the caller’s node ''id''.
:Bound to the caller’s node ''id''.
</div>
<div id="count">
<div id="count">
;count
;count
:Bound to the number of nodes in the NodeNetwork.
:Bound to the number of nodes in the NodeNetwork.
</div>
<div id="nodes">
<div id="nodes">
;nodes
;nodes
:Bound to the 1-dimensional array of Nodes in a NodeNetwork.
:Bound to the 1-dimensional array of Nodes in a NodeNetwork.
 
</div></div>
===Primops===
===Primops===
<div id="node">
<div id="node">
Line 621: Line 779:
;CONNECTION(id0, id1)
;CONNECTION(id0, id1)
:'''Returns''': the connection from Node with id ''id0'' to Node with id ''id1'', or null if no such connection exists.
:'''Returns''': the connection from Node with id ''id0'' to Node with id ''id1'', or null if no such connection exists.
</div>
<div id="CONNECTIONS_IN">
<div id="CONNECTIONS_IN">
;CONNECTIONS_IN([id])
;CONNECTIONS_IN([id])
:'''Returns''': the array of connections into the node ''id'' (if ''id'' is omitted, it is assumed to be the caller). Each connection is an object with 3 properties: ''id'', the node id of the source; ''strength'', the raw strength of the connection; and ''n_strength'', the normalized strength of the connection, where the total normalized strength of all connections into the caller is 1.
:'''Returns''': the array of connections into the node ''id'' (if ''id'' is omitted, it is assumed to be the caller). Each connection is an object with 3 properties: ''id'', the node id of the source; ''strength'', the raw strength of the connection; and ''n_strength'', the normalized strength of the connection, where the total normalized strength of all connections into the caller is 1.
</div>
<div id="CONNECTIONS_OUT">
<div id="CONNECTIONS_OUT">
;CONNECTIONS_OUT([id])
;CONNECTIONS_OUT([id])
:'''Returns''': the array of connections from the node ''id'' (if ''id'' is omitted, it is assumed to be the caller). Each connection is an object with 3 properties: ''id'', the node id of the target; ''strength'', the raw strength of the connection; and ''n_strength'', the normalized strength of the connection, where the total normalized strength of all connections from the caller is 1.
:'''Returns''': the array of connections from the node ''id'' (if ''id'' is omitted, it is assumed to be the caller). Each connection is an object with 3 properties: ''id'', the node id of the target; ''strength'', the raw strength of the connection; and ''n_strength'', the normalized strength of the connection, where the total normalized strength of all connections from the caller is 1.
</div>
<div id="NODE">
<div id="NODE">
;NODE(id)
;NODE(id)
:'''Returns''': a scope for node ''id''.
:'''Returns''': a scope for node ''id''.
</div>
<div id="NODECOUNT">
<div id="NODECOUNT">
;NODECOUNT()
;NODECOUNT()
:'''Returns''': the total number of nodes.
:'''Returns''': the total number of nodes.
</div>
<div id="NODE_VALUE">
<div id="NODE_VALUE">
;NODE_VALUE(id, comp)
;NODE_VALUE(id, comp)
Line 639: Line 802:


   NODE_VALUE(id, comp) == NODE(id)[comp]
   NODE_VALUE(id, comp) == NODE(id)[comp]
</div>
<div id="NODES">
<div id="NODES">
;NODES()
;NODES()
:'''Returns''': the array of node scopes.
:'''Returns''': the array of node scopes.
</div>
<div id="INFLOW">
<div id="INFLOW">
;INFLOW([id])
;INFLOW([id])
:'''Returns''': the total strength of connections into node ''id'' (if ''id'' is omitted, it is assumed to be the caller).
:'''Returns''': the total strength of connections into node ''id'' (if ''id'' is omitted, it is assumed to be the caller).
</div>
<div id="OUTFLOW">
<div id="OUTFLOW">
;OUTFLOW([id])
;OUTFLOW([id])
:'''Returns''': the total strength of connections from node ''id'' (if ''id'' is omitted, it is assumed to be the caller).
:'''Returns''': the total strength of connections from node ''id'' (if ''id'' is omitted, it is assumed to be the caller).
</div>
<div id="NEIGHBORS_IN">
<div id="NEIGHBORS_IN">
<div id="NEIGHBORS_OUT">
<div id="NEIGHBORS_OUT">
Line 653: Line 820:
;NEIGHBORS_OUT([id])
;NEIGHBORS_OUT([id])
:'''Returns''': a list of all scopes of Nodes with input (output) connections to the Node with given ''id''. If ''id'' is omitted, the caller's id is used.
:'''Returns''': a list of all scopes of Nodes with input (output) connections to the Node with given ''id''. If ''id'' is omitted, the caller's id is used.
</div></div></div>


==NetWorld Primops==
==NetWorld Primops==

Latest revision as of 18:57, 17 November 2018

Numerus supports a large set of primitives divided into properties and primitive operators, or primops.

A property is an identifier assigned a value at the beginning of a simulation run which is not expected to change. For example, the rows and cols properties of a CellMatrix are fixed at the start of a run and don’t change. A special type of property, called a scope, is used to look up the current values of components.

Primops are functions of zero or more arguments. Some primitives may be used without restriction; others make sense only in specific contexts; for example rows and cols are only useful in spatial contexts such as CellMatrices, AgentVectors and SimWorlds.

Here are the properties and primops supported by the current Numerus implementation, organized by type and area of applicability. All properties (except for mathematical properties) begin with a lower case letter, and all primops are composed entirely of capital letters. Primops are always functions, and therefore require an argument list (even if empty) in order to be invoked.

Notation: x, y represent values (numbers or string constants or expressions); fn represents a Javascript function; exp represents a string expression; [x, y] represents one or more optional arguments, coords represents a coords object of the form {row: r, col: c} or (in the case of 3 dimensions) {row: r, col: c, plane: p}.

Universal Properties and Primops

These can be used in any expression in any component.

Properties

self
scope
The scope of a simulator (Capsule, CellMatrix, etc.) Used to look up component values (see the section on scopes, coming soon).
Self
_cap_
Reference from the scope of a simulator to that simulator.

Control Primops

ALERT(h, [b], [t])
Displays string h in a dialog box as the header of message.
If optional string b is provided, it is the body of the message.
If optional string t is provided, it is the title of the message.
COUNT(fn, l)
fn is a boolean function of one argument and a l is list.
Returns: COUNT(f, l) applies f to each element of l and returns the number of times the result is true.
DELAY(comp, x, [y])
Returns: the value of component comp delayed by x time units. Comp is a string naming a stateful component (i.e., stock, variable or sequence).
Optional y is returned if the current time is less than x. If y is omitted then 0 is returned.
PULSE(amount, start, interval)
Returns: amount when current time is start, start + interval, start + 2*interval, etc.; 0 otherwise
DELAYN(comp scale shape init)
Returns: the n-th order exponentially smooth delay for component comp. comp should be a string naming a Stock, Sequence or Term.
STEP(x, y)
Returns: the value of x if the current time is y or greater; 0 otherwise.
TERMINATE()
Terminates the running simulation.
TOTAL(fn, l)
fn is a numerical function of one argument and a l is list.
Returns: TOTAL(fn, l) applies fn to each element of l and returns the sum of the results.
RESETTING()
Returns: true when the system is currently resetting.

Convenience Primops

These primops perform useful functions that could otherwise be programmed.

FLIP(p)
Simulates a Bernoulli trial.
Returns: true with probability p and false with probability 1-p.
BOUNCER(angle, x, y, cols, rows)
Returns: the expected angle in one step of a projectile moving on a surface bounded by [x, cols] and [y, rows], deflecting off of the edge according to the standard laws of physics.
NORMALIZE(theta)
NORMALIZE02PI(theta)
Returns: angle theta normalized on the interval [, π ] and [0, ], respectively.

Input/Output Primops

BASEDIR()
Returns: the current model directory.

In each of the following path designates a textfile. if path begins with “/” it is treated as an absolute pathname; otherwise it is treated as relative to the current model directory.

OPENREAD(path)
Opens path for reading and returns a Java BufferedReader object. The latter contains methods read and readLine to perform input. See http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html for complete details.
OPENWRITE(path)
Opens path for writing and returns a Java PrintWriter object. The latter contains methods print and println to perform output. See http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html for complete details.
READDATA(path)
Returns: the content of the file path as a string.
PRINT(x0, x1, ...)
Returns: nothing; outputs the values of its arguments to the console, separated by spaces.

Mathematical Properties

PI
PI2
PIO2
Constants π, and π/2, respectively
MPI
MPI2
MPIO2
Constants , -2π and -π/2, respectively
LN10
LN2
LOG10E
LOG2E
Constants ln(10), ln(2), log10(e) and log2(e)
SQRT1_2
SQRT2
Constants 1/√2 and 2, respectively.

Mathematical Primops

Math.XXX
The JavaScript Math functions and constants; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math.
DERIVN(fn, n)
Returns: the value of the nth derivative of fn at the current time, with precision based on the value of dt. fn should be a string naming a State (Stock or Sequence) or Term.
DISTANCE(x0, y0, x1, y1)
Returns: Euclidean distance between points (x0, y0) and (x1, y1).
RANDOM()
Returns: a uniformly distributed random number between 0 and 1.
SEED(x)
Returns: nothing; sets the seed of the random number generator. Should be part of simulation initialization.
RANDOM_HEADING()
Returns: a uniformly distributed random number between and π.
BINOMIAL(n, p)
n is an integer; 0 ≤ p ≤ 1
Returns: a random number from the binomial distribution with n trials and success probability p.
MULTIBINOMIAL(n, p, k)
Returns: Sum of k independent executions of BINOMIAL(n, p).
MULTINOMIAL(n, [p0, p1, ... pm])
Returns: an m-element vector of outcomes from performing n independent generalized Bernoulli trials.
SELECT([s0,...,sm], [p0, .... pm])
A single generalized Bernoulli trial over the states s0, ... sm with respective probabilities p0, ... pm.
Returns: One of the values si with probability pi. Note: if the probabilities do not sum to 1, pm is increased accordingly
NORMAL(x, y)
Returns: a random number from the normal distribution with mean x and standard deviation y.
POISSON(lambda)
Returns: a random number from the Poisson distribution with density lambda.
UNIFORM(x, y)
Returns: a uniformly distributed random variable between x and y.
SIN(x)
Returns: the trigonometric sin of x.
SINWAVE(x, y)
Returns: x*sin(2πt/y), where t is the current time.
COS(x)
Returns: the trigonometric cosine of x.
COSWAVE(x)
Returns: x*cos(2πt/y), where t is the current time.
TAN(x)
Returns: the trigonometric tangent of x.
ACOS(x)
Returns the trigonometric arccosine of x.
ASIN(x)
Returns the trigonometric arcsine of x.
ATAN(x)
Returns: the trigonometric arctangent of x.
ATAN2(y, x)
Returns: the trigonometric tangent of y/x.
MIN(x, y, z ...)
MAX(x, y, z, ...)
Returns:, respectively, the lowest or highest value in a list of arguments:
CEIL(x)
FLOOR(x)
ROUND(x);
Returns:, respectively, x rounded up, x rounded down, and x rounded to the nearest integer.
SQRT(x)
Returns: x
ABS(x)
Returns: |x|
POW(x, y)
Returns: xy
EXP(x)
Returns: ex
LOG(x)
Returns: ln(x)
LOG2(x)
Returns: log2(x)
LOG10(x)
Returns: log10(x)
ARRAYSUM(a)
Returns: the sum of the elements in array a.
ARRAYOF(n, x)
Returns: an array of length n filled with x.
WRAPXM(v, m)
Returns: v mod m normalized to [0, m].
FIXAT(n, d)
Returns: Number n with at most d decimal places.
FACT(n)
Returns: The factorial of n, using Stirling's formula for n > 20.
GRAPHFUN([[x0, y0], [x1, y1], ...])
GRAPHFUN([x0, y0], [x1, y1], ...)
Returns: A function based on the graph defined by the ordered pairs in the argument, interpolated linearly. Acceptable input can be single argument consisting of an array of ordered pairs, or multiple arguments, each an ordered pair. The list need not be in increasing order of x. The returned function maps any value smaller (greater) than the smallest (largest) domain value xk to xk 's value in the range.

Matrix Primops

COLUMNSPLIT(tab)
tab is a 2-dimensional array derived from a table, where the first row contains column headers.
Returns: an object in which each property name is a column header with property value an array comprising the corresponding column.
CSVTOMAT(csv)
csv is a string where line is a comma separated sequence of values.
Returns: the matrix in which each row corresponds to a line in csv.
ROWSTOOBJS(tab)
tab is a 2-dimensional array derived from a table, where the first row contains column headers.
Returns: an array of objects, one for each non-header row. In each object properties are column headers bound to the entry for that column in the corresponding row.
TRANSPOSE(mat)
mat is a matrix (i.e. 2-dimensional array)
Returns: the transpose of mat.

Simulation Primops

CLOCK()
Returns the current clock as an object.
DT()
Returns: current delta value (dt).
SIMSTART()
SIMEND()
SIMMETHOD()
Returns: simulation start time, end time and integration method, respectively.
TIME()
Returns: current simulation time.
TICK()
Returns: the number of simulation steps since the start of the simulation.
SET_DT(dt)
Returns: nothing; sets the current DT value to dt.
DIMENSION(state)
Return: the dimension of the State component state. state should be a string naming a State component (Stock or Sequence).
TRAIL(state)
Returns: an array containing all values recorded for component state. state should be a string naming a State component (Stock or Sequence). Note: complete component history requires that the full history checkbox be selected for the component.

Miscellaneous Primops

_.XXX
The underscore.js library of useful functions. See http://underscorejs.org.
ASVALUE(v)
Required when supplying an array or function value to the input pin of an aggregator. Arrays supplied as input to aggregators are usually interpreted so that each array element is used as input for one of the elements of the aggregator. Similarly, functions are invoked on the id of each element to compute the input value for that element. An array or function wrapped with ASVALUE is sent intact to each element of the aggregator.
DEPENDSON(comp)
Returns: 0. This is used during model construction to assert dependencies.
DISTRIBUTE(a)
Returns: if a is an array of at most 3 dimensions, DISTRIBUTE returns a function f which takes as many arguments as the dimension of a and returns the selected value. Otherwise f is a function of no arguments that return a.
LOOKUP_AREA(term, lo, hi)
Returns: the integral of component term on the interval [lo, hi]. term is a string naming a Term.

Cell Properties and Primops

The following may only be used by capsules contained in a CellMatrix, or cell capsule in a SimWorld. row and col are integers representing row-column coordinates within the CellMatrix. coords is a Coords object All primops expecting coordinate pairs as parameters can either be called with separate row-column arguments or with a Coords object.

Cartesian coordinates will generally be automatically wrapped; i.e. if the coordinate space has dimension rows x cols, then a negative value for row or col is treated respectively as rows + row and cols + col. Values that exceed the dimensions respectively become row – rows and col – cols. This type of space is topologically equivalent to a torus.

Properties

coords
Object whose row and col properties respectively reference the caller’s row and column coordinates within the CellMatrix.
rows
cols
Bound to the total number of rows and columns, respectively.
matrix
Bound to the 2 dimensional array of cells in a CellMatrix

Primops

BLOCK(n, [wrap])
Returns: a list (array) of coordinate objects (i.e., containing row and col properties) comprising the square block of cells n units away from the caller or less. (if wrap is true, BLOCK treats the surface as a torus).
CELL(row, col)
CELL(coords)
Returns the scope for the cell at the given coordinates, which may be passed either as separate parameters or in a coords object. The fields of the scope bind each of the Stocks, Terms and Flows in the cell to the current value of the corresponding component.
CELLS()
Returns the entire matrix (i.e., 2-dimensional array) of scopes for the CellMatrix.
  CELLS()[row][col] == CELL(row, col).
CELL_VALUE(row, col, comp)
CELL_VALUE(coords, comp)
comp is a String naming a Stock, Flow or Term in the cell capsule.
Returns: the current value of that component in the cell with the given coordinates.
  CELL VALUE(row, col, comp) == CELL(row, col)[comp]
RING(n, [wrap])
Returns: a list (array) of coordinate objects (i.e., containing row and col properties) for all cells comprising the square exactly n units away from the caller. (if wrap is true, RING treats the surface as a torus).
WRAP(row, col)
WRAP(coords)
Performs a “wraparound” of the coordinates if they exceed the size of the matrix (or are negative). Returns an array containing the new row and column.

Hexagonal Primops

The following should only be used if the CellMatrix is in hexagonal mode.

HEXRING(n, [wrap])
Returns: a list (array) of coordinate objects (i.e., containing row and col properties) for all cells comprising the hexagon exactly n units away from the caller. (If wrap is true, HEXRING treats the surface as a torus.)
HEXBLOCK(n, [wrap])
Returns: a list (array) of coordinate objects (i.e., containing row and col properties) comprising the hexagonal block of cells n units away from the caller or less. (If wrap is true, HEXBLOCK treats the surface as a torus.)

Convenience Primops

These primops perform useful functions that could otherwise be programmed.

COUNT_CELLS(l, comp, value)
l is a list of cell scopes objects, comp is a string naming a component in those cells (stock, term, flow, etc.), and value is any JavaScript data element.
Returns: Returns the number of objects in l for which the current value of comp is value.
ALL_CELLS(l, comp, value)
NO_CELL(l, comp, value)
SOME_CELL(l, comp, value)
l is a list of cell scopes, comp is a string naming a component in those cells (stock, term, flow, etc.), and value is any JavaScript data element.
Returns: Respectively returns true if for all, none or some scopes in l the current value of comp is value; false otherwise.

Agent Properties and Primops

The following may only be used by capsules contained in an AgentVector. id is an integer representing agent id of an agent. The term “caller” is used to identify the agent in which the primop is being executed, or the property value is being looked up. loc is a location object with properties x and y.

Properties

birth
The point in model time at which the caller was created.
myId
The unique agent ID that has been assigned to the caller.
rows
cols
planes
Bound to the total number of rows and columns in the space occupied by this AgentVector. Planes returns 0

unless space is 3d.

vector
Bound to the object mapping agent ids to agents in an AgentVector

Primops

ADATA(s)
Returns: if s = "AGENTIDS", then ADATA returns the current list of agents; if s == "AGENTCOUNT", then ADATA returns the current agent count. Used to extract data from AgentVectors.
AGE(id)
MYAGE()
Returns: the age (i.e., time since birth) of agent id, or of the caller, respectively.
AGENT(id)
Returns: the scope of the agent identified by id, if it exists.
AGENTS()
Returns: the list of live agent scopes.
AGENTS_AT(row, col)
AGENTS_AT(coords)
Returns: a list of agents contained in the cell at specified coordinates.
AGENT_COUNT()
Returns: the total number of agents.
AGENT_IDS()
Returns: the array of ids for currently living agents.
AGENT_VALUE(id, comp)
comp is a String naming a Stock, Flow or Term in the agent capsule.
Returns: the current value of that component in agent id.
   AGENT VALUE(id, comp) == AGENT(id)[comp]
CELL_COORDS(id)
Returns: a coords object containing the row/col coordinates of the current position of the agent identified by id. If id is omitted, returns the row/col coordinates of the caller.
CREATE([init], [n])
Schedules the creation of a n new agents (n is assumed to be 1 if omitted). init is an initializer object containing bindings for properties in the new agent. These may include init_x, init_ y and init_heading, to indicate the new agent’s initial position and direction. It may also include alternate initialization expressions for Stocks, Local Variables and Properties. If init is omitted, the new agent is a clone of the caller. All new agents are created at the end of the cycle.
KILL(id)
Schedules the elimination of agent id. All agent eliminations are carried out at the end of the cycle.
LOCATION(id)
Returns: the cartesian location of the agent identified by id in an object with properties x and y (and z if the space is 3-dimensional), and the current heading of the agent with property theta. If id is omitted, returns these data for the caller.
LWRAP(x, y)
LWRAP(loc)
Performs a “wraparound” of the location if either coordinate exceeds the size of the agent coordinate space (or is negative).
Returns: an array containing the new x and y;
AGENTBLOCK(n, [sort])
Returns: a list of the scopes of all agents within a block of n units from the caller. If sort is true the list is sorted based on distance from the caller.
HEXAGENTBLOCK(n, [sort])
Returns: a list of the scopes of all agents within a block of n units from the caller on a hexagonal surface. If sort is true the list is sorted based on distance from the caller.
NEIGHBORS(n)
Returns: a sorted list (based on distance from the caller) of the scopes of all other agents within n units of the caller.
HEXNEIGHBORS(n)
Returns: a list of the scopes of all agents within n units of the caller on a hexagonal surface.
NEAREST_NEIGHBOR(n)
Returns: the scope of the nearest neighbor within n units of the caller.
MOVE(x, y, [z])
MOVETO(x, y, [z])
Sets the location of the caller to (x, y), or (x, y, z) in 3 dimensions. All moves occur at the end of the cycle.
MOVEPLUS(x, y, [z])
Sets the location of the caller to its current location plus (x, y), or (x, y, z) in 3 dimensions.
HEADTO(theta, [phi])
SET_HEADING(theta, [phi])
Sets the directional heading(s) of the caller to theta (and phi in 3 dimensions). Angles are given in radians.
HEADPLUS(theta, [phi])
Sets the directional heading(s) of the caller to its current direction(s) plus theta (and phi in 3 dimensions). Angles are given in radians.
GO(speed, theta, [,phi])
Move the location of the caller to its new location based the given speed using directional angle(s) theta (and phi in 3 dimensions). Angles are given in radians.
GO_BOUNCE(speed, theta)
Equivalent to GO(speed, theta) except that the agent bounces off the edge of the space like a billiard ball. Currently only available in 2 dimensions.
HEXMOVE(speed, theta)
Move the location of the caller to its new location based on the given speed and direction theta. Theta is one of N,NE,SE,S,SW,NW.

Convenience Primops

These primops perform useful functions that could otherwise be programmed.

COUNT_AGENTS(l, comp, value)
l is a list of agent scopes, comp is a string naming a component in those agents (stock, term, flow, etc.), and value is any JavaScript data element.
Returns: Returns the number of objects in l for which the current value of comp is value.
ALL_AGENTS(l, comp, value)
NO_AGENT(l, comp, value)
SOME_AGENT(l, comp, value)
l is a list of agent scopes, comp is a string naming a component in those agents, and value is any JavaScript data element.
Returns: Respectively returns true if for all, none or some scope in l the current value of comp is value; false otherwise.
ALL_NEIGHBORS(d, comp, value)
NO_NEIGHBOR(d, comp, value)
SOME_NEIGHBOR(d, comp, value)
Analogous to ALL_AGENTS, etc. except the agents of interest are those within a radius of d units from the agent making the call. Forms that list of agents and returns true if for all, none, or some agent scope in that list the current value of comp is value; false otherwise.
RANDOM_MOVE(loc, [wrap])
Returns: a location object (i.e., with fields x and y) representing a random move (wrapping if wrap is true) of one unit from the location object loc. If loc is omitted it defaults to the location of the caller.
HEX_RANDOM_MOVE(loc, [wrap])
Returns: a location object (i.e., with fields x and y) representing a random move (wrapping if wrap is true) of one unit from the location object loc on a hexagonal surface. If loc is omitted it defaults to the location of the caller.
INBOUNDS(x, y)
Returns: true if 0 ≤ x < columns and 0 ≤ y < rows, where [columns, rows] is the dimension of the agent landscape.

SimWorld Properties

cellmatrix
Bound to the CellMatrix component in a SimWorld
agentvector
Bound to the AgentVector component in a SimWorld

SimWorld Primops

Cell and agent capsules in a SimWorld may respectively use the Cell and Agent properties and primops described above. Also in a SimWorld, cell capsules may call some agent primops and agent capsules may call some cell primops, as detailed below.

Cell Primops in a SimWorld

Cell capsules may call the following agent primops:

AGENT
AGENTS AT
AGENT_COUNT
AGENT_IDS
AGENT_VALUE
AGENTS
CREATE
KILL

Cell capsules in a SimWorld may call the following new primops:

MYAGENTS()
Returns: the list of agents currently contained in the caller.
MYAGENT_COUNT()
Returns: the number of agents currently contained in the caller.

Agent Primops in a SimWorld

Agent capsules may call the following cell primops:

CELL
CELLS
CELL_VALUE

Agent capsules in a SimWorld may call the following new primop:

MYCELL()
Returns: the scope of the cell containing the caller.

Hexagonal Agent Primop

The following should only be used by an agent if the cell component of the SimWorld is in hexagonal mode.

HEXMOVE(dist, dir)
Moves the calling agent distance dist in the direction dir. Directions are denoted by compass directions; i.e., “N”, “NE”, “SE”, “S”, “SW”, “NW”.

Convenience Primops

These primops perform useful functions that could otherwise be programmed.

AGENTBLOCK(n, ["sort"])
AGENTWBLOCK(n, ["sort"])
AGENTRING(n, ["sort"])
AGENTWRING(n, ["sort"])
Returns: a list of scopes for all agents in the ring or block (wrapped or otherwise) specified by n. If “sort” is included, the list is sorted in order of increasing distance from the caller.

Node Properties and Primops

The following may only be used by capsules contained in a NodeNetwork. id is an integer representing node id of a node.

Properties

myId
Bound to the caller’s node id.
count
Bound to the number of nodes in the NodeNetwork.
nodes
Bound to the 1-dimensional array of Nodes in a NodeNetwork.

Primops

CONNECTION(id0, id1)
Returns: the connection from Node with id id0 to Node with id id1, or null if no such connection exists.
CONNECTIONS_IN([id])
Returns: the array of connections into the node id (if id is omitted, it is assumed to be the caller). Each connection is an object with 3 properties: id, the node id of the source; strength, the raw strength of the connection; and n_strength, the normalized strength of the connection, where the total normalized strength of all connections into the caller is 1.
CONNECTIONS_OUT([id])
Returns: the array of connections from the node id (if id is omitted, it is assumed to be the caller). Each connection is an object with 3 properties: id, the node id of the target; strength, the raw strength of the connection; and n_strength, the normalized strength of the connection, where the total normalized strength of all connections from the caller is 1.
NODE(id)
Returns: a scope for node id.
NODECOUNT()
Returns: the total number of nodes.
NODE_VALUE(id, comp)
comp is a String naming a Stock, Flow or Term in the node capsule.
Returns: the current value of that component in node id.
 NODE_VALUE(id, comp) == NODE(id)[comp]
NODES()
Returns: the array of node scopes.
INFLOW([id])
Returns: the total strength of connections into node id (if id is omitted, it is assumed to be the caller).
OUTFLOW([id])
Returns: the total strength of connections from node id (if id is omitted, it is assumed to be the caller).
NEIGHBORS_IN([id])
NEIGHBORS_OUT([id])
Returns: a list of all scopes of Nodes with input (output) connections to the Node with given id. If id is omitted, the caller's id is used.

NetWorld Primops

Cell and agent capsules in a NetWorld may respectively use the Node and Agent properties and primops described above. Also in a NetWorld, node capsules may call some agent primops and agent capsules may call some node primops, as detailed below.

Node Primops in a NodeWorld

Node capsules may call the following agent primops:

AGENT
AGENTS AT
AGENT_COUNT
AGENT_IDS
AGENT_VALUE
AGENTS
CREATE
KILL

Node capsules in a NetWorld may call the following new primops:

MYAGENTS()
Returns: the list of agents currently contained in the caller.
MYAGENT_COUNT()
Returns: the number of agents currently contained in the caller.

Agent Primops in a NetWorld

Agent capsules may call the following node primops:

NODE
NODES
NODE_VALUE

Agent capsules in a NetWorld may call the following new primops:

MYNODE()
Returns: the scope of the node containing the caller.
NETMOVE(nodeId)
Changes current location of caller to node indicated by nodeId. All moves occur at the end of the cycle.
NODE_NEIGHBORS(agentId)
Returns: a list of scopes corresponding to the the nodes to which the node currently occupied by agent agentId has outward links. If agentId is omitted, it is assumed to be the caller.