Allow to specify output of a chain in the Graph class.

This commit is contained in:
Romain Dorgueil
2017-05-13 15:26:51 +02:00
parent 697b3e539e
commit aa6da3aa2b

View File

@ -21,11 +21,17 @@ class Graph:
self.nodes.append(c)
return i
def add_chain(self, *nodes, _input=BEGIN):
def add_chain(self, *nodes, _input=BEGIN, _output=None):
for node in nodes:
_next = self.add_node(node)
self.outputs_of(_input, create=True).add(_next)
_input = _next
if _output:
if not _output in self.nodes:
raise ValueError('Output not found.')
self.outputs_of(_input, create=True).add(self.nodes.index(_output))
return self
def __len__(self):
return len(self.nodes)