def _to_dot(self):
"""Converts graph in dot format.
`label` property of is used as short description of each node.
Returns:
str: The graph in dot format.
"""
ret = "digraph graphname{"
for node in self.nodes:
assert isinstance(node, (variable.Variable, function.Function))
if isinstance(node, variable.Variable):
ret += DotNode(node, self.variable_style).label
else:
ret += DotNode(node, self.function_style).label
for edge in self.edges:
head, tail = edge
if (isinstance(head, variable.Variable) and
isinstance(tail, function.Function)):
head_attr = self.variable_style
tail_attr = self.function_style
elif (isinstance(head, function.Function) and
isinstance(tail, variable.Variable)):
head_attr = self.function_style
tail_attr = self.variable_style
else:
raise TypeError(
'head and tail should be the set of Variable and Function')
head_node = DotNode(head, head_attr)
tail_node = DotNode(tail, tail_attr)
ret += "%s -> %s;" % (head_node.id_, tail_node.id_)
ret += "}"
return ret
评论列表
文章目录