Allow to specify output of a chain in the Graph class.
This commit is contained in:
@ -21,11 +21,17 @@ class Graph:
|
|||||||
self.nodes.append(c)
|
self.nodes.append(c)
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def add_chain(self, *nodes, _input=BEGIN):
|
def add_chain(self, *nodes, _input=BEGIN, _output=None):
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
_next = self.add_node(node)
|
_next = self.add_node(node)
|
||||||
self.outputs_of(_input, create=True).add(_next)
|
self.outputs_of(_input, create=True).add(_next)
|
||||||
_input = _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):
|
def __len__(self):
|
||||||
return len(self.nodes)
|
return len(self.nodes)
|
||||||
|
|||||||
Reference in New Issue
Block a user