remainingActors.remove(actor);
}
clusteredActors.add(actor);
entityToFiringsPerIteration.put(actor, new Fraction(1));
pendingActors.addLast(actor);
while (!pendingActors.isEmpty()) {
Actor currentActor = (Actor) pendingActors.removeFirst();
Iterator actorPorts = ((ComponentEntity) currentActor)
.portList().iterator();
while (actorPorts.hasNext()) {
IOPort currentPort = (IOPort) actorPorts.next();
_propagatePort(container, currentPort,
entityToFiringsPerIteration, externalRates,
remainingActors, pendingActors, clusteredActors,
clusteredExternalPorts);
}
}
// Now we have _clusteredActors, which contains actors in
// one cluster (they are connected). Find the LCM of their
// denominator and normalize their firings. This means firings
// of actors are only normalized within their cluster.
int lcm = 1;
for (Iterator actors = clusteredActors.iterator(); actors.hasNext();) {
Actor currentActor = (Actor) actors.next();
Fraction fraction = (Fraction) entityToFiringsPerIteration
.get(currentActor);
int denominator = fraction.getDenominator();
lcm = Fraction.lcm(lcm, denominator);
}
// Got the normalizing factor.
Fraction lcmFraction = new Fraction(lcm);
for (Iterator actors = clusteredActors.iterator(); actors.hasNext();) {
Actor currentActor = (Actor) actors.next();
Fraction repetitions = ((Fraction) entityToFiringsPerIteration
.get(currentActor)).multiply(lcmFraction);
if (repetitions.getDenominator() != 1) {
throw new InternalErrorException(
"Failed to properly perform"
+ " fraction normalization.");
}
entityToFiringsPerIteration.put(currentActor, repetitions);
}
for (Iterator externalPorts = clusteredExternalPorts.iterator(); externalPorts
.hasNext();) {
IOPort port = (IOPort) externalPorts.next();
Fraction rate = ((Fraction) externalRates.get(port))
.multiply(lcmFraction);
if (rate.getDenominator() != 1) {
throw new InternalErrorException(
"Failed to properly perform"
+ " fraction normalization.");
}