Guides‎ > ‎

Dictionary

The set of NetLogo commands and reporters has been extended by the Behaviour Composer. Those that are not solely for internal use are listed here and can be used in your micro-behaviours. This document is intended as a reference resource while the programming guide describes Behaviour Composer programming in detail.

Scheduling

do-every

do-every interval [ actions ] performs actions now and every interval time units (actions can be any NetLogo commands).

do-every-dynamic

do-every-dynamic [interval-reporter] [ actions ] performs actions now and repeats them after an interval computed by running the  interval-reporter  (actions can be any NetLogo commands). 

do-at-setup

do-at-setup [ actions ] performs actions when the simulation is initialised (actions can be any NetLogo commands).

do-after-setup

do-after-setup [ action ] performs actions just after the simulation is initialised (actions can be any NetLogo commands).

do-after

do-after interval [ actions ] performs actions after interval time units (actions can be any NetLogo commands; interval any positive number).

do-at-time

do-at-time time [ actions ] performs actions when the clock has reached time (actions can be any NetLogo commands and time can be any number).

do-now

do-now [ actions ] performs actions immediately (actions can be any NetLogo commands).

when

when [ condition ] [ actions ] performs actions one time as soon as condition holds (actions can be any NetLogo commands; condition any NetLogo reporter that returns true or false).

whenever

whenever [ condition ] [ actions ] performs actions every time condition is true (actions can be any NetLogo commands; condition any NetLogo reporter that returns true or false).

do-if-else

do-if-else [ condition ] [ micro-behaviourt1 micro-behaviourt2 … micro-behaviourtn ] [ micro-behaviourf1 micro-behaviourf2 … micro-behaviourfn ]

adds micro-behaviourt1 micro-behaviourt2 … micro-behaviourtn if condition reports true otherwise it adds micro-behaviourf1 micro-behaviourf2 … micro-behaviourfn.

do-for-n

do-for-n n agents [ actions ]

This is useful when you want a subset of agents to perform some action. Selects n of the agents and runs actions for each agent. If n is a non-integer the remainder is used as the odds of selecting an additional agent. If there are fewer than n agents then all agents run the actions. While the actions are run the code can refer to the agent that is running do-for-n using the-other. select-n is a reporter that returns n agents and also treats fractions probabilistically.

A typical example is from RANDOM_ENCOUNTER:

do-every 1	 [do-if my-state = "infected"	     [do-for-n the-encounter-rate		       all-individuals with [my-state != "dead"]	               [add-behaviour POSSIBLE-INFECTION]]]

It selects the-encounter-rate of those not dead and adds the POSSIBLE-INFECTION micro-behaviour.

do-repeatedly

do-repeatedly n [ actions ] performs actions n times (if n is a non-integer then the actions may be performed an additional time where the odds are the fractional part of n). When n is an integer this is identical to the NetLogo repeat reporter.

do-with-probability

do-with-probability odds [ actions ] performs actions with probability odds.

do-with-probabilities

do-with-probabilities odds1 [ behaviour1  ]  odds2 [ behaviour2  ] …  oddsn [ behaviourn  ] performs behaviouri  with probability of oddsi. If oddsi that together with the oddsj where j < i adds up to more than 1.0 then only the portion of oddsi  that adds up to 1.0 is used.

add-behaviour

add-behaviour micro-behaviour adds the micro-behaviour to the current agent (the prototype running the micro-behaviour that is executing the add-behaviour command).

add-behaviours

add-behaviours [ micro-behaviour1 micro-behaviour2 … micro-behaviourn ] adds the micro-behaviours  to the current agent  (the prototype running the micro-behaviour that is executing the add-behaviours command).

add-behaviour-to agent

add-behaviour-to agent micro-behaviour adds the micro-behaviour to the agent.

add-behaviours-to

add-behaviours-to agent [ micro-behaviour1 micro-behaviour2 … micro-behaviourn ] adds the micro-behaviours to the agent.

add-link-behaviour

add-link-behaviour micro-behaviour when-to-add when asked of a link or set of links adds the micro-behaviour to the links at time when-to-add. when-to-add can be time so that it is added immediately.

add-link-behaviours

add-link-behaviours [ micro-behaviour1 micro-behaviour2 … micro-behaviourn ] when-to-add when asked of a link or set of links adds the micro-behaviours to the links at time when-to-add. when-to-add can be time so that they are added immediately.

add-link-behaviour-after

add-link-behaviour micro-behaviour delay  when asked of a link or set of link adds the micro-behaviour to the links after delay.

add-link-behaviours-after

add-link-behaviours-after [ micro-behaviour1 micro-behaviour2 … micro-behaviourn ] delay when asked of a link or set of links adds the micro-behaviours to the links after delay. 

remove-behaviours-from

remove-behaviours-from agent-or-agent-set [ micro-behaviour1 micro-behaviour2 … micro-behaviourn ] removes the micro-behaviours from agent-or-agent-set . If  a micro-behaviour of agent-or-agent-set and one of the micro-behaviouri are copies of the same micro-behaviour then it is removed from agent-or-agent-set.

remove-all-behaviours

remove-all-behaviours removes all behaviours from the agent running it.

remove-all-behaviours-from

remove-all-behaviours-from agent-or-agent-set removes all behaviours from agent-or-agent-set.

Selecting agents

select-n

select-n n agents returns n random members of agents. If n is a non-integer the remainder is used as the odds of selecting an additional agent. If there are fewer than n agents then all agents is returned. If n is an integer that is equal to or larger than the number of agents then this is identical to the NetLogo n-of reporter.

can-pick-one

can-pick-one agents if agents is not empty reports true and the-other will return the agent chosen.

any

any prototype name reports true if there are any (non-hidden) agents other than the caller created as copies of the prototype named prototype name and the-other will return the agent chosen.

anyone-who-is

anyone-who-is [ conditions ] [ actions ] runs actions for any agent that satisfies conditions and the-other will return the agent chosen (actions can be any NetLogo commands; condition any NetLogo reporter that returns true or false).

all-who-are

all-who-are [ conditions ] [ actions ] runs actions for all agents that satisfy conditions and the-other can be used. 

the-other

the-other can be used in NetLogo code in the Behaviour Composer to refer to an agent defined by the most recent execution of one of the above extensions. An example of its use is in EAT-WHEN-HUNGRY. A simplified version is

when   [can-pick-one all-individuals with [distance-to-me < 5]]   [add-behaviour-to the-other DIE]

When there is at least one individual whose distance to the agent running this code fragment is less than 5 units then the behaviour DIE is added to the the-other, can-pick-one sets the-other when it randomly choses one of the agents from all-individuals with [distance-to-me < 5].

all-individuals

all-individuals reports all agents that are not invisible. Same as NetLogo objects with [my-visibility = true]

all-of-kind

all-of-kind "prototype name" reports all instances of the prototype with that name. Same as NetLogo: objects with [kind = "prototype name"]

any-of-kind

any-of-kind "prototype name" reports one random instance of the prototype with that name. Same as NetLogo: one-of objects with [kind = "prototype name"]

all-others

all-others reports all agents that are not invisible other than the agent calling this.

Random numbers

random-integer-between

random-integer-between [number1 number2 ] for whole numbers or integers between number1 and number2.

random-number-between

random-number-between [number1 number2 ] creates a random number between number1 and number2 (including all rational numbers e.g. fractions of whole numbers represented by double floating numbers).

Movement

The BehaviourComposer supports three movement attributes: my-x , my-y , and my-heading . If the corresponding NetLogo variables xcor, ycor, and heading are not updated (which many NetLogo primitives do such as forward , face , right , ...) then they are set to the values of the attributes. Note that as with all attributes, one can use my-next-x, my-next-y, and my-next-heading to distinguish between the value the attribute should have when the current cycle ends and the value it currently has.

The advantage of using go-forward and turn-right is that they work together with any other code that deals with my-x , my-y , and my-heading such that they don't depend upon the order of events.

go-forward

go-forward is similar to NetLogo's jump except it relies upon my-x, my-y, and my-heading.

turn-right

turn-right angle sets my-next-heading to my-heading+angle. This is similar to how NetLogo's right affects heading. Because it sets my-next-heading my-heading is not updated until the end of the cycle.

turn-left

turn-left angle decrements sets my-next-heading to my-heading-angle . This is similar to how NetLogo's left affects heading. Because it sets my-next-heading my-heading is not updated until the end of the cycle.

move-horizontally-or-vertically-towards-another

 move-horizontally-or-vertically-towards-another agent speed moves speed units towards agent by moving either horizontally or vertically. The odds of whether it moves horizontally or vertically is proportional to the horizontal and vertical distance to the other.

random-unoccupied-location

random-unoccupied-location min-xcor max-xcor min-ycor max-ycor reports a location (a list of the x and y coordinates) that does not contain an agent and is in the region specified by min-xcor, max-xcor, min-ycor, and max-ycor.

heading-towards-another

heading-towards-another another reports the heading towards another if another is an agent or patch. This is similar to NetLogo's towards except that it returns my-heading if another is at the same location as the agent or another is neither a patch nor an agent.

canonical-heading

canonical-heading angle reports an angle between 0 and 360 degrees that is equivalent to angle.

Miscellaneous

create-agents

create-agents number-of-agents prototype-name [additional behaviours] creates number-of-agents using all the behaviours of the  prototype-name and any additional behaviours. create-objects is the older name of this command.  After calling create-agents the local variable just-created-agents contains the set agents just created. This is implemented by generating NetLogo code that relies upon sprout.

create-agents-from-data

create-agents-from-data   prototype-name list-of-attribute-names data [additional behaviours] creates (length of data) / (length of  list-of-attribute-names ) agents using the data and all the behaviours of the  prototype-name and any additional behaviours. This is implemented by generating NetLogo code that relies upon sprout.

ask-every-patch

ask-every-patch [ actions ] performs actions for every patch of the environment. Note that unlike ask patches in NetLogo this can be run from the "turtle context".

within-range

within-range x minimum-value maximum-value reports x if it is between minimum-value and maximum-value. Otherwise it returns minimum-value if x is less than minimum-value and maximum-value  if x is greater than maximum-value.

layout-grid

layout-grid agent-set-or-list lower-left-x lower-left-y width height lays the members of agent-set-or-list out in a grid that is width by height  with its lower left corner at lower-left-x, lower-left-y.

layout-rectangular-prism

layout-rectangular-prism agent-set-or-list lower-left-x lower-left-y lower-left-z width height depth lays the members of agent-set-or-list out in a rectangular prism that is width by height by depth  with its lower left corner at lower-left-x, lower-left-y, lower-left-z.

add-copies
add-copies [n behaviours] creates n exact copies of the agent running this and then adds the behaviours to each of the newly created agents.

add-copies-of-another

add-copies-of-another [n another-agent behaviours] creates n exact copies of another-agent and then adds the behaviours to each of the newly created agents.

log-log-histogram

Similar to NetLogo's histogram command.  log-log-histogram [data increment] computes the frequency of data points in the interval [m+n*increment, m+(n+1)*increment) where m is the minimum value in data and n is any non-negative integer. If the frequency is not zero it  plots the natural logarithm of the frequency and the logarithm of the average of the interval.

power-law-random

power-law-random [power maximum-value] returns a random non-negative integer less than or equal to maximum-value. The distribution of the random numbers follows a power law with power as the exponent.

power-law-list

power-law-list  [n power maximum-value]  returns a list of n values returned by power-law-random.

second

second list reports the second element of the list. Same as NetLogo first but-first.

third

third list reports the third element of the list. Same as NetLogo  first  but-firstbut-first.

fourth

fourth list reports the forth element of the list. Same as NetLogo first but-first but-first but-first.