connectedRate = DFUtilities.getRate(connectedPort);
}
// currentFiring is the firing ratio that we've already
// calculated for currentActor
Fraction currentFiring = (Fraction) entityToFiringsPerIteration
.get(currentActor);
// Compute the firing ratio that we think connected actor
// should have, based on its connection to currentActor
Fraction desiredFiring;
// HDF actors might have zero rates...
if ((currentRate == 0) && (connectedRate > 0)) {
// The current port of the current actor has a rate
// of 0, and the current connected port of the
// connected actor has a positive integer rate.
// therefore, we must set the firing count of
// the connected actor to 0 so that it will
// not appear in the final static schedule.
desiredFiring = Fraction.ZERO;
} else if ((currentRate > 0) && (connectedRate == 0)) {
// The current port of the current actor has a
// positive integer rate, and the current
// connected port of the connected actor has
// rate of 0. therefore, we set the firing
// count of the current actor to 0 so that
// it will not appear in the final static schedule.
currentFiring = Fraction.ZERO;
// Update the entry in the firing table.
entityToFiringsPerIteration.put(currentActor, currentFiring);
// Set the firing count of the connected actor to
// be 1.
desiredFiring = new Fraction(1);
} else if ((currentRate == 0) && (connectedRate == 0)) {
// Give the connected actor the same rate as the
// current actor.
desiredFiring = currentFiring;
} else {
// Both the rates are non zero, so we can just do the
// regular actor propagation.
desiredFiring = currentFiring.multiply(new Fraction(
currentRate, connectedRate));
}
// Now, compare the firing ratio that was computed before
// with what we just determined.
// This should be either
// the firing that we computed previously, or null
// if the port is an external port, or _minusOne if
// we have not computed the firing ratio for this actor yet.
Fraction presentFiring = (Fraction) entityToFiringsPerIteration
.get(connectedActor);
if (_debugging && VERBOSE) {
_debug("presentFiring of connectedActor " + connectedActor
+ " = " + presentFiring);
}
// if (presentFiring == null) {
// Make sure to check for presentFiring == null here so that
// we avoid a NullPointerException if the model is ill formed.
// I had problems here with a bug in Publisher.clone() and
// Subscriber.clone() where presentFiring was null.
// Getting a NullPointerException is bad, we should check
// for null and try to give a better message.
if (connectedActor == model || presentFiring == null) {
// We've gotten out to an external port.
// Temporarily create the entry in the firing table.
// This is possibly rather fragile.
entityToFiringsPerIteration.put(connectedActor, desiredFiring);
// Compute the external rate for this port.
Fraction rate = currentFiring.multiply(new Fraction(
currentRate, 1));
Fraction previousRate = (Fraction) externalRates
.get(connectedPort);
if (previousRate == null) {
// This can happen if we somehow have a link to a port
// within a class definition.