本文整理汇总了Python中treelib.Tree.remove_subtree方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.remove_subtree方法的具体用法?Python Tree.remove_subtree怎么用?Python Tree.remove_subtree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treelib.Tree
的用法示例。
在下文中一共展示了Tree.remove_subtree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: crossOver
# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import remove_subtree [as 别名]
def crossOver(individualA, individualB):
tree = None
while tree is None or tree.depth(tree.get_node(tree.root)) > TREE_MAX_DEPTH:
treeA = Tree(tree = individualA.tree, deep=True)
treeB = Tree(tree = individualB.tree, deep=True)
regenerate_ids(treeA)
regenerate_ids(treeB)
removedNode = random.choice(treeA.all_nodes())
addedNode = random.choice(treeB.all_nodes())
addedSubtree = Tree(tree = treeB.subtree(addedNode.identifier), deep=True)
if treeA.root == removedNode.identifier:
tree = addedSubtree
else:
parent = treeA.parent(removedNode.identifier)
treeA.remove_subtree(removedNode.identifier)
treeA.paste(parent.identifier, addedSubtree)
tree = treeA
return Individual(tree)