A behavior tree is a
mathematical model
A mathematical model is a description of a system using mathematical concepts and language. The process of developing a mathematical model is termed mathematical modeling. Mathematical models are used in the natural sciences (such as physics, ...
of
plan
A plan is typically any diagram or list of steps with details of timing and resources, used to achieve an objective to do something. It is commonly understood as a temporal set of intended actions through which one expects to achieve a goal ...
execution used in
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
,
robotics
Robotics is an interdisciplinarity, interdisciplinary branch of computer science and engineering. Robotics involves design, construction, operation, and use of robots. The goal of robotics is to design machines that can help and assist human ...
,
control systems
A control system manages, commands, directs, or regulates the behavior of other devices or systems using control loops. It can range from a single home heating controller using a thermostat controlling a domestic boiler to large industrial ...
and
video games
Video games, also known as computer games, are electronic games that involves interaction with a user interface or input device such as a joystick, controller, keyboard, or motion sensing device to generate visual feedback. This feedb ...
. 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. 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.
Background
Behavior trees originate from the computer game industry as a powerful tool to
model the behavior of
non-player character
A non-player character (NPC), or non-playable character, is any character in a game that is not controlled by a player. The term originated in traditional tabletop role-playing games where it applies to characters controlled by the gamemaster ...
s (NPCs).
They have been extensively used in high-profile video games such as
Halo
Halo, halos or haloes usually refer to:
* Halo (optical phenomenon)
* Halo (religious iconography), a ring of light around the image of a head
HALO, halo, halos or haloes may also refer to:
Arts and entertainment Video games
* Halo (franchise), ...
,
Bioshock
''BioShock'' is a 2007 first-person shooter game developed by 2K Boston (later Irrational Games) and 2K Australia, and published by 2K Games. The first game in the ''BioShock'' series, it was released for Microsoft Windows and Xbox 360 pla ...
, and
Spore
In biology, a spore is a unit of sexual or asexual reproduction that may be adapted for dispersal and for survival, often for extended periods of time, in unfavourable conditions. Spores form part of the life cycles of many plants, algae, ...
. Recent works propose behavior trees as a multi-mission control framework for
UAV, complex robots, robotic manipulation, and multi-robot systems.
[Klöckner, Andreas. "Interfacing BTs with the World Using Description Logic." In AIAA Guidance, Navigation and Control Conference, Boston, MA. 2013.]
Behavior trees have now reached the maturity to be treated in Game AI textbooks,
as well as generic game environments such as
Unity (game engine)
Unity is a cross-platform game engine developed by Unity Technologies, first announced and released in June 2005 at Apple Worldwide Developers Conference as a Mac OS X game engine. The engine has since been gradually extended to support a varie ...
and
Unreal Engine
Unreal Engine (UE) is a 3D computer graphics game engine developed by Epic Games, first showcased in the 1998 first-person shooter game '' Unreal''. Initially developed for PC first-person shooters, it has since been used in a variety of genr ...
(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
In computer graphical user interfaces, drag and drop is a pointing device gesture in which the user selects a virtual object by "grabbing" it and dragging it to a different location or onto another virtual object. In general, it can be used ...
) 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.
[ 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.
]
Key concepts
A behavior tree is graphically represented as a directed tree
In botany, a tree is a perennial plant with an elongated stem, or trunk, usually supporting branches and leaves. In some usages, the definition of a tree may be narrower, including only woody plants with secondary growth, plants that are ...
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 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.
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
Mathematical state space definition
In order to apply control theory tools to the analysis of behavior trees, they can be defined as three-tuple.
where is the index of the tree, is a vector field representing the right hand side of an ordinary difference equation, is a time step and
is the return status, that can be equal to either
Running ,
Success , or
Failure .
Note: A task is a degenerate behavior tree with no parent and no child.
Behavior tree execution
The execution of a behavior tree is described by the following standard ordinary difference equations:
where represent the discrete time, and is the state space of the system modelled by the behavior tree.
Sequence composition
Two behavior trees and can be composed into a more complex behavior tree using a Sequence operator.
Then return status and the vector field associated with are defined (for ) as follows:
See also
* Decision tree
A decision tree is a decision support tool that uses a tree-like model of decisions and their possible consequences, including chance event outcomes, resource costs, and utility. It is one way to display an algorithm that only contains co ...
* Hybrid system A hybrid system is a dynamical system that exhibits both continuous and discrete dynamic behavior – a system that can both ''flow'' (described by a differential equation) and ''jump'' (described by a state machine or automaton). Often, the ...
* Subsumption architecture Subsumption architecture is a reactive robotic architecture heavily associated with behavior-based robotics which was very popular in the 1980s and 90s. The term was introduced by Rodney Brooks and colleagues in 1986.Brooks, R. A., "A Robust Pro ...
References
External links
ROS behavior tree library
Unreal Engine 4 behavior tree documentation
Behavior trees for AI: How they work
Behavior Trees: Simple yet Powerful AI for your Robot
Video Lectures on Behavior Trees
{{DEFAULTSORT:Behavior tree
Automata (computation)
Models of computation
Digital electronics
Robot control
Automated planning and scheduling
Visual programming