From dd437506aac0a9df0a200da993e057557900b9d1 Mon Sep 17 00:00:00 2001 From: liuwz Date: Tue, 19 Mar 2024 19:15:52 +0800 Subject: [PATCH 1/2] reduce circulation when the parallel node policy is SuccessOnOne --- py_trees/composites.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/py_trees/composites.py b/py_trees/composites.py index 072b426c..947b6c28 100644 --- a/py_trees/composites.py +++ b/py_trees/composites.py @@ -731,14 +731,12 @@ def tick(self) -> typing.Iterator[behaviour.Behaviour]: new_status = common.Status.SUCCESS self.current_child = self.children[-1] elif type(self.policy) is common.ParallelPolicy.SuccessOnOne: - successful = [ - child - for child in self.children - if child.status == common.Status.SUCCESS - ] - if successful: - new_status = common.Status.SUCCESS - self.current_child = successful[-1] + for index in range(len(self.children) - 1, -1, -1): + child = self.children[index] + if child.status == common.Status.SUCCESS: + new_status = common.Status.SUCCESS + self.current_child = child + break elif type(self.policy) is common.ParallelPolicy.SuccessOnSelected: if all( [c.status == common.Status.SUCCESS for c in self.policy.children] From 777162bb0944e657348b0ce12c0a8ec30deded2b Mon Sep 17 00:00:00 2001 From: wanfeng <42433161+starrye@users.noreply.github.com> Date: Tue, 3 Sep 2024 10:59:48 +0800 Subject: [PATCH 2/2] [composites]Update Syntax --- py_trees/composites.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/py_trees/composites.py b/py_trees/composites.py index 30253df9..6326cb48 100644 --- a/py_trees/composites.py +++ b/py_trees/composites.py @@ -731,8 +731,7 @@ def tick(self) -> typing.Iterator[behaviour.Behaviour]: new_status = common.Status.SUCCESS self.current_child = self.children[-1] elif type(self.policy) is common.ParallelPolicy.SuccessOnOne: - for index in range(len(self.children) - 1, -1, -1): - child = self.children[index] + for child in reversed(self.children): if child.status == common.Status.SUCCESS: new_status = common.Status.SUCCESS self.current_child = child