Skip to content

Commit

Permalink
remove previous unecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jashlu committed Sep 10, 2024
1 parent 19bc6b4 commit d760b23
Showing 1 changed file with 6 additions and 58 deletions.
64 changes: 6 additions & 58 deletions src/social_norms_trees/mutate_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def format_children_with_indices(composite: py_trees.composites.Composite) -> st
return output


def format_tree_with_indices(tree: py_trees.behaviour.Behaviour, mode: str = "all") -> str:
def format_tree_with_indices(tree: py_trees.behaviour.Behaviour) -> str:
"""
Examples:
>>> print(format_tree_with_indices(py_trees.behaviours.Dummy()))
Expand Down Expand Up @@ -172,20 +172,8 @@ def format_tree_with_indices(tree: py_trees.behaviour.Behaviour, mode: str = "al
7: --> p
"""
index_strings = []
index = 0
for i, node in enumerate_nodes(tree):
if mode == "children" and node.children:
# Do not number parent nodes in 'children' mode
index_strings.append('_')
elif mode == "parents" and not node.children:
# Do not number child nodes in 'parents' mode
index_strings.append('_')
else:
# Number all nodes in 'all' mode
index_strings.append(str(index))
index += 1

index_strings = [str(i) for i, _ in enumerate_nodes(tree)]

output = label_tree_lines(tree, index_strings)

Expand All @@ -200,10 +188,9 @@ def prompt_identify_node(
tree: py_trees.behaviour.Behaviour,
message: str = "Which node?",
display_nodes: bool = True,
mode: str = "all"
) -> py_trees.behaviour.Behaviour:
node_index = prompt_identify_tree_iterator_index(
tree=tree, message=message, display_nodes=display_nodes, mode=mode
tree=tree, message=message, display_nodes=display_nodes
)
node = next(islice(iterate_nodes(tree), node_index, node_index + 1))
return node
Expand All @@ -213,10 +200,9 @@ def prompt_identify_tree_iterator_index(
tree: py_trees.behaviour.Behaviour,
message: str = "Which position?",
display_nodes: bool = True,
mode: str = "all"
) -> int:
if display_nodes:
text = f"{format_tree_with_indices(tree, mode)}\n{message}"
text = f"{format_tree_with_indices(tree)}\n{message}"
else:
text = f"{message}"
node_index = click.prompt(
Expand Down Expand Up @@ -302,7 +288,7 @@ def remove_node(tree: T, node: Optional[py_trees.behaviour.Behaviour] = None) ->
"""
if node is None:
node = prompt_identify_node(tree, f"Which node do you want to remove?", True, "children")
node = prompt_identify_node(tree, f"Which node do you want to remove?")
parent_node = node.parent
if parent_node is None:
warnings.warn(
Expand Down Expand Up @@ -409,42 +395,4 @@ def exchange_nodes(
tree = move_node(tree, node0, node1_parent, node1_index)
tree = move_node(tree, node1, node0_parent, node0_index)

return tree


# if __name__ == "__main__":


# tree = py_trees.composites.Sequence(
# "",
# False,
# children=[
# py_trees.behaviours.Dummy(),
# py_trees.behaviours.Dummy(),
# py_trees.composites.Sequence(
# "",
# False,
# children=[
# py_trees.behaviours.Success(),
# py_trees.behaviours.Dummy(),
# ],
# ),
# py_trees.composites.Sequence(
# "",
# False,
# children=[
# py_trees.behaviours.Dummy(),
# py_trees.behaviours.Failure(),
# py_trees.behaviours.Dummy(),
# py_trees.behaviours.Running(),
# ],
# ),
# ],
# )

# print(py_trees.display.ascii_tree(tree))
# move_node(tree)
# exchange_nodes(tree)
# remove_node(tree)
# print(format_tree_with_indices(tree))
# print("Done with demo!")
return tree

0 comments on commit d760b23

Please sign in to comment.