Behavior model parallelization method based on minimum behavior partial order set
Through the minimal behavior partial order set method, the parallelization processing of the behavior tree is optimized, and the problem of insufficient parallelization ability of the behavior tree in the existing technology is solved, and the maximum parallelization and execution efficiency of the behavior tree are achieved.
Patent Information
- Application Number
- CN202510455793.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-11
- Publication Date
- 2025-07-25
AI Technical Summary
The existing behavior tree parallelization method fails to fully explore the parallelization ability of the behavior tree, resulting in limited improvement in execution efficiency.
The minimum behavior partial order set method is adopted, and by establishing a behavior tree parallelization model, generating an execution sequence, defining the parallelism and sequence relationship of action node pairs, exchanging node orders and judging state consistency, and building temporary parallel nodes to achieve maximum parallelism of the behavior tree.
The maximization and parallelization of the behavior tree is realized, and the execution efficiency and response speed of the behavior tree are improved.
Smart Images

Figure CN120373428A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer simulation. More specifically, it relates to a method for parallelizing a behavior model based on a minimum behavior poset. Background Art
[0002] A Behavior Tree (BT) is a model used to describe the decision-making process of an agent. Its structured characteristics make it suitable for parallel processing. Parallelizing the behavior tree can improve the efficiency of protocol verification, simulation, and real-time system design.
[0003] The work of parallelizing the behavior tree refers to implementing the simultaneous execution of multiple child nodes through parallel nodes in the behavior tree to improve the execution efficiency and response speed of the behavior tree.
[0004] Currently, the methods for parallelizing the behavior tree model are as follows: the hierarchical parallelization method, which decomposes the behavior tree into multiple subtrees, each subtree is executed independently, and is coordinated through an event-driven or time-slice rotation mechanism; the branch parallelization method, which implements parallel processing at the branch nodes of the behavior tree. For example, multiple sensor data acquisition nodes can be executed simultaneously; the hardware acceleration method, which uses FPGA or GPU to achieve rapid evaluation of the behavior tree and is applicable to real-time systems; the distributed computing method, which decomposes the behavior tree into multiple subtasks and assigns them to different computing nodes, and collaborates through a message passing mechanism.
[0005] The above methods improve the degree of parallelization of the behavior tree execution through software and hardware technologies such as distributed computing and parallel computing, thereby realizing the parallel execution ability of the behavior tree.
[0006] However, none of the above algorithms have exploited the parallelization ability of the behavior tree model. By exploiting the parallelization ability of the behavior tree, the simultaneous execution of multiple child nodes is achieved through parallel nodes, the parallelization ability of the behavior tree is improved, and further the degree of parallelization of the behavior pattern is realized. Summary of the Invention
[0007] The purpose of the present invention is to provide a method for parallelizing a behavior model based on a minimum behavior poset to solve at least one of the problems existing in the prior art.
[0008] To achieve the above purpose, the present invention adopts the following technical solutions:
[0009] The first aspect of the present invention provides a method for parallelizing a behavior model based on a minimum behavior poset, the method comprising:
[0010] Establish a behavior tree and generate an execution sequence after accessing the root node and the set of child nodes of the behavior tree;
[0011] Segment the execution sequence according to the node type to generate a set of segmented node sequences;
[0012] Generate multiple sets of action nodes corresponding to multiple sets of segment nodes in the set of segment node sequences;
[0013] Traverse multiple sets of action nodes and select the sets of action nodes with the number of action nodes greater than a first preset value to obtain multiple selected sets of action nodes;
[0014] Define a minimum behavior poset, where the minimum behavior poset includes a first set of action node pairs for which the behavior tree does not satisfy the order relationship and a second set of action node pairs for which the behavior tree satisfies the parallel relationship;
[0015] Establish a corresponding third set of action node pairs for the selected sets of action nodes, and use a nested loop method for the selected sets of action nodes to form action node pairs and put them into the third set of action node pairs;
[0016] Exchange the order of the action nodes in the action node pairs in the third set of action node pairs, and determine whether the states of the behavior tree nodes before and after the exchange are consistent. If they are consistent, add the action node pairs before the exchange to the first set of action node pairs;
[0017] Traverse multiple selected sets of action nodes and generate a final first set of action node pairs;
[0018] Select the action node pairs in the final first set of action node pairs and establish temporary parallel nodes, obtain the parent nodes of the action nodes in the action node pairs, add the temporary parallel nodes to the set of child nodes and delete the action nodes in the action node pairs, run the behavior tree containing the temporary parallel nodes to generate a behavior tree execution sequence and record the state of each node, and determine whether the state of the temporary parallel node is successful. If so, add the action node pairs to the second set of action node pairs;
[0019] Traverse the action node pairs in the final first set of action node pairs to generate a final second set of action node pairs.
[0020] Optionally, the establishing a behavior tree and generating an execution sequence after accessing the root node of the behavior tree and its set of child nodes includes:
[0021] Access the root node of the behavior tree;
[0022] Use a recursive method to sequentially access the nodes in the set of child nodes and find the corresponding node relationships until the set of child nodes is an empty set;
[0023] Sequentially record the accessed nodes to form an execution sequence.
[0024] Optionally, the segmenting the execution sequence according to the node type to generate a set of segment node sequences includes:
[0025] Pre-set the set of segmentation node sequences to be an empty set;
[0026] Traverse each node in the execution sequence. If the type of the current node is the first node type, the second node type, or the third node type, then add the sequences of all nodes before the current node to the set of segmentation node sequences, and continue traversing from the current node until all nodes are traversed.
[0027] Optionally, the generating multiple action node sets corresponding to multiple segmentation node sequences in the set of segmentation node sequences includes:
[0028] Count the number of segmentation node sequences in the set of segmentation node sequences;
[0029] Set the subscript and initial value of each segmentation node sequence;
[0030] Generate a corresponding action node set for each segmentation node sequence, and remove the nodes with the first node type, the second node type, or the third node type from the action node set.
[0031] Optionally, the first preset value is greater than or equal to 2.
[0032] Optionally, the defining the minimum behavior poset, the minimum behavior poset includes the first set of action node pairs where the behavior tree does not satisfy the order relationship and the second set of action node pairs where the behavior tree satisfies the parallel relationship includes:
[0033] Preset the first set of action node pairs where the behavior tree does not satisfy the order relationship to be an empty set;
[0034] Preset the second set of action node pairs where the behavior tree satisfies the parallel relationship to be an empty set.
[0035] Optionally, the establishing a corresponding third set of action node pairs for the selected action node set, and forming action node pairs by using a nested loop for the selected action node set and putting them into the third set of action node pairs includes:
[0036] Set the subscript of the selected action node set and preset the corresponding third set of action node pairs to be an empty set;
[0037] Use the outer loop to control the first action node in the action node set, use the inner loop to control the second action node in the action node set, and select two action nodes in sequence to form an action node pair and put it into the third set of action node pairs.
[0038] Optionally, the steps of swapping the order of the action nodes in the action node pairs in the third action node pair set and determining whether the states of the behavior tree nodes before and after the swapping are the same. If they are the same, adding the action node pairs before the swapping to the first action node pair set include:
[0039] Set the subscript of the action node pairs in the third action node pair set;
[0040] Select a group of action node pairs, run the behavior tree according to the given input, generate the behavior tree execution sequence before swapping the nodes, and record the state of each node;
[0041] Swap the order of the action nodes in the action node pair, run the behavior tree according to the given input, generate the behavior tree execution sequence after swapping the nodes, and record the state of each node;
[0042] Determine whether the state of each node before swapping the nodes is the same as the state of each node after swapping the nodes;
[0043] If they are the same, add the selected group of action node pairs to the first action node pair set.
[0044] Optionally, the steps of selecting the action node pairs in the final first action node pair set and establishing a temporary parallel node, obtaining the parent nodes of the action nodes in the action node pair, adding the temporary parallel node to the child node set, and deleting the action nodes in the action node pair include:
[0045] Set the subscript of the action node pairs in the final first action node pair set;
[0046] Select the action node pairs in the final first action node pair set;
[0047] Establish the node relationship of the temporary parallel node and the temporary parallel node;
[0048] Obtain the parent nodes of the action nodes in the action node pair and find the node relationship of the parent nodes. Add the temporary parallel node to the child node set in the node relationship of the parent nodes, and delete the action nodes in the action node pair from the child node set.
[0049] Optionally, the steps of traversing the action node pairs in the final first action node pair set to generate the final second action node pair set include: constructing a new parallel behavior tree.
[0050] The beneficial effects of the present invention are as follows:
[0051] The technical solution of the present invention proposes to use a poset to represent the sequence relationship of behavior execution in the behavior tree model, and realizes the construction of the behavior poset of the behavior tree; an algorithm for maximizing the parallel execution of behaviors in the behavior tree model is realized, and the maximum parallelism of the behavior tree is realized. Brief Description of the Drawings
[0052] The following further describes in detail the specific embodiments of the present invention in conjunction with the drawings.
[0053] Figure 1 The flowchart showing the method for parallelizing a behavior model based on a minimum behavior poset provided by an embodiment of the present invention is shown. Specific Embodiments
[0054] To more clearly illustrate the present invention, the present invention will be further described below in conjunction with embodiments and drawings. Similar components in the drawings are denoted by the same reference numerals. Those skilled in the art should understand that the content specifically described below is illustrative rather than restrictive, and should not be used to limit the protection scope of the present invention.
[0055] Currently, none of the behavior tree model parallelization methods have achieved the maximization of behavior tree model parallelization.
[0056] In view of this, as Figure 1 shown, an embodiment of the present invention provides a method for parallelizing a behavior model based on a minimum behavior poset. The method includes: establishing a behavior tree and generating an execution sequence after accessing the root node and the set of child nodes of the behavior tree; segmenting the execution sequence according to node types to generate a set of segmented node sequences; correspondingly generating a plurality of action node sets for the plurality of segmented node sequences in the set of segmented node sequences; traversing the plurality of action node sets and selecting the action node sets with the number of action nodes greater than a first preset value to obtain a plurality of selected action node sets; defining a minimum behavior poset, where the minimum behavior poset includes a first set of action node pairs in the behavior tree that do not satisfy the sequential relationship and a second set of action node pairs in the behavior tree that satisfy the parallel relationship; establishing a corresponding third set of action node pairs for the selected action node sets, and forming action node pairs in the selected action node sets in a nested loop manner and putting them into the third set of action node pairs; swapping the order of the action nodes in the action node pairs in the third set of action node pairs, and determining whether the states of the behavior tree nodes before and after the swap are the same. If they are the same, adding the action node pairs before the swap to the first set of action node pairs; traversing the plurality of selected action node sets and generating a final first set of action node pairs; selecting the action node pairs in the final first set of action node pairs and establishing temporary parallel nodes, obtaining the parent nodes of the action nodes in the action node pairs, adding the temporary parallel nodes to the set of child nodes and deleting the action nodes in the action node pairs, running the behavior tree containing the temporary parallel nodes to generate a behavior tree execution sequence and recording the state of each node, and determining whether the state of the temporary parallel node is successful. If it is, adding the action node pairs to the second set of action node pairs; traversing the action node pairs in the final first set of action node pairs to generate a final second set of action node pairs.
[0057] In a specific example, in the behavior tree BT, the basic structure of the behavior tree includes node types. The behavior tree is composed of multiple nodes, each node represents a behavior or decision logic, and the nodes can be divided into the following types: root node, the starting point of the behavior tree, all behaviors are executed from the root node; leaf node, represents a specific behavior action or behavior condition, such as moving to the target position, etc.; leaf nodes are divided into execution nodes and condition nodes; execution nodes, execute specific behaviors or tasks, such as moving, attacking, etc.; condition nodes, check whether a certain addition is satisfied, usually return success or failure; control nodes, determine the execution order of child nodes, common control nodes include selection nodes, sequence nodes and parallel nodes; selection nodes, execute child nodes in sequence until a node returns success; if all child nodes fail, the selection node fails; if any child node succeeds, the selection node succeeds; sequence nodes, execute child nodes in sequence until a node returns failure, if all child nodes succeed, the sequence node succeeds; if any child node succeeds, the selection node succeeds; parallel nodes, execute multiple child nodes at the same time; decoration nodes, modify the behavior of child nodes, such as repeated execution, limiting the number of executions, etc.
[0058] Furthermore, the basic structure of the behavior tree also includes the execution process. The behavior tree starts from the root node and traverses the child nodes in sequence. The control node determines the execution order and logic of the leaf nodes. In the leaf nodes, the execution node completes the specific task, and the condition node checks whether the condition is met. The execution of the behavior tree is dynamic and will adjust the behavior according to the current state and environmental changes.
[0059] Furthermore, the basic structure of the behavior tree also includes return values, such as success, the node completes the task; failure, the node fails to complete the task; running, the node is in execution and has not yet completed.
[0060] Furthermore, for a given behavior tree BT, the behavior tree is regarded as a collection of tree nodes, and a formal method is used to represent the behavior tree nodes, node relationships, node states, and node state transfer functions.
[0061] Furthermore, any behavior tree node is represented by a tuple (node type, node name), where the node type can be one of a selection node "Selector", a sequence node "Sequence", a parallel node "Parallel", an action node "Action", and a condition node "Condition", and the node name is the specific name of the node.
[0062] Furthermore, for any behavior tree, nodes are represented by the symbol n, and node relationships are represented in the form of a tuple (parent node, child node set), and node relationships are represented by the symbol rn It is represented that the set of child nodes of a node can be found through the node relationship of the node.
[0063] Furthermore, the root node of the behavior tree is represented by the symbol n0, and the node relationship of the root node is represented by the symbol r n0 It is represented that the node relationship of the root node is a binary tuple (n0, {n1, n2,..., n k}) where n0 is the root node and {n1, n2,..., n k} is the set of child nodes of the root node.
[0064] Furthermore, the node state of any behavior tree node n can be one of "Success", "Failure" or "Running". Success means the node has completed the task, failure means the node has failed to complete the task, and running means the node is in the process of execution and has not been completed.
[0065] Furthermore, the node state transition function of any behavior tree node n is:
[0066] δ: n × S * → S
[0067] In the formula, δ represents the node state transition function, n is the node, and S * represents the node state in the set of child nodes of node n, and S represents the node state of node n.
[0068] It defines how a node updates its own state according to the states of its child nodes. Specifically, the state transition function updates its own node state according to different node types of the behavior tree and different states of the child nodes.
[0069] In a specific example, the state transition function of the behavior tree node that selects the node's state transition function is expressed as:
[0070]
[0071] In the formula, δ represents the node state transition function, (Selector, l) represents the selector node, where Selector is the node type of the selector node and l is the node name of the selector node, and [s1,..., s k represents the node states in the set of child nodes of the selector node. If there is a node state s i that is "Success", then the state of the selector node returns "Success"; if all node states s i are "Failure", then the state of the selector node returns "Failure"; in other cases, the state of the selector node returns "Running".
[0072] Furthermore, the state transition function of the sequential node is expressed as:
[0073]
[0074] In the formula, δ represents the node state transition function, (Sequence, l) represents the sequential node, where Sequence is the node type of the sequential node, l is the node name of the sequential node, [s1,..., s k represents the node states in the set of child nodes of the sequential node. If there exists a node state s i that is "Failure", then the state of the sequential node returns "Failure"; if all node states s i are "Success", then the state of the sequential node returns "Success"; in other cases, the state of the sequential node returns "Running".
[0075] Furthermore, the state transition function of the parallel node is expressed as:
[0076]
[0077] In the formula, δ represents the node state transition function, ((Parallel, l) represents the parallel node, where Parallel is the node type of the parallel node, l is the node name of the parallel node, [s1,..., s k represents the node states in the set of child nodes of the parallel node. According to a specific policy, check the state returns of the child nodes, and then return the state return value of the parallel node. If the states of the child nodes do not meet the specific policy, then the state of the parallel node returns "Failure"; if the specific policy is met, then the state of the parallel node returns "Success"; in other cases, the state of the parallel node returns "Running".
[0078] In a specific example, given two behaviors ω h , ω l ∈ Ω Φ , where ω h , ω l are the first behavior and the second behavior respectively, and Ω Φ represents the set of behaviors.
[0079] Define the following two relationships:
[0080] Sequential relationship, represented by the symbol , is a binary relationship representing the order of behaviors ω h , ω l , the order of precedence of ωh Must be started before ω l starts;
[0081] For non-parallel relationships, use the symbol to represent, which is a binary relation, indicating the behavior ω h , ω l cannot be executed in parallel simultaneously.
[0082] Obviously, given a set of behavior sets Ω Φ , the sequential relationship and the non-parallel relationship among the more behaviors, the more sequential constraints there are during the execution of these behaviors. This can be explained by two extreme cases: one is that there is no partial order relationship among the behaviors in the behavior set, which means that there are no sequential constraints for any behavior in the behavior set and they can be executed in parallel; the other is that there is a total order relationship among the behaviors in the behavior set, which means that for all behaviors in the set, each behavior can only start after its previous behavior is completed. As will be discussed later, fewer sequential constraints mean more parallel execution among behaviors, thus improving the efficiency of the entire system. Therefore, it is desirable to find a behavior tree decomposition with fewer partial order relationships.
[0083] In a specific example, in order to reduce the complete partial order relationship, a "swap" operation is introduced to change the order of adjacent nodes, and the node states of the behavior tree before and after the swap action node are detected to see if they are consistent. If so, this means that the relative order of these two adjacent child nodes can potentially be relaxed or removed from the partial order set. On the contrary, if this swap results in inconsistent node states of the behavior tree, it is explicitly retained in the partial order set.
[0084] Furthermore, for any node set corresponding to the non-parallel relationship, parallel nodes are constructed to allow the action nodes in the action node set to be executed in parallel. If this newly constructed parallel node can be successfully executed, it means that the action nodes in these action node sets do not belong to the partial order relationship.
[0085] What is obtained in this embodiment through the above method is a new effective behavior partial order set, which has fewer partial order constraints. It can achieve the maximum parallelization of the behavior tree operation.
[0086] In a specific example, the method specifically includes the following steps:
[0087] Step 1: Given the behavior tree BT, represented by a set of tree nodes, with N tree nodes in the set, generate an execution sequence in preorder traversal.
[0088] Specifically, for a given behavior tree BT, the behavior tree is represented as a set of tree nodes, and each tree node contains its node relationships. Starting from the root node n0, while searching for the node relationship of the root node The node relationship of the root node is represented by the symbol to represent, and find its set of child nodes; in a recursive manner, visit the nodes in the set of child nodes in turn n i , search for its node relationship, and use the symbol to represent, until the set of child nodes of the found node n i is an empty set; record the visited nodes in turn to form a node execution sequence, and the node execution sequence is represented as ρ = n0, n1, n2,..., n N-1 , where, n0, n1, n2,..., n N-1 means that each node in this execution sequence is a node in the behavior tree, and is represented by the symbol n i , where 0 ≤ i < N.
[0089] Step 2: Segment the node execution sequence ρ = n0, n1, n2,..., n N-1 by node type to generate a set Ρ of segmented node sequences.
[0090] Specifically, initially set the set Ρ of segmented node sequences to be an empty set, traverse each node in the node execution sequence. If the current node type is "Selector", "Sequence" or "Parallel", then add the sequence of nodes before this node to the set Ρ of segmented node sequences, and continue to traverse backward from the current node until all nodes are traversed.
[0091] Step 3: Count the number of segmented node sequences in the set Ρ of segmented node sequences. There are K segmented node sequences in total, and generate a node set for each segmented node sequence, for a total of K node sets.
[0092] Specifically, for each segmented node sequence ρ k in the set Ρ of segmented node sequences, generate a corresponding node set, 0 ≤ k < K. At the same time, remove the nodes in the node set whose node type is "Selector", "Sequence" or "Parallel".
[0093] Step 4: Traverse all K action node sets, select the node sets with more than 2 action nodes, count the number of action node sets with more than 2 action nodes. There are L action node sets in total, and each action node set is represented by B l , where 0 ≤ l < L.
[0094] Step 5: Set the set of action node pairs for which the behavior tree BT does not satisfy the sequential relationship to be Set the set of action node pairs in the behavior tree BT that satisfy the parallel relationship as I || , initialize to be an empty set, and initialize I || to be an empty set.
[0095] In this embodiment, a set of behavior that does not satisfy the partial order relationship is constructed by constructing a set of action node pairs that do not satisfy the sequential relationship and a set of action node pairs that satisfy the parallel relationship, thereby minimizing the behavior partial order set.
[0096] Step 6: For each set of action nodes B l , set the corresponding set of action node pairs I l , 0 ≤ l < L; the set of action node pairs I l is initialized to an empty set; for each set of action nodes B l , in a nested loop manner, the outer loop controls the first action node, and the inner loop controls the second action node. Two action nodes are selected in sequence to form an action node pair and put into the set of action pairs I l .
[0097] Step 7: Select an action node pair (n l , n i , n j ) from each set of action node pairs I j , exchange the order of the action nodes before and after to become (n i , n i ), and detect whether the node states of the behavior tree before and after the exchange of the action nodes are consistent.
[0098] Specifically, before the order of the action nodes is exchanged, given an input, run the behavior tree, generate the behavior tree execution sequence, and record the state of each node; after the order of the action nodes is exchanged, give the same input, run the behavior tree, generate the behavior tree execution sequence, and record the state of each node; detect whether the states of each behavior tree node before and after the node order is exchanged are consistent. If the behavior tree states are consistent before and after the action node exchange, add (n i , n j ) to the set of action node pairs that do not satisfy the sequential relationship .
[0099] Step 8: Traverse the L sets of action nodes, and repeat Step 6 and Step 7 until all L sets of action nodes have been processed, and construct the set of action node pairs in the behavior tree BT that do not satisfy the sequential relationship
[0100] Step 9: Count the number of action node pairs in the set of action node pairs that do not satisfy the sequential relationship , denoted as M; traverse the M action pairs, for a group of action pairs (n i, n j ), first, create a temporary parallel node n temp with (Parallel, Temp), and set the node relationship of the temporary parallel node to n temp , {n i , n j}, indicating that the two action nodes in the action node pair are the children of the temporary parallel node, the two action nodes are executed simultaneously, the states of both action nodes return successfully, and the state of this parallel node returns successfully; then, find the parent node n i , n j of the action nodes in the action node pair and find the node relationship of the parent node parent In add n to its child node set, and delete the action nodes n temp from the child node set i , n j ; then, run the behavior tree with the added parallel node, generate the behavior tree execution sequence, and record the state of each node; finally, check the node state of n temp . If the node state returns successfully, add the action node pair (n i , n j ) to the set I || of action nodes that satisfy the parallel relationship
[0101] Step 10: Until all M action pairs have been processed, construct the set I || of action node pairs that satisfy the parallel relationship, and at the same time, construct a new parallel behavior tree BT'.
[0102] This embodiment defines a behavior poset in combination with the concept of a poset, and uses the behavior poset to plan the execution order and dependency relationship of complex behaviors, analyzes the execution order of the behavior tree in combination with the behavior poset, and maximizes the parallelism of the behavior tree execution based on the minimization of the behavior poset; the core of the behavior model is to decompose complex behaviors into a series of behaviors and organize the execution order of these behaviors through the relationships between the behaviors; in combination with the behavior tree model and the poset, the behavior tree is used to control the behavior implementation for execution, and at the same time, the poset is used to plan the execution order and dependency relationship of complex behaviors; it is proposed to use the poset to represent the execution order relationship of the behaviors in the behavior tree model, and the construction of the behavior poset of the behavior tree is realized; an algorithm for maximizing the parallelism of the behavior execution in the behavior tree model is implemented to achieve the maximum parallelism of the behavior tree and ensure the correctness of the algorithm.
[0103] In a possible implementation, the generating of the execution sequence after establishing the behavior tree and accessing the root node and its set of child nodes of the behavior tree includes: accessing the root node of the behavior tree; recursively accessing the nodes in the set of child nodes in sequence and finding the corresponding node relationships until the set of child nodes is an empty set; recording the accessed nodes in sequence to form the execution sequence.
[0104] In a specific example, step 1 includes step 1.1: Given a behavior tree BT, represented by a set of tree nodes, where there are N tree nodes in the set, and each tree node contains its node relationship. Starting from the root node n0, at the same time, find the node relationship of the root node to find its set of child nodes.
[0105] Furthermore, the structure of the behavior tree is:
[0106]
[0107]
[0108] Among them, (Sequence, Fight) is the root node.
[0109] Furthermore, step 1 also includes step 1.2: In a recursive manner, access the nodes n in the set of child nodes in sequence i , find its node relationship until the found set of child nodes is an empty set.
[0110] Furthermore, starting from the root node (Sequence, Fight), find its node relationship as ((Sequence, Fight), {(Sequence, Attack), (Selector, Retreat)});
[0111] Access the node (Sequence, Attack), find its node relationship as ((Sequence, Attack), {(Action, MoveToTarget), (Action, Prepare), (Action, AttackEnemy)});
[0112] Access the node (Action, MoveToTarget), find its node relationship as ((Action, MoveToTarget), {}), and its set of child nodes is an empty set;
[0113] Access the node (Action, Prepare), find its node relationship as ((Action, Prepare), {}), and its child nodes are an empty set;
[0114] Visit the node (Action, AttackEnemy), find its node relationship is ((Action, AttackEnemy), {}), and its child node set is an empty set;
[0115] Visit the node (Selector, Retreat) and find its node relationship is ((Selector, Retreat), {(Condition, CheckHealth), (Action, Retreat)});
[0116] Visit the node (Condition, CheckHealth), find its node relationship is ((Condition, CheckHealth), {}), and its child node set is an empty set;
[0117] Visit the node (Action, Retreat) and find that its node relationship is ((Action, Retreat), {}) and its child nodes are an empty set.
[0118] Furthermore, step 1 also includes step 1.3: recording the visited nodes in sequence to form an executable sequence ρ = n0, n1, n2, ..., n N-1 ; Each node n of the path i All are nodes in the behavior tree, 0≤i <N。
[0119] Furthermore, the access nodes are recorded in sequence, and the generated execution sequence is expressed as ρ = [(Sequence, Fight), (Sequence, Attack), (Action, MoveToTarget), (Action, Prepare), (Action, AttackEnemy), (Selector, Retreat), (Condition, CheckHealth), (Action, Retreat)].
[0120] In one possible implementation, segmenting the execution sequence according to the node type to generate a segmented node sequence set includes: presetting the segmented node sequence set to an empty set; traversing each node in the execution sequence, and if the type of the current node is the first node type, the second node type, or the third node type, adding the sequences of all nodes before the current node to the segmented node sequence set, and continuing to traverse from the current node until all nodes are traversed.
[0121] In a specific example, step 2 includes step 2.1: presetting the segment node sequence set P to be an empty set,
[0122] Further, step 2 further includes step 2.2: traverse each node in the node execution sequence ρ = n0, n1,..., n N-1 If the current node type is the first node type "Selector", the second node type "Sequence", or the third node type "Parallel", then add the sequence of the nodes before this node to the segmented node sequence set Ρ, and continue to traverse backward from the current node until all nodes are traversed.
[0123] Further, let the segmented node sequence set Ρ be an empty set.
[0124] Further, the node (Sequence, Fight) in the node execution sequence being traversed is a sequential node.
[0125] Further, continue to traverse the node (Sequence, Attack), then add [(Sequence, Fight)] to the segmented node sequence set Ρ.
[0126] Further, continue to traverse the nodes in the node execution sequence until the node (Selector, Retreat) appears, and add [(Sequence, Attack), (Action, MoveToTarget), (Action, Prepare), (Action, AttackEnemy)] to the segmented node sequence set Ρ.
[0127] Further, continue to traverse the nodes in the node execution sequence, and add [(Selector, Retreat), (Condition, CheckHealth), (Action, Retreat)] to the segmented node sequence set Ρ.
[0128] In a possible implementation manner, the generating multiple action node sets corresponding to the multiple segmented node sequences in the segmented node sequence set includes: counting the number of segmented node sequences in the segmented node sequence set; setting the subscript and initial value of each segmented node sequence; generating the corresponding action node set for each segmented node sequence, and removing the nodes whose node types are the first node type, the second node type, or the third node type from the action node set.
[0129] In a specific example, step 3 includes step 3.1: count the number of segmented node sequences in the segmented node sequence set Ρ, denoted as K.
[0130] Further, Ρ = {[(Sequence, Fight)], [(Sequence, Attack), (Action, MoveToTarget), (Action, Prepare), (Action, AttackEnemy)], [(Selector, Retreat), (Condition, CheckHealth), (Action, Retreat)]}.
[0131] Further, the number of segmented node sequences in set P is 3, and K = 3.
[0132] Further, step 3 includes step 3.2: Set the subscript of each segmented node sequence in the segmented node sequence set Ρ to k, and the initial value of k is set to 0.
[0133] Further, step 3 includes step 3.3: Generate a node set corresponding to each segmented sequence. At the same time, remove the nodes in the node set whose node types are "Selector", "Sequence" or "Parallel", and k = k + 1.
[0134] Further, obtain {}, {(Action, MoveToTarget), (Action, Prepare),
[0135] (Action, AttackEnemy)}, {(Condition, CheckHealth), (Action, Retreat)}.
[0136] Further, step 3 includes step 3.4: When k < K, return to step 3.3.
[0137] In a possible implementation, the first preset value is greater than or equal to 2.
[0138] In a possible implementation, traversing multiple action node sets and selecting the action node sets with the number of action nodes greater than the first preset value, the obtained multiple selected action node sets include:
[0139] Further, step 4 includes step 4.1: Traverse all action node sets and select the node sets with the number of action nodes greater than 2.
[0140] Further, the selected node set with the number of action nodes greater than 2 is {(Action, MoveToTarget), (Action, Prepare), (Action, AttackEnemy)}.
[0141] Further, step 4 includes step 4.2: Count the number of node sets where the number of action nodes is greater than 2, denoted as L. Each action node set is represented by B1, where 0 ≤ l < L.
[0142] Further, the number of sets where the number of action nodes is greater than 2 is 1, L = 1.
[0143] In a possible implementation, the defined minimum behavior poset, the minimum behavior poset includes a first set of action node pairs where the behavior tree does not satisfy the order relationship and a second set of action node pairs where the behavior tree satisfies the parallel relationship, including: The preset first set of action node pairs where the behavior tree does not satisfy the order relationship is an empty set; The preset second set of action node pairs where the behavior tree satisfies the parallel relationship is an empty set.
[0144] In a specific example, step 5 includes: Set the set of action node pairs where the behavior tree BT does not satisfy the order relationship to Set the set of action node pairs where the behavior tree BT satisfies the parallel relationship to I || , initialize to be an empty set, and initialize I || to be an empty set;
[0145] In a possible implementation, for the selected action node set, establish a corresponding third set of action node pairs. For the selected action node set, use a nested loop to form action node pairs and put them into the third set of action node pairs, including: Set the subscript of the selected action node set and preset the corresponding third set of action node pairs to be an empty set; Use the outer loop to control the first action node in the action node set, use the inner loop to control the second action node in the action node set, and select two action nodes in sequence to form an action node pair and then put it into the third set of action node pairs.
[0146] In a specific example, step 6 includes step 6.1: In the node set where the number of action nodes is greater than 2, set the subscript of the action node set to l, the initial value of l is 0, and preset the action pair set I1 with subscript l, and initialize it to be an empty set.
[0147] Further, step 6 also includes step 6.2: For each action node set B l , use a nested loop, the outer loop controls the first action node, the inner loop controls the second action node, select two action nodes in sequence, form an action node pair, and put it into the action pair set I l , where 0 ≤ l < L.
[0148] Further, there are 3 pairs of generated action nodes, namely ((Action, MoveToTarget), (Action, Prepare)), ((Action, MoveToTarget), (Action, AttackEnemy)), and ((Action, Prepare), (Action, AttackEnemy)).
[0149] Further, step 6 further includes step 6.3: counting the number of action pairs in each set I of action nodes l which is denoted as N l ; counting the number of action pairs in the set I of action nodes l is 3, and N l = 3.
[0150] In a possible implementation manner, the method of swapping the order of the action nodes of the action node pairs in the third set of action node pairs and determining whether the states of the behavior tree nodes before and after the swap are the same. If they are the same, adding the action node pairs before the swap to the first set of action node pairs includes: setting the subscript of the action node pairs in the third set of action node pairs; selecting a group of action node pairs, running the behavior tree according to the given input, generating the execution sequence of the behavior tree before swapping the nodes and recording the state of each node; swapping the order of the action nodes in the action node pairs, running the behavior tree according to the given input, generating the execution sequence of the behavior tree after swapping the nodes and recording the state of each node; determining whether the states of each node before swapping the nodes and the states of each node after swapping the nodes are the same; if they are the same, adding the selected group of action node pairs to the first set of action node pairs.
[0151] In a specific example, step 7 includes step 7.1: in the set I1 of action node pairs, setting the subscript of the action node pair as nl, and the initial value of nl is set to 0.
[0152] Further, step 7 further includes step 7.2: selecting a group of action pairs (n i , n j ), and nl = nl + 1.
[0153] Further, select the action pair ((Action, MoveToTarget), (Action, Prepare)), and nl = nl + 1.
[0154] Further, step 7 includes step 7.2: swapping the order of the action nodes to become (n j , n i ); before swapping the order of the action nodes, given an input, run the behavior tree, generate the execution sequence of the behavior tree, and record the state of each node.
[0155] Further, before the action node pair is swapped, given an input, the behavior tree is run, and the states of each node in the behavior tree execution sequence [(Sequence, Fight), (Sequence, Attack), (Action, MoveToTarget), (Action, Prepare), (Action, AttackEnemy), (Selector, Retreat), (Condition, CheckHealth), (Action, Retreat)] are [success, success, success, success, success, success, Failure, success] respectively.
[0156] Further, step 7 includes step 7.3: After the action node order is swapped, for the same input, the behavior tree is run, the behavior tree execution sequence is generated, and the state of each node is recorded.
[0157] Further, the action node pair is swapped, for the same input, the behavior tree is run, and the states of each node in the behavior tree execution sequence [(Sequence, Fight), (Sequence, Attack), (Action, Prepare), (Action, MoveToTarget), (Action, AttackEnemy), (Selector, Retreat), (Condition, CheckHealth), (Action, Retreat)] are [success, success, success, success, success, success, Failure, success] respectively.
[0158] Further, step 7 includes step 7.4: Detect whether the states of each behavior tree node are the same before and after the node order is swapped; the behavior tree node states of [success, success, success, success, success, success, Failure, success] and [success, success, success, success, success, success, Failure, success] are the same.
[0159] Further, step 7 includes step 7.5: Before and after the action nodes are swapped, if the behavior tree states are the same, add (n i , n j ) to the set of action node pairs that do not satisfy the order relationship in.
[0160] Further, add ((Action, MoveToTarget), (Action, Prepare)) to the set of action nodes that do not satisfy the sequential relationship among them.
[0161] In a possible implementation, the traversing of multiple selected sets of action nodes and generating the final set of first action node pairs includes:
[0162] Step 8.1: When nl < N l , return to Step 7.2.
[0163] Step 8.2: When l < L, return to Step 6.2.
[0164] Step 8.3: When l is equal to L, construct the set of action node pairs that do not satisfy the sequential relationship of the completed behavior tree BT
[0165] Further, construct the set of action node pairs that do not satisfy the sequential relationship as {((Action, MoveToTarget), (Action, Prepare))}.
[0166] In a possible implementation, the selecting of the action node pairs in the final set of first action node pairs and establishing a temporary parallel node, obtaining the parent nodes of the action nodes in the action node pairs, adding the temporary parallel node to the set of child nodes and deleting the action nodes in the action node pairs includes: setting the subscript of the action node pairs in the final set of first action node pairs; selecting the action node pairs in the final set of first action node pairs; establishing the node relationship of the temporary parallel node and the temporary parallel node; obtaining the parent nodes of the action nodes in the action node pairs and finding the node relationship of the parent nodes, adding the temporary parallel node to the set of child nodes in the node relationship of the parent nodes, and deleting the action nodes in the action node pairs from the set of child nodes.
[0167] In a specific example, Step 9 includes Step 9.1: Count the number of action node pairs in the set of action node pairs that do not satisfy the sequential relationship and denote it as M.
[0168] Further, count the number of action node pairs in the set of action node pairs that do not satisfy the sequential relationship as 1, M = 1.
[0169] Further, Step 9 also includes Step 9.2: Set the subscript of the action node pairs that do not satisfy the sequential relationship as m, and set the initial value of m to 0.
[0170] Furthermore, step 9 also includes step 9.3: selecting an action pair (n i , n j ), m=m+1.
[0171] Further, select ((Action, MoveToTarget), (Action, Prepare)).
[0172] Furthermore, step 9 also includes step 9.4: creating a temporary parallel node n temp (Parallel, Temp) and set the node relationship of the temporary parallel node for (n temp ,{n i ,n j}), indicating that the two action nodes in the action node pair are child nodes of the temporary parallel node, the two action nodes are executed simultaneously, the status of both action nodes return success, and the status of the parallel node returns success.
[0173] First, create a temporary parallel node n temp (Parallel, Temp) and set the node relationship of the temporary parallel node is ((Parallel, Temp), {(Action, MoveToTarget), (Action, Prepare)}).
[0174] Furthermore, step 9 also includes step 9.5: finding the action node n in the action node pair i ,n j The parent node n parent And find the node relationship of the parent node exist Lieutenant General temp Add to its child node set and delete action node n from the child node set i ,n j .
[0175] Further, the parent nodes of the action nodes (Action, MoveToTarget) and (Action, Prepare) are found to be (Sequence, Attack). The node relationship of the node (Sequence, Attack) is ((Sequence, Attack), {(Action, MoveToTarget), (Action, Prepare), (Action, AttackEnemy)}). (Parallel, Temp) is added to the set of child nodes, and (Action, MoveToTarget) and (Action, Prepare) are deleted, resulting in ((Sequence, Attack), {(Parallel, Temp), (Action, AttackEnemy)}).
[0176] Further, step 9 also includes step 9.6: Run the behavior tree with the added parallel node to generate a behavior tree execution sequence and record the status of each node; Run the behavior tree to obtain the behavior tree execution sequence [(Sequence, Fight), (Sequence, Attack), (Parallel, Temp), {(Action, MoveToTarget), (Action, Prepare)}, (Action, AttackEnemy), (Selector, Retreat), (Condition, CheckHealth), (Action, Retreat)], where (Action, MoveToTarget) and (Action, Prepare) are executed simultaneously;
[0177] Further, step 9 also includes step 9.7: Check the temp node status of n. If the node status is successful, i.e., success, then add the action node pair (n i , n j ) to the set I ‖ of action node pairs that satisfy the parallel relationship.
[0178] Further, the status of (Parallel, Temp) is obtained as success, and ((Action, MoveToTarget), (Action, Prepare)) is added to the set I ‖ of action node pairs that satisfy the parallel relationship.
[0179] In a possible implementation manner, traversing the action node pairs in the final first action node pair set to generate the final second action node pair set includes: constructing a new parallel behavior tree.
[0180] In a specific example, step 10 includes step 10.1: when m < M, return to step 9.3;
[0181] Furthermore, step 10 further includes step 10.2: when m = M, construct a set I of action node pairs that satisfy the parallel relationship ‖ , and at the same time, construct a new parallel behavior tree.
[0182] Furthermore, constructing a set I of action node pairs that satisfy the parallel relationship ‖ is {((Action, MoveToTarget), (Action, Prepare))}, and constructing a parallel behavior tree BT ′ is:
[0183]
[0184] This embodiment combines the behavioral poset to analyze the execution order of behaviors, and realizes the maximization of parallelism in behavior execution based on the minimization of the behavioral poset; the core of the behavior tree model is to decompose complex behaviors into a series of behaviors, and organize the execution order of these behaviors through the relationships between behaviors; the technical solution of the present invention combines the behavior tree model and the poset, uses the behavior tree to control the execution of behaviors, and at the same time uses the poset to plan the execution order and dependency relationships of complex behaviors; it proposes to use the poset to represent the execution order relationship of the behavior tree model behaviors, and realizes the construction of the behavioral poset of the behavior tree; an algorithm for maximizing the parallelism of behavior execution in the behavior tree model is used to achieve the maximization of parallelism of the behavior tree.
[0185] Obviously, the above embodiments of the present invention are only examples for clearly explaining the present invention, rather than limitations on the embodiments of the present invention. For those of ordinary skill in the art, other different forms of changes or modifications can be made based on the above description. It is impossible to list all the embodiments here. Any obvious changes or modifications derived from the technical solutions of the present invention still fall within the protection scope of the present invention.
Claims
1. A method for parallelizing a behavior model based on a minimal behavior poset, characterized in that, The method includes: Building a behavior tree and generating an execution sequence after accessing the root node and the set of child nodes of the behavior tree; Segmenting the execution sequence according to the node type to generate a set of segmented node sequences; Generating a plurality of action node sets corresponding to the plurality of segmented node sequences in the set of segmented node sequences; Traversing the plurality of action node sets and selecting the action node sets with the number of action nodes greater than a first preset value to obtain a plurality of selected action node sets; Defining a minimum behavior poset, where the minimum behavior poset includes a first set of action node pairs where the behavior tree does not satisfy the order relationship and a second set of action node pairs where the behavior tree satisfies the parallel relationship; Establishing a corresponding third set of action node pairs for the selected action node sets, and forming action node pairs in the selected action node sets in a nested loop manner and putting them into the third set of action node pairs; Exchanging the order of the action nodes in the action node pairs in the third set of action node pairs, and determining whether the states of the behavior tree nodes before and after the exchange are the same. If they are the same, adding the action node pairs before the exchange to the first set of action node pairs; Traversing the plurality of selected action node sets and generating a final first set of action node pairs; Selecting the action node pairs in the final first set of action node pairs and establishing temporary parallel nodes, obtaining the parent nodes of the action nodes in the action node pairs, adding the temporary parallel nodes to the set of child nodes and deleting the action nodes in the action node pairs, running the behavior tree containing the temporary parallel nodes to generate a behavior tree execution sequence and recording the state of each node, and determining whether the state of the temporary parallel node is successful. If it is, adding the action node pairs to the second set of action node pairs; Traversing the action node pairs in the final first set of action node pairs to generate a final second set of action node pairs.
2. The method according to claim 1, wherein The building of the behavior tree and generating an execution sequence after accessing the root node and its set of child nodes of the behavior tree includes: Accessing the root node of the behavior tree; Sequentially accessing the nodes in the set of child nodes in a recursive manner and finding the corresponding node relationships until the set of child nodes is an empty set; Sequentially recording the accessed nodes to form an execution sequence.
3. The method according to claim 2, wherein The segmenting of the execution sequence according to the node type to generate a set of segmented node sequences includes: Pre-setting the set of segmented node sequences to be an empty set; Traversing each node in the execution sequence. If the type of the current node is the first node type, the second node type, or the third node type, adding the sequence of all nodes before the current node to the set of segmented node sequences, and continuing to traverse from the current node until all nodes are traversed.
4. The method according to claim 3, wherein The generating of a plurality of action node sets corresponding to the plurality of segmented node sequences in the set of segmented node sequences includes: Counting the number of segmented node sequences in the set of segmented node sequences; Setting the subscript and initial value of each segmented node sequence; Generate a corresponding set of action nodes for each segmented node sequence, and remove the nodes in the set of action nodes whose node types are the first node type, the second node type, or the third node type.
5. The method according to claim 4, wherein The first preset value is greater than or equal to 2.
6. The method according to claim 5, wherein The defining of the minimum behavior poset, the minimum behavior poset includes a first set of action node pairs where the behavior tree does not satisfy the order relationship and a second set of action node pairs where the behavior tree satisfies the parallel relationship, including: The preset first set of action node pairs where the behavior tree does not satisfy the order relationship is an empty set; The preset second set of action node pairs where the behavior tree satisfies the parallel relationship is an empty set.
7. The method according to claim 6, wherein The establishing of a corresponding third set of action node pairs for the selected set of action nodes, and forming action node pairs in a nested loop manner for the selected set of action nodes and putting them into the third set of action node pairs, including: Set the subscript of the selected set of action nodes and preset the corresponding third set of action node pairs as an empty set; Use the outer loop to control the first action node in the set of action nodes, use the inner loop to control the second action node in the set of action nodes, and select two action nodes in sequence to form an action node pair and put it into the third set of action node pairs.
8. The method according to claim 7, wherein The swapping of the order of the action nodes in the action node pairs in the third set of action node pairs, and determining whether the states of the behavior tree nodes before and after the swapping are the same. If they are the same, then add the action node pair before the swapping to the first set of action node pairs, including: Set the subscript of the action node pairs in the third set of action node pairs; Select a group of action node pairs, run the behavior tree according to the given input, generate the behavior tree execution sequence before swapping the nodes and record the state of each node; Swap the order of the action nodes in the action node pair, run the behavior tree according to the given input, generate the behavior tree execution sequence after swapping the nodes and record the state of each node; Determine whether the state of each node before swapping the nodes is the same as the state of each node after swapping the nodes; If they are the same, then add the selected group of action node pairs to the first set of action node pairs.
9. The method according to claim 8, wherein The selecting of the action node pairs in the final first set of action node pairs and establishing a temporary parallel node, obtaining the parent nodes of the action nodes in the action node pair, adding the temporary parallel node to the set of child nodes and deleting the action nodes in the action node pair, including: Set the subscript of the action node pairs in the final first set of action node pairs; Select the action node pairs in the final first set of action node pairs; Establish the node relationship of the temporary parallel node and the temporary parallel node; Obtain the parent nodes of the action nodes in the action node pair and find the node relationship of the parent nodes, add the temporary parallel node to the set of child nodes in the node relationship of the parent nodes, and delete the action nodes in the action node pair from the set of child nodes.
10. The method according to claim 9, wherein Generating the final set of second action node pairs for the action node pairs in the finally traversed first set of action node pairs includes: constructing a new parallel behavior tree.