tree.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:ptreeopt 作者: jdherman 项目源码 文件源码
def graphviz_export(self, filename, dpi = 300):

    import pygraphviz as pgv
    G = pgv.AGraph(directed=True)
    G.node_attr['shape'] = 'box'
    # G.graph_attr['size'] = '2!,2!' # use for animations only
    # G.graph_attr['dpi'] = str(dpi)

    parent = self.root
    G.add_node(str(parent))
    S = []

    while parent.is_feature or len(S) > 0:
      if parent.is_feature:
        S.append(parent)
        child = parent.l
        label = 'T'

      else:
        parent = S.pop()
        child = parent.r
        label = 'F'

      G.add_node(str(child))
      G.add_edge(str(parent), str(child), label=label)
      parent = child

    G.layout(prog='dot')
    G.draw(filename)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号