Program: 75264
Project: 75264
Buggy source:
/** 
 * Propagate the number of fractional firings decided for this actor through the specified port.  Compute the fractional firing ratio for each actor that is connected to the given port. If we have not previously computed the ratio for an actor, then store the value in the given map of firing ratios and move the actor from the remainingActors list to the pendingActors list. If the value has been previously computed and is not the same, then the model is not schedulable and an exception will be thrown. Note that ports directly contained by the given container are handled slightly differently from other ports.  Most importantly, their rates are propagated to ports they are connected to on the inside, as opposed to ports they are connected to on the outside.
 * @param container The actor that is being scheduled.
 * @param currentPort The port that we are propagating from.
 * @param entityToFiringsPerIteration The current Map offractional firing ratios for each actor.  This map will be updated if the ratio for any actor has not been previously computed.
 * @param externalRates A map from external ports of container tothe fractional rates of that port.  This will be updated during this method.
 * @param remainingActors The set of actors that have not had theirfractional firing set.  This will be updated during this method.
 * @param pendingActors The set of actors that have had their rateset, but have not been propagated onwards.  This will be updated during this method.
 * @exception NotSchedulableException If the model is notschedulable.
 * @exception IllegalActionException If the expression for arate parameter is not valid.
 */
private void _propagatePort(CompositeActor container,IOPort currentPort,Map entityToFiringsPerIteration,Map externalRates,LinkedList remainingActors,LinkedList pendingActors) throws NotSchedulableException, IllegalActionException {
  ComponentEntity currentActor=(ComponentEntity)currentPort.getContainer();
  if (currentPort.isOutput() && currentPort.getContainer() != container) {
    Iterator connectedPorts=currentPort.deepConnectedPortList().iterator();
    while (connectedPorts.hasNext()) {
      IOPort connectedPort=(IOPort)connectedPorts.next();
      if (connectedPort.isOutput() && connectedPort.getContainer() != container) {
        throw new NotSchedulableException(currentPort,connectedPort,"String_Node_Str" + "String_Node_Str");
      }
 else       if (connectedPort.isInput() && connectedPort.getContainer() == container) {
        throw new NotSchedulableException(currentPort,connectedPort,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      }
    }
  }
  if (currentPort.isInput() && currentPort.getContainer() == container) {
    Iterator connectedPorts=currentPort.deepInsidePortList().iterator();
    while (connectedPorts.hasNext()) {
      IOPort connectedPort=(IOPort)connectedPorts.next();
      if (connectedPort.isOutput() && connectedPort.getContainer() != container) {
        throw new NotSchedulableException(currentPort,connectedPort,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      }
 else       if (connectedPort.isInput() && connectedPort.getContainer() == container) {
        throw new NotSchedulableException(currentPort,connectedPort,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      }
    }
  }
  int currentRate=SDFUtilities._getRate(currentPort);
  if (currentRate < 0) {
    throw new NotSchedulableException(currentPort,"String_Node_Str" + currentRate);
  }
  Iterator connectedPorts;
  if (currentPort.getContainer() == container) {
    connectedPorts=currentPort.deepInsidePortList().iterator();
    if (_debugging && VERBOSE) {
      _debug("String_Node_Str" + currentPort);
      while (connectedPorts.hasNext()) {
        _debug(connectedPorts.next().toString());
      }
    }
    connectedPorts=currentPort.deepInsidePortList().iterator();
  }
 else {
    connectedPorts=currentPort.deepConnectedPortList().iterator();
  }
  while (connectedPorts.hasNext()) {
    IOPort connectedPort=(IOPort)connectedPorts.next();
    ComponentEntity connectedActor=(ComponentEntity)connectedPort.getContainer();
    if (_debugging && VERBOSE) {
      _debug("String_Node_Str" + currentPort + "String_Node_Str"+ connectedActor.getName());
    }
    int connectedRate=SDFUtilities._getRate(connectedPort);
    Fraction currentFiring=(Fraction)entityToFiringsPerIteration.get(currentActor);
    Fraction desiredFiring;
    if ((currentRate == 0) && (connectedRate > 0)) {
      desiredFiring=Fraction.ZERO;
    }
 else     if ((currentRate > 0) && (connectedRate == 0)) {
      currentFiring=Fraction.ZERO;
      entityToFiringsPerIteration.put(currentActor,currentFiring);
      desiredFiring=new Fraction(1);
    }
 else     if ((currentRate == 0) && (connectedRate == 0)) {
      desiredFiring=currentFiring;
    }
 else {
      desiredFiring=currentFiring.multiply(new Fraction(currentRate,connectedRate));
    }
    Fraction presentFiring=(Fraction)entityToFiringsPerIteration.get(connectedActor);
    if (_debugging && VERBOSE) {
      _debug("String_Node_Str" + connectedActor + "String_Node_Str"+ presentFiring);
    }
    if (presentFiring == null) {
      entityToFiringsPerIteration.put(connectedActor,desiredFiring);
      Fraction rate=currentFiring.multiply(new Fraction(currentRate,1));
      Fraction previousRate=(Fraction)externalRates.get(connectedPort);
      if (previousRate.equals(Fraction.ZERO)) {
        externalRates.put(connectedPort,rate);
      }
 else       if (!rate.equals(previousRate)) {
        throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ connectedPort.getFullName());
      }
      _propagatePort(container,connectedPort,entityToFiringsPerIteration,externalRates,remainingActors,pendingActors);
      entityToFiringsPerIteration.remove(connectedActor);
    }
 else     if (presentFiring.equals(_minusOne)) {
      entityToFiringsPerIteration.put(connectedActor,desiredFiring);
      remainingActors.remove(connectedActor);
      pendingActors.addLast(connectedActor);
    }
 else     if (!presentFiring.equals(desiredFiring)) {
      throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ connectedPort.getFullName());
    }
    if (_debugging && VERBOSE) {
      _debug("String_Node_Str");
      _debug(entityToFiringsPerIteration.toString());
    }
  }
}

Fixed version (ground truth):
/** 
 * Propagate the number of fractional firings decided for this actor through the specified port.  Compute the fractional firing ratio for each actor that is connected to the given port. If we have not previously computed the ratio for an actor, then store the value in the given map of firing ratios and move the actor from the remainingActors list to the pendingActors list. If the value has been previously computed and is not the same, then the model is not schedulable and an exception will be thrown. Note that ports directly contained by the given container are handled slightly differently from other ports.  Most importantly, their rates are propagated to ports they are connected to on the inside, as opposed to ports they are connected to on the outside.
 * @param container The actor that is being scheduled.
 * @param currentPort The port that we are propagating from.
 * @param entityToFiringsPerIteration The current Map offractional firing ratios for each actor.  This map will be updated if the ratio for any actor has not been previously computed.
 * @param externalRates A map from external ports of container tothe fractional rates of that port.  This will be updated during this method.
 * @param remainingActors The set of actors that have not had theirfractional firing set.  This will be updated during this method.
 * @param pendingActors The set of actors that have had their rateset, but have not been propagated onwards.  This will be updated during this method.
 * @exception NotSchedulableException If the model is notschedulable.
 * @exception IllegalActionException If the expression for arate parameter is not valid.
 */
private void _propagatePort(CompositeActor container,IOPort currentPort,Map entityToFiringsPerIteration,Map externalRates,LinkedList remainingActors,LinkedList pendingActors) throws NotSchedulableException, IllegalActionException {
  ComponentEntity currentActor=(ComponentEntity)currentPort.getContainer();
  if (currentPort.isOutput() && currentPort.getContainer() != container) {
    Iterator connectedPorts=currentPort.deepConnectedPortList().iterator();
    while (connectedPorts.hasNext()) {
      IOPort connectedPort=(IOPort)connectedPorts.next();
      if (connectedPort.isOutput() && connectedPort.getContainer() != container) {
        throw new NotSchedulableException(currentPort,connectedPort,"String_Node_Str" + "String_Node_Str");
      }
 else       if (connectedPort.isInput() && connectedPort.getContainer() == container) {
        throw new NotSchedulableException(currentPort,connectedPort,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      }
    }
  }
  if (currentPort.isInput() && currentPort.getContainer() == container) {
    Iterator connectedPorts=currentPort.deepInsidePortList().iterator();
    while (connectedPorts.hasNext()) {
      IOPort connectedPort=(IOPort)connectedPorts.next();
      if (connectedPort.isOutput() && connectedPort.getContainer() != container) {
        throw new NotSchedulableException(currentPort,connectedPort,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      }
 else       if (connectedPort.isInput() && connectedPort.getContainer() == container) {
        throw new NotSchedulableException(currentPort,connectedPort,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      }
    }
  }
  Director director=(Director)getContainer();
  CompositeActor model=(CompositeActor)director.getContainer();
  int currentRate;
  if (currentActor == model) {
    currentRate=1;
  }
 else {
    currentRate=SDFUtilities._getRate(currentPort);
  }
  if (currentRate < 0) {
    throw new NotSchedulableException(currentPort,"String_Node_Str" + currentRate);
  }
  Iterator connectedPorts;
  if (currentPort.getContainer() == container) {
    connectedPorts=currentPort.deepInsidePortList().iterator();
    if (_debugging && VERBOSE) {
      _debug("String_Node_Str" + currentPort);
      while (connectedPorts.hasNext()) {
        _debug(connectedPorts.next().toString());
      }
    }
    connectedPorts=currentPort.deepInsidePortList().iterator();
  }
 else {
    connectedPorts=currentPort.deepConnectedPortList().iterator();
  }
  while (connectedPorts.hasNext()) {
    IOPort connectedPort=(IOPort)connectedPorts.next();
    ComponentEntity connectedActor=(ComponentEntity)connectedPort.getContainer();
    if (_debugging && VERBOSE) {
      _debug("String_Node_Str" + currentPort + "String_Node_Str"+ connectedActor.getName());
    }
    int connectedRate;
    if (connectedActor == model) {
      connectedRate=1;
    }
 else {
      connectedRate=SDFUtilities._getRate(connectedPort);
    }
    Fraction currentFiring=(Fraction)entityToFiringsPerIteration.get(currentActor);
    Fraction desiredFiring;
    if ((currentRate == 0) && (connectedRate > 0)) {
      desiredFiring=Fraction.ZERO;
    }
 else     if ((currentRate > 0) && (connectedRate == 0)) {
      currentFiring=Fraction.ZERO;
      entityToFiringsPerIteration.put(currentActor,currentFiring);
      desiredFiring=new Fraction(1);
    }
 else     if ((currentRate == 0) && (connectedRate == 0)) {
      desiredFiring=currentFiring;
    }
 else {
      desiredFiring=currentFiring.multiply(new Fraction(currentRate,connectedRate));
    }
    Fraction presentFiring=(Fraction)entityToFiringsPerIteration.get(connectedActor);
    if (_debugging && VERBOSE) {
      _debug("String_Node_Str" + connectedActor + "String_Node_Str"+ presentFiring);
    }
    if (presentFiring == null) {
      entityToFiringsPerIteration.put(connectedActor,desiredFiring);
      Fraction rate=currentFiring.multiply(new Fraction(currentRate,1));
      Fraction previousRate=(Fraction)externalRates.get(connectedPort);
      if (previousRate.equals(Fraction.ZERO)) {
        externalRates.put(connectedPort,rate);
      }
 else       if (!rate.equals(previousRate)) {
        throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ connectedPort.getFullName());
      }
      _propagatePort(container,connectedPort,entityToFiringsPerIteration,externalRates,remainingActors,pendingActors);
      entityToFiringsPerIteration.remove(connectedActor);
    }
 else     if (presentFiring.equals(_minusOne)) {
      entityToFiringsPerIteration.put(connectedActor,desiredFiring);
      remainingActors.remove(connectedActor);
      pendingActors.addLast(connectedActor);
    }
 else     if (!presentFiring.equals(desiredFiring)) {
      throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ connectedPort.getFullName());
    }
    if (_debugging && VERBOSE) {
      _debug("String_Node_Str");
      _debug(entityToFiringsPerIteration.toString());
    }
  }
}