|
|
@@ -64,10 +64,18 @@ class DepGraph:
|
|
|
def __repr__(self):
|
|
|
repr = "Dependents: \n"
|
|
|
for dep in self.__dependents:
|
|
|
- repr += dep.getBlockName() + ":" + str(self.__dependents[dep]) + "\n"
|
|
|
+ if isinstance(dep, Port):
|
|
|
+ name = dep.name
|
|
|
+ else:
|
|
|
+ name = dep.getBlockName()
|
|
|
+ repr += name + ":" + str(self.__dependents[dep]) + "\n"
|
|
|
repr += "Influencers: \n"
|
|
|
for infl in self.__influencers:
|
|
|
- repr += infl.getBlockName() + ":" + str(self.__influencers[infl]) + "\n"
|
|
|
+ if isinstance(infl, Port):
|
|
|
+ name = infl.name
|
|
|
+ else:
|
|
|
+ name = infl.getBlockName()
|
|
|
+ repr += name + ":" + str(self.__influencers[infl]) + "\n"
|
|
|
return repr
|
|
|
|
|
|
def addMember(self, object):
|
|
|
@@ -292,33 +300,38 @@ def createDepGraph(model, curIteration, ignore_hierarchy=False):
|
|
|
Create a dependency graph of the CBD model.
|
|
|
Use the curIteration to differentiate between the first and other iterations
|
|
|
Watch out for dependencies with sub-models.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ model: The model for which the dependency graph must be computed.
|
|
|
+ curIteration: The current iteration for the dependency graph.
|
|
|
+ ignore_hierarchy: Assume the CBD model is flat and don't call this recursively.
|
|
|
"""
|
|
|
blocks = model.getBlocks()
|
|
|
depGraph = DepGraph(ignore_hierarchy)
|
|
|
|
|
|
for block in blocks:
|
|
|
depGraph.addMember(block)
|
|
|
- # for port in model.getInputPorts() + model.getOutputPorts():
|
|
|
- # depGraph.addMember(port)
|
|
|
+ for port in model.getInputPorts() + model.getOutputPorts():
|
|
|
+ depGraph.addMember(port)
|
|
|
|
|
|
def recSetInternalDependencies(blocks, curIteration):
|
|
|
"""
|
|
|
Recursive call for setting the internal dependencies of the graph.
|
|
|
|
|
|
Args:
|
|
|
- blocks (iter): The list of blocks to set as depencency
|
|
|
+ blocks (iter): The list of blocks to set as dependency
|
|
|
curIteration (int): The current iteration number
|
|
|
"""
|
|
|
for block in blocks:
|
|
|
for dep in block.getDependencies(curIteration):
|
|
|
- # if dep.block == model:
|
|
|
- # depGraph.setDependency(block, dep, curIteration)
|
|
|
- # else:
|
|
|
- depGraph.setDependency(block, dep.block, curIteration)
|
|
|
+ if dep.block == model:
|
|
|
+ depGraph.setDependency(block, dep, curIteration)
|
|
|
+ else:
|
|
|
+ depGraph.setDependency(block, dep.block, curIteration)
|
|
|
if isinstance(block, CBD) and not ignore_hierarchy:
|
|
|
recSetInternalDependencies(block.getBlocks(), curIteration)
|
|
|
|
|
|
- recSetInternalDependencies(blocks, curIteration)
|
|
|
+ recSetInternalDependencies(blocks + model.getOutputPorts(), curIteration)
|
|
|
|
|
|
return depGraph
|
|
|
|