// @param node The super node to expand.
// @param apgan The scheduler that was used to build the cluster hierarchy.
// @return The schedule saving the expansion result.
private SymbolicScheduleElement _expandAPGAN(PSDFGraph graph,
ptolemy.graph.Node node, PSDFAPGANStrategy strategy) {
PSDFGraph childGraph = (PSDFGraph) strategy.getClusterManager()
.getSubgraph(node);
try {
// Atomic node
if (childGraph == null) {
PSDFNodeWeight weight = (PSDFNodeWeight) node.getWeight();
SymbolicFiring firing = new SymbolicFiring((Actor) weight
.getComputation(), "1");
return firing;
// Super node
} else {
// FIXME: why call new Schedule here?
/*Schedule schedule = */new Schedule();
// Expand the super node with adjacent nodes contained
// within it.
Edge edge = (Edge) childGraph.edges().iterator().next();
ptolemy.graph.Node source = edge.source();
ptolemy.graph.Node sink = edge.sink();
SymbolicScheduleElement first = _expandAPGAN(childGraph,
source, strategy);
SymbolicScheduleElement second = _expandAPGAN(childGraph, sink,
strategy);
// Determine the iteration counts of the source and
// sink clusters.
String producedExpression = strategy.producedExpression(edge);
String consumedExpression = strategy.consumedExpression(edge);
// These errors should not occur.
if (producedExpression == null) {
throw new RuntimeException("Internal error: null "
+ "production rate expression. The offending edge "
+ "follows.\n" + edge);
} else if (consumedExpression == null) {
throw new RuntimeException(
"Internal error: null "
+ "consumption rate expression. The offending edge "
+ "follows.\n" + edge);
}
String denominator = PSDFGraphs.gcdExpression(
producedExpression, consumedExpression);
String firstIterations = "(" + consumedExpression + ") / ("
+ denominator + ")";
String secondIterations = "(" + producedExpression + ") / ("
+ denominator + ")";
first.setIterationCount(firstIterations);
second.setIterationCount(secondIterations);
SymbolicSchedule symbolicSchedule = new SymbolicSchedule("1");
symbolicSchedule.add((ScheduleElement) first);
symbolicSchedule.add((ScheduleElement) second);
// Compute buffer sizes and associate them with the
// corresponding relations.
Iterator edges = childGraph.edges().iterator();
while (edges.hasNext()) {
Edge nextEdge = (Edge) edges.next();
PSDFEdgeWeight weight = (PSDFEdgeWeight) nextEdge
.getWeight();