如何使graphviz重复图形中的节点以创建树状图像?

时间:2012-12-04 12:44:03

标签: graph tree graphviz dot

我在graphviz上有以下图表:

Original graph with converging paths

如何让graphviz重复图形中的节点,这样我就能得到像这样的树状图像:

Derived tree with repeated labels

1 个答案:

答案 0 :(得分:1)

我认为你不能在graphviz中修改图形。您应该使用您想要的结构为graphviz提供不同的图形。该图可以通过如下过程(伪代码)获得:

function visit(path: a list of nodes):
  let n be the last node on the path
  for every child c of n:
    write (a copy of) c to output
    if c is not in path:
      visit(path + [c])
write root to output
visit([root])

您可以在递归调用之前将节点标记为path,而不是此列表visited,并在调用后删除该标志:

function visit(n: a node):
  mark n as visited
  for every child c of n:
    write (a copy of) c to output
    if c is not marked as visited:
      visit(c)
  mark n as not visited
write root to output
visit(root)