Behavior tree (artificial intelligence, robotics and control)

A behavior tree is a mathematical model of plan execution used in computer science, robotics, control systems and video games.

They describe switchings between a finite set of tasks in a modular fashion.

Behavior trees present some similarities to hierarchical state machines with the key difference that the main building block of a behavior is a task rather than a state.

Its ease of human understanding make behavior trees less error prone and very popular in the game developer community.

Behavior trees have been shown to generalize several other control architectures.

[1][2] A behavior based control structure has been initially proposed by Rodney Brooks in his paper titled 'A robust layered control system for a mobile robot'.

In the initial proposal a list of behaviors could work as alternative one another, later the approach has been extended and generalized in a tree-like organization of behaviors, with extensive application in the game industry[citation needed] as a powerful tool to model the behavior of non-player characters (NPCs).

[3][4][5][6] They have been extensively used in high-profile video games such as Halo, Bioshock, and Spore.

Recent works propose behavior trees as a multi-mission control framework for UAV, complex robots, robotic manipulation, and multi-robot systems.

[7][8][9][10][11][12] Behavior trees have now reached the maturity to be treated in Game AI textbooks,[13][14] as well as generic game environments such as Unity (game engine) and Unreal Engine (see links below).

Behavior trees became popular for their development paradigm: being able to create a complex behavior by only programming the NPC's actions and then designing a tree structure (usually through drag and drop) whose leaf nodes are actions and whose inner nodes determine the NPC's decision making.

Behavior trees are visually intuitive and easy to design, test, and debug, and provide more modularity, scalability, and reusability than other behavior creation methods.

Over the years, the diverse implementations of behavior trees kept improving both in efficiency and capabilities to satisfy the demands of the industry, until they evolved into event-driven behavior trees.

[15][5] Event-driven behavior trees solved some scalability issues of classical behavior trees by changing how the tree internally handles its execution, and by introducing a new type of node that can react to events and abort running nodes.

Nowadays, the concept of event-driven behavior tree is a standard and used in most of the implementations, even though they are still called "behavior trees" for simplicity.

Graphically, the children of a control flow node are placed below it, ordered from left to right.

[16] The execution of a behavior tree starts from the root which sends ticks with a certain frequency to its child.

A tick is an enabling signal that allows the execution of a child.

When the execution of a node in the behavior tree is allowed, it returns to the parent a status running if its execution has not finished yet, success if it has achieved its goal, or failure otherwise.

When a subtask is completed and returns its status (success or failure), the control flow node decides whether to execute the next subtask or not.

Fallback nodes are used to find and execute the first child that does not fail.

A fallback node will return with a status code of success or running immediately when one of its children returns success or running (see Figure I and the pseudocode below).

The children are ticked in order of importance, from left to right.

In pseudocode, the algorithm for a fallback composition is: Sequence nodes are used to find and execute the first child that has not yet succeeded.

A sequence node will return with a status code of failure or running immediately when one of its children returns failure or running (see Figure II and the pseudocode below).

In pseudocode, the algorithm for a sequence composition is: In order to apply control theory tools to the analysis of behavior trees, they can be defined as three-tuple.

is a vector field representing the right hand side of an ordinary difference equation,

Note: A task is a degenerate behavior tree with no parent and no child.

The execution of a behavior tree is described by the following standard ordinary difference equations:

is the state space of the system modelled by the behavior tree.

Behavior tree modelling the search and grasp plan of a two-armed robot
Figure I. Graphical representation of a fallback composition of N tasks.
Figure II. Graphical representation of a sequence composition of N tasks.