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


Python Tree.create_node方法代码示例

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


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

示例1: create_family_tree

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import create_node [as 别名]
def create_family_tree():
    ## Create the family tree
    tree = Tree()
    tree.create_node("Harry", "harry")  # root node
    tree.create_node("Jane", "jane", parent="harry")
    tree.create_node("Bill", "bill", parent="harry")
    tree.create_node("Diane", "diane", parent="jane")
    tree.create_node("Mary", "mary", parent="diane")
    tree.create_node("Mark", "mark", parent="jane")
    return tree
开发者ID:suresh852456,项目名称:external,代码行数:12,代码来源:family_tree.py

示例2: DecisionTree

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import create_node [as 别名]

#.........这里部分代码省略.........
            if isinstance(value_dict, dict):
                new_value = min(value_dict.keys())
                if new_value < min_value[0]:
                    min_value = (
                        new_value,
                        key,
                        counted_attribs[key].get(new_value),

                    )
        return min_value, comp_entropy

    def generate_tree(
        self, parent=None, atrr_names=None, training_data=None
    ):
        if not atrr_names:
            return self.decision_tree
        counted_attribs = self.entropy_counter(
            atrr_names=atrr_names, training_data=training_data
        )
        lower_entropy, comp_entropy = self.get_lower_entropy(
            counted_attribs,
            attr_names=atrr_names
        )

        if not lower_entropy:
            return self.decision_tree

        ATTRIBUTE_NAMES = {atrr_names[value]: value for value in atrr_names}
        entropy, attribute_name, attribute_value = lower_entropy
        attribute_line = ATTRIBUTE_NAMES.pop(attribute_name)

        if not self.decision_tree.nodes:
            root = self.create_identifier(attribute_name, attribute_name)
            self.decision_tree.create_node(
                name=attribute_name,
                identifier=root
            )
            for attr_value in self.ATTRIBUTE_VALUES:
                name = self.create_identifier(attribute_name, attr_value)
                self.decision_tree.create_node(
                    name=name,
                    identifier=name,
                    parent=root
                )
                if attr_value != attribute_value:
                    victory = self.create_identifier(
                        attribute_name, attr_value, 'True'
                    )
                    self.decision_tree.create_node(
                        name=victory,
                        identifier=victory,
                        parent=name
                    )
            parent = self.create_identifier(attribute_name, attribute_value)

        elif parent:
            if entropy < comp_entropy:
                for attr_value in self.ATTRIBUTE_VALUES:
                    name = self.create_identifier(attribute_name, attr_value)
                    self.decision_tree.create_node(
                        name=name,
                        identifier=name,
                        parent=parent
                    )
                    if attr_value != attribute_value:
                        victory = self.create_identifier(
开发者ID:Rivinek,项目名称:Inteligent-Garbage,代码行数:70,代码来源:decision_tree.py

示例3: print

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import create_node [as 别名]
    print(','.join([tree[node].tag for node in tree.expand_tree()]))

    example("All family members (with identifiers) but Diane's sub-family:")
    tree.show(idhidden=False, filter=lambda x: x.identifier != 'diane')

    example("Let me introduce Diane family only:")
    sub_t = tree.subtree('diane')
    sub_t.show()

    example("Children of Diane:")
    for child in tree.is_branch('diane'):
        print(tree[child].tag)

    example("New members join Jill's family:")
    new_tree = Tree()
    new_tree.create_node("n1", 1)  # root node
    new_tree.create_node("n2", 2, parent=1)
    new_tree.create_node("n3", 3, parent=1)
    tree.paste('bill', new_tree)
    tree.show()

    example("They leave after a while:")
    tree.remove_node(1)
    tree.show()

    example("Now Mary moves to live with grandfather Harry:")
    tree.move_node('mary', 'harry')
    tree.show()

    example("A big family for Mark to send message to the oldest Harry:")
    print(','.join([tree[node].tag for node in tree.rsearch('mark')]))
开发者ID:suresh852456,项目名称:external,代码行数:33,代码来源:family_tree.py

示例4: Tree

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import create_node [as 别名]
		if new_score >= current_score:
			break
		else:
			current_score = new_score


if __name__ == "__main__":
	file_name = sys.argv[1]
	tree = Tree()
	r = c = -1
	#build initial tree
	with open(file_name, 'r') as fp:
		lines = fp.readlines()
		r, c = map(int, lines[0].split())
		current_row = 0
		tree.create_node(identifier="root")
		for line in lines[1:]:
			tree.create_node(LineMarker(current_row), identifier=current_row, parent="root")
			current_col = 0
			for ch in line: 
				if ch == '#':
					tree.create_node(SquareCommand(current_row, current_col, 0), parent=current_row)
				current_col += 1
			current_row += 1

	#print(tree)

	#try reduce

	optimize(tree, r)
开发者ID:VenturaDelMonte,项目名称:google-hashcode2016,代码行数:32,代码来源:solver2.py


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