|
|
@@ -1,11 +1,9 @@
|
|
|
-""" This module implements a dependency graph
|
|
|
+"""
|
|
|
+This module implements a dependency graph
|
|
|
|
|
|
-:Author: Marc Provost
|
|
|
-:Organization: McGill University
|
|
|
-:License: GNU General Public License
|
|
|
-:Contact: marc.provost@mail.mcgill.ca
|
|
|
+:Original Author: Marc Provost
|
|
|
"""
|
|
|
-from .Core import CBD, BaseBlock
|
|
|
+from .Core import CBD, BaseBlock, Port
|
|
|
import copy
|
|
|
|
|
|
|
|
|
@@ -138,6 +136,7 @@ class DepGraph:
|
|
|
ValueError: if the dependency already exists
|
|
|
"""
|
|
|
# TODO: fix infinite cycle when passing straight through
|
|
|
+ # TODO: fix errors when multi-level connection
|
|
|
|
|
|
# Link CBD outputs
|
|
|
if isinstance(influencer, CBD) and not self.ignore_hierarchy:
|
|
|
@@ -147,10 +146,7 @@ class DepGraph:
|
|
|
for inp in dependent.getInputPorts():
|
|
|
inf_out = inp.getIncoming().source
|
|
|
if inf_out.block == influencer:
|
|
|
- inf = inf_out.getIncoming().source
|
|
|
- if inf.block == influencer:
|
|
|
- # Look beyond, because normal connection is straight-through
|
|
|
- inf = inf.getIncoming().source
|
|
|
+ inf = inp.getPreviousPortClosure()
|
|
|
self.setDependency(dependent, inf.block, curIt)
|
|
|
return
|
|
|
|
|
|
@@ -160,17 +156,11 @@ class DepGraph:
|
|
|
# more than one dependency should be set, as there is more than one underlying
|
|
|
# connection
|
|
|
for inp in dependent.getInputPorts():
|
|
|
- inf_out = inp.getIncoming().source
|
|
|
- while isinstance(inf_out.block, CBD):
|
|
|
- inf_out = inf_out.getIncoming().source
|
|
|
+ inf_out = inp.getPreviousPortClosure()
|
|
|
if inf_out.block == influencer:
|
|
|
- for conn in inp.getOutgoing():
|
|
|
- dep = conn.target
|
|
|
- if dep.block == dependent:
|
|
|
- # Look beyond, because normal connection is straight-through
|
|
|
- for c2 in dep.getOutgoing():
|
|
|
- self.setDependency(c2.target.block, influencer, curIt)
|
|
|
- else:
|
|
|
+ for dep in inp.getNextPortClosure():
|
|
|
+ # When direction == OUT; the port is simply unused!
|
|
|
+ if dep.direction == Port.Direction.IN:
|
|
|
self.setDependency(dep.block, influencer, curIt)
|
|
|
return
|
|
|
|
|
|
@@ -308,6 +298,8 @@ def createDepGraph(model, curIteration, ignore_hierarchy=False):
|
|
|
|
|
|
for block in blocks:
|
|
|
depGraph.addMember(block)
|
|
|
+ # for port in model.getInputPorts() + model.getOutputPorts():
|
|
|
+ # depGraph.addMember(port)
|
|
|
|
|
|
def recSetInternalDependencies(blocks, curIteration):
|
|
|
"""
|
|
|
@@ -319,7 +311,7 @@ def createDepGraph(model, curIteration, ignore_hierarchy=False):
|
|
|
"""
|
|
|
for block in blocks:
|
|
|
for dep in block.getDependencies(curIteration):
|
|
|
- # if dep.block == block._parent:
|
|
|
+ # if dep.block == model:
|
|
|
# depGraph.setDependency(block, dep, curIteration)
|
|
|
# else:
|
|
|
depGraph.setDependency(block, dep.block, curIteration)
|
|
|
@@ -348,7 +340,11 @@ def gvDepGraph(model, curIt, ignore_hierarchy=False):
|
|
|
nodes = []
|
|
|
edges = []
|
|
|
for block in m2.getBlocks():
|
|
|
- nodes.append('{name} [label="{type}({name})"];'.format(name=block.getBlockName(), type=block.getBlockType()))
|
|
|
+ bname = block.getBlockName()
|
|
|
+ nodes.append('{namee} [label="{type}({name})"];'.format(name=bname, namee=bname.replace(".", "_"), type=block.getBlockType()))
|
|
|
for inf in depGraph.getInfluencers(block):
|
|
|
- edges.append("{} -> {};".format(block.getBlockName(), inf.getBlockName()))
|
|
|
+ if isinstance(inf, BaseBlock):
|
|
|
+ edges.append("{} -> {};".format(block.getBlockName().replace(".", "_"), inf.getBlockName().replace(".", "_")))
|
|
|
+ else:
|
|
|
+ edges.append("{} -> {};".format(block.getBlockName().replace(".", "_"), inf.name.replace(".", "_")))
|
|
|
return "digraph { // time = " + str(curIt) + "\n\t" + "\n\t".join(nodes + edges) + "\n}"
|