Neha Patil (Editor)

Behavior tree (artificial intelligence, robotics and control)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Behavior tree (artificial intelligence, robotics and control)


A behavior tree (BT) 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. Their strength comes from their ability to create very complex tasks composed of simple tasks, without worrying how the simple tasks are implemented. BTs 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 BTs less error prone and very popular in the game developer community. BTs have shown to generalize several other control architectures.

Contents

Background

BTs originates from the computer game industry as a powerful tool to model the behavior of non-player characters (NPCs). They have been extensively used in high profile video games such as Halo, Bioshock, and Spore. Recent works propose BTs as a multi-mission control framework for UAV, complex robots, robotic manipulation, and multi-robot systems. BT have now reached the maturity to be treated in Game AI textbooks as well as generic game environments such as PyGame and Unreal Engine (see links below).

Relation to other Control Architectures

It has been shown that BTs generalize a number of earlier control architectures, such as

  • The Subsumption Architecture by Brooks
  • The Teleo-Reactive Programs by Nils John Nilsson
  • Sequential Behavior Decompositions
  • Decision Tree
  • Key concepts

    BT is graphically represented as a directed tree in which the nodes are classified as root, control flow nodes, or execution nodes (tasks). For each pair of connected nodes the outgoing node is called parent and the incoming node is called child. The root has no parents and exactly one child, the control flow nodes have one parent and at least one child, and the execution nodes have one parent and no children. Graphically, the children of a control flow node are placed below it, ordered from left to right.

    The execution of a BT 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 BT 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.

    Control flow node

    A control flow node is used to control the subtasks of which it is composed. A control flow node may be either a selector (fallback) node or a sequence node. They run each of their subtasks in turn. 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.

    Selector (fallback) node

    Fallback nodes are used to find and execute the first child that does not fail. A fallback node will return immediately with a status code of success or running 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:

    1 for i from 1 to n do 2 childstatus ← Tick(child(i)) 3 if childstatus = running 4 return running 5 else if childstatus = success 6 return success 7 end 8 return failure

    Sequence node

    Sequence nodes are used to find and execute the first child that has not yet succeeded. A sequence node will return immediately with a status code of failure or running when one of its children returns failure or running (see Figure II and the pseudocode below). The children are ticked in order, from left to right.

    In pseudocode, the algorithm for a sequence composition is:

    1 for i from 1 to n do 2 childstatus ← Tick(child(i)) 3 if childstatus = running 4 return running 5 else if childstatus = failure 6 return failure 7 end 8 return success

    Youtube instruction videos

  • Introduction to AI - Part 1: Behavior Tree Basics (Unreal Engine 4)
  • 07B Behavior Trees
  • Unity AI - Behave Demo
  • Understanding the Second Generation of Behavior Trees and Preparing for Challenges Beyond
  • Mathematical state space definition

    In order to apply control theory tools to the analysis of Behavior Trees, BT can be defined as three-tuple.

    T i = { f i , r i , Δ t } ,

    where i N is the index of the tree, f i : R n R n is a vector field representing the right hand side of an ordinary difference equation, Δ t is a time step and r i : R n { R i , S i , F i } is the return status, that can be equal to either Running R i , Success S i , or Failure F i .

    Note: A task is degenerate BT with no parent and no child.

    Behavior tree execution

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

    x k + t ( t k + 1 ) = f i ( x k ( t k ) )

    t k + 1 = t k + Δ t

    where k N represent the discrete time, and x R n is the state space of the system modelled by the behavior tree.

    Fallback composition

    Two BTs T i and T j can be composed into a more complex BT T 0 using a Fallback operator.

    T 0 = fallback ( T i , T j ) .

    Then return status r 0 and the vector field f 0 associated with T 0 are defined as follows:

    r 0 ( x k ) = { r j ( x k )  if  x k F 1 r i ( x k )  otherwise  .

    f 0 ( x k ) = { f j ( x k )  if  x k F 1 f i ( x k )  otherwise  .

    Sequence composition

    Two BTs T i and T j can be composed into a more complex BT T 0 using a Sequence operator.

    T 0 = sequence ( T i , T j ) .

    Then return status r 0 and the vector field f 0 associated with T 0 are defined as follows:

    r 0 ( x k ) = { r j ( x k )  if  x k S 1 r i ( x k )  otherwise  .

    f 0 ( x k ) = { f j ( x k )  if  x k S 1 f i ( x k )  otherwise  .

    References

    Behavior tree (artificial intelligence, robotics and control) Wikipedia