Program: 73785
Project: 73785
Buggy source:
/** 
 * Create an optimal schedule for a set of actors.   FIXME: contains a lot of duplicated code from same method in SDFScheduler Would be good to factor out common code, but I do not want to touch SDFScheduler
 * @param externalRates Map from external port to an Integerrepresenting the number of tokens produced or consumed from that port during the course of an iteration.
 * @param actorList The actors that need to be scheduled.
 * @param container The container.
 * @return An instance of the Schedule class, indicating the orderin which actors should fire.
 * @exception NotSchedulableException If the algorithm encounters an SDFgraph that is not consistent with the firing vector, or detects an inconsistent internal state, or detects a graph that cannot be scheduled.
 */
private Schedule _scheduleConnectedActors(Map externalRates,List actorList,CompositeActor container) throws NotSchedulableException {
  LinkedList readyToScheduleActorList=new LinkedList();
  Schedule optimizedSchedule;
  Map firingsRemainingVector=new HashMap();
  firingsRemainingVector.putAll(_firingVector);
  LinkedList unscheduledActorList=new LinkedList();
  unscheduledActorList.addAll(actorList);
  try {
    Iterator actorsIterator=actorList.iterator();
    while (actorsIterator.hasNext()) {
      Actor actor=(Actor)actorsIterator.next();
      Iterator inputPorts=actor.inputPortList().iterator();
      while (inputPorts.hasNext()) {
        IOPort inputPort=(IOPort)inputPorts.next();
        Receiver[][] receivers=inputPort.getReceivers();
        if (receivers != null) {
          for (int m=0; m < receivers.length; m++) {
            for (int n=0; n < receivers[m].length; n++) {
              ((SDFReceiver)receivers[m][n])._waitingTokens=0;
            }
          }
        }
      }
    }
    Iterator externalOutputPorts=container.outputPortList().iterator();
    while (externalOutputPorts.hasNext()) {
      IOPort outputPort=(IOPort)externalOutputPorts.next();
      Receiver[][] receivers=outputPort.getInsideReceivers();
      if (receivers != null) {
        for (int m=0; m < receivers.length; m++) {
          for (int n=0; n < receivers[m].length; n++) {
            ((SDFReceiver)receivers[m][n])._waitingTokens=0;
          }
        }
      }
    }
    Iterator actors=actorList.iterator();
    while (actors.hasNext()) {
      Actor actor=(Actor)actors.next();
      Iterator outputPorts=actor.outputPortList().iterator();
      while (outputPorts.hasNext()) {
        IOPort outputPort=(IOPort)outputPorts.next();
        int count=DFUtilities.getTokenInitProduction(outputPort);
        if (count > 0) {
          _simulateTokensCreated(outputPort,count);
        }
      }
    }
    for (Iterator inputPorts=container.inputPortList().iterator(); inputPorts.hasNext(); ) {
      IOPort port=(IOPort)inputPorts.next();
      int count=((Integer)externalRates.get(port)).intValue();
      if (count > 0) {
        _simulateExternalInputs(port,count,actorList,readyToScheduleActorList);
      }
    }
    OptimalScheduleFinder finder=new OptimalScheduleFinder(this,optimizationCriterion);
    HashMap repVec=new HashMap();
    Iterator rvi=_firingVector.keySet().iterator();
    while (rvi.hasNext()) {
      Actor rva=(Actor)rvi.next();
      if (rva != container) {
        repVec.put(rva,_firingVector.get(rva));
      }
    }
    optimizedSchedule=finder.makeSchedule(repVec);
    Iterator si=optimizedSchedule.iterator();
    while (si.hasNext()) {
      Firing firing=(Firing)si.next();
      Actor firingActor=firing.getActor();
      _simulateInputConsumption(firingActor,1);
      for (Iterator outputPorts=firingActor.outputPortList().iterator(); outputPorts.hasNext(); ) {
        IOPort outputPort=(IOPort)outputPorts.next();
        int count=DFUtilities.getTokenProductionRate(outputPort);
        _simulateTokensCreated(outputPort,count);
      }
    }
  }
 catch (  IllegalActionException ex) {
    throw new InternalErrorException(this,ex,"String_Node_Str");
  }
  if (_debugging) {
    _debug("String_Node_Str");
    _debug(optimizedSchedule.toString());
  }
  return optimizedSchedule;
}

Fixed version (ground truth):
/** 
 * Create an optimal schedule for a set of actors.   FIXME: contains a lot of duplicated code from same method in SDFScheduler Would be good to factor out common code, but I do not want to touch SDFScheduler
 * @param externalRates Map from external port to an Integerrepresenting the number of tokens produced or consumed from that port during the course of an iteration.
 * @param actorList The actors that need to be scheduled.
 * @param container The container.
 * @return An instance of the Schedule class, indicating the orderin which actors should fire.
 * @exception NotSchedulableException If the algorithm encounters an SDFgraph that is not consistent with the firing vector, or detects an inconsistent internal state, or detects a graph that cannot be scheduled.
 */
private Schedule _scheduleConnectedActors(Map externalRates,List actorList,CompositeActor container) throws NotSchedulableException {
  LinkedList readyToScheduleActorList=new LinkedList();
  Schedule optimizedSchedule;
  Map firingsRemainingVector=new HashMap();
  firingsRemainingVector.putAll(_firingVector);
  LinkedList unscheduledActorList=new LinkedList();
  unscheduledActorList.addAll(actorList);
  try {
    Iterator actorsIterator=actorList.iterator();
    while (actorsIterator.hasNext()) {
      Actor actor=(Actor)actorsIterator.next();
      Iterator inputPorts=actor.inputPortList().iterator();
      while (inputPorts.hasNext()) {
        IOPort inputPort=(IOPort)inputPorts.next();
        Receiver[][] receivers=inputPort.getReceivers();
        if (receivers != null) {
          for (int m=0; m < receivers.length; m++) {
            for (int n=0; n < receivers[m].length; n++) {
              ((SDFReceiver)receivers[m][n])._waitingTokens=0;
            }
          }
        }
      }
    }
    Iterator externalOutputPorts=container.outputPortList().iterator();
    while (externalOutputPorts.hasNext()) {
      IOPort outputPort=(IOPort)externalOutputPorts.next();
      Receiver[][] receivers=outputPort.getInsideReceivers();
      if (receivers != null) {
        for (int m=0; m < receivers.length; m++) {
          for (int n=0; n < receivers[m].length; n++) {
            ((SDFReceiver)receivers[m][n])._waitingTokens=0;
          }
        }
      }
    }
    Iterator actors=actorList.iterator();
    while (actors.hasNext()) {
      Actor actor=(Actor)actors.next();
      Iterator outputPorts=actor.outputPortList().iterator();
      while (outputPorts.hasNext()) {
        IOPort outputPort=(IOPort)outputPorts.next();
        int count=DFUtilities.getTokenInitProduction(outputPort);
        if (count > 0) {
          _simulateTokensCreated(outputPort,count);
        }
      }
    }
    for (Iterator inputPorts=container.inputPortList().iterator(); inputPorts.hasNext(); ) {
      IOPort port=(IOPort)inputPorts.next();
      int count=((Integer)externalRates.get(port)).intValue();
      if (count > 0) {
        _simulateExternalInputs(port,count,actorList,readyToScheduleActorList);
      }
    }
    OptimalScheduleFinder finder=new OptimalScheduleFinder(this,optimizationCriterion);
    HashMap repVec=new HashMap();
    Iterator rvi=_firingVector.keySet().iterator();
    while (rvi.hasNext()) {
      Actor rva=(Actor)rvi.next();
      if (rva != container) {
        repVec.put(rva,_firingVector.get(rva));
      }
    }
    optimizedSchedule=finder.makeScheduleGreedy(repVec);
    Iterator si=optimizedSchedule.iterator();
    while (si.hasNext()) {
      Firing firing=(Firing)si.next();
      Actor firingActor=firing.getActor();
      _simulateInputConsumption(firingActor,1);
      for (Iterator outputPorts=firingActor.outputPortList().iterator(); outputPorts.hasNext(); ) {
        IOPort outputPort=(IOPort)outputPorts.next();
        int count=DFUtilities.getTokenProductionRate(outputPort);
        _simulateTokensCreated(outputPort,count);
      }
    }
  }
 catch (  IllegalActionException ex) {
    throw new InternalErrorException(this,ex,"String_Node_Str");
  }
  if (_debugging) {
    _debug("String_Node_Str");
    _debug(optimizedSchedule.toString());
  }
  return optimizedSchedule;
}