当前位置: 首页>>代码示例>>Python>>正文


Python Tree.parent方法代码示例

本文整理汇总了Python中treelib.Tree.parent方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.parent方法的具体用法?Python Tree.parent怎么用?Python Tree.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在treelib.Tree的用法示例。


在下文中一共展示了Tree.parent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_modify_node_identifier_root

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import parent [as 别名]
 def test_modify_node_identifier_root(self):
     tree = Tree()
     tree.create_node("Harry", "harry")
     tree.create_node("Jane", "jane", parent="harry")
     tree.update_node(tree['harry'].identifier, identifier='xyz', tag='XYZ')
     self.assertTrue(tree.root == 'xyz')
     self.assertTrue(tree['xyz'].tag == 'XYZ')
     self.assertEqual(tree.parent('jane').identifier, 'xyz')
开发者ID:caesar0301,项目名称:treelib,代码行数:10,代码来源:test_tree.py

示例2: StateMachine

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import parent [as 别名]
class StateMachine(object):
    """A class to track information about a state machine"""

    def __init__(self, name):
        self.name = name
        self.events = {}
        self.effects = {}
        self.state_tree = Tree()
        self.current_state = None

        # Add the Root state automatically
        self.add_state('Root')

    def add_state(self, name):
        assert isinstance(name, str)
        state_node = Node(identifier=name, data=State(name))

        if self.current_state is None:
            self.state_tree.add_node(state_node)
            self.current_state = state_node.data
        else:
            self.state_tree.add_node(state_node, self.current_state.name)

    def add_event(self, ev):
        assert isinstance(ev, Event)
        self.events[ev.name] = ev

    def add_effect(self, eff):
        assert isinstance(eff, Effect)
        self.effects[eff.name] = eff

    def enter_state(self, state):
        self.current_state = state

    def exit_state(self, state):
        self.current_state = self.state_tree.parent(state.name).data

    def get_state_by_name(self, state_name):
        return self.state_tree.get_node(state_name).data
开发者ID:r-chaves,项目名称:plantuml-codegen,代码行数:41,代码来源:sm_entities.py

示例3: crossOver

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import parent [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)
开发者ID:liranr23,项目名称:genersi,代码行数:25,代码来源:individual.py

示例4: test_subtree

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import parent [as 别名]
 def test_subtree(self):
     subtree_copy = Tree(self.tree.subtree("jane"), deep=True)
     self.assertEqual(subtree_copy.parent("jane") is None, True)
     subtree_copy["jane"].tag = "Sweeti"
     self.assertEqual(self.tree["jane"].tag == "Jane", True)
     self.assertEqual(subtree_copy.level("diane"), 1)
     self.assertEqual(subtree_copy.level("jane"), 0)
     self.assertEqual(self.tree.level("jane"), 1)
开发者ID:Mondego,项目名称:pyreco,代码行数:10,代码来源:allPythonContent.py


注:本文中的treelib.Tree.parent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。