BTProbabilitySelector
Inherits: BTComposite < BTTask < BT
BT composite that chooses a child task to execute based on attached probabilities.
Description
BTProbabilitySelector chooses a child task to execute based on attached probabilities. It is typically used for decision-making purposes. Probability distribution is calculated based on weights assigned to each child task.
Returns SUCCESS
when a child task results in SUCCESS
.
Returns RUNNING
when a child task results in RUNNING
.
The behavior of BTProbabilitySelector when a child task results in FAILURE
depends on the abort_on_failure value:
If abort_on_failure is
false
, when a child task results inFAILURE
, BTProbabilitySelector will normalize the probability distribution over the remaining children and choose a new child task to be executed. If all child tasks fail, the composite will returnFAILURE
.If abort_on_failure is
true
, when a child task results inFAILURE
, BTProbabilitySelector will not choose another child task to be executed and will immediately returnFAILURE
.
Properties
bool |
|
Methods
float |
get_probability ( int child_idx ) const |
float |
get_total_weight ( ) const |
float |
get_weight ( int child_idx ) const |
bool |
has_probability ( int child_idx ) const |
void |
set_probability ( int child_idx, float probability ) |
void |
set_weight ( int child_idx, float weight ) |
Property Descriptions
bool abort_on_failure = false
void set_abort_on_failure ( bool value )
bool get_abort_on_failure ( )
If true
, BTProbabilitySelector will not choose another child to execute and will return FAILURE
when a child task results in FAILURE
.
Method Descriptions
float get_probability ( int child_idx ) const
Returns the child task’s selection probability.
float get_total_weight ( ) const
Returns the total weight of all child tasks.
float get_weight ( int child_idx ) const
Returns the child task’s weight within the weighted probability selection algorithm.
bool has_probability ( int child_idx ) const
Returns whether the child task at index child_idx
participates within the weighted probability selection algorithm and has a probability assigned to it. Returns false
for BTComment tasks.
void set_probability ( int child_idx, float probability )
Sets the child task’s weight calculated based on the desired probability.
void set_weight ( int child_idx, float weight )
Sets the child task’s weight for the weighted probability selection algorithm.