Program: 75897
Project: 75897
Buggy source:
/** 
 * Create a schedule for a set of UnscheduledActors.  Given a valid firing vector, simulate the scheduling of the actors until the end of one synchronous dataflow iteration. Each actor will appear in the schedule exactly the number of times that minimally solves the balance equations and in an order where each actor has sufficient tokens on its inputs to fire.   Note that no claim is made that this is an optimal solution in any other sense.
 * @param UnscheduledActors The Actors that need to be scheduled.
 * @return A LinkedList of the Actors in the order they 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 LinkedList _scheduleConnectedActors(LinkedList actorList) throws NotSchedulableException {
  LinkedList readyToScheduleActorList=new LinkedList();
  LinkedList newSchedule=new LinkedList();
  Map waitingTokens=new TreeMap(new NamedObjComparator());
  Map firingsRemainingVector=new TreeMap(new NamedObjComparator());
  firingsRemainingVector.putAll(_firingvector);
  LinkedList unscheduledActorList=new LinkedList();
  unscheduledActorList.addAll(actorList);
  try {
    Iterator schedulableEntities=actorList.iterator();
    while (schedulableEntities.hasNext()) {
      Actor a=(Actor)schedulableEntities.next();
      Iterator ainputports=a.inputPortList().iterator();
      while (ainputports.hasNext()) {
        IOPort ainputport=(IOPort)ainputports.next();
        int[] tokencount=new int[ainputport.getWidth()];
        for (int channel=0; channel < tokencount.length; channel++)         tokencount[channel]=0;
        waitingTokens.put(ainputport,tokencount);
      }
    }
    schedulableEntities=actorList.iterator();
    while (schedulableEntities.hasNext()) {
      Actor a=(Actor)schedulableEntities.next();
      Iterator aoutputports=a.outputPortList().iterator();
      while (aoutputports.hasNext()) {
        IOPort aOutputPort=(IOPort)aoutputports.next();
        int count=getTokenInitProduction(aOutputPort);
        if (_debugging)         _debug("String_Node_Str" + count + "String_Node_Str"+ aOutputPort);
        if (count > 0) {
          _simulateTokensCreated(aOutputPort,count,actorList,readyToScheduleActorList,waitingTokens);
        }
      }
    }
    schedulableEntities=actorList.iterator();
    while (schedulableEntities.hasNext()) {
      Actor a=(Actor)schedulableEntities.next();
      int inputCount=_countUnfulfilledInputs(a,actorList,waitingTokens);
      if (inputCount == 0)       readyToScheduleActorList.addFirst((ComponentEntity)a);
      if (_debugging)       _debug("String_Node_Str" + ((ComponentEntity)a).getName() + "String_Node_Str"+ inputCount+ "String_Node_Str");
    }
    while (readyToScheduleActorList.size() > 0) {
      if (_debugging)       _debug("String_Node_Str");
      Iterator ports=waitingTokens.keySet().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        int tokencount[]=(int[])waitingTokens.get(port);
        if (_debugging) {
          _debug("String_Node_Str" + port.getFullName());
          _debug("String_Node_Str" + tokencount.length);
        }
        for (int channel=0; channel < tokencount.length; channel++)         if (_debugging)         _debug("String_Node_Str" + channel + "String_Node_Str"+ tokencount[channel]+ "String_Node_Str");
      }
      if (_debugging) {
        _debug("String_Node_Str");
        Iterator actorsLeft=readyToScheduleActorList.iterator();
        while (actorsLeft.hasNext()) {
          Entity e=(Entity)actorsLeft.next();
          _debug(e.getFullName());
        }
        _debug("String_Node_Str");
        actorsLeft=unscheduledActorList.iterator();
        while (actorsLeft.hasNext()) {
          Entity e=(Entity)actorsLeft.next();
          _debug(e.getFullName());
        }
      }
      ComponentEntity currentActor=(ComponentEntity)readyToScheduleActorList.getFirst();
      while (readyToScheduleActorList.remove(currentActor))       ;
      if (_debugging) {
        _debug("String_Node_Str" + currentActor.getName());
      }
      _simulateInputConsumption(currentActor,waitingTokens);
      newSchedule.addLast(currentActor);
      Iterator aOutputPorts=((Actor)currentActor).outputPortList().iterator();
      while (aOutputPorts.hasNext()) {
        IOPort aOutputPort=(IOPort)aOutputPorts.next();
        int count=getTokenProductionRate(aOutputPort);
        _simulateTokensCreated(aOutputPort,count,unscheduledActorList,readyToScheduleActorList,waitingTokens);
      }
      int firingsRemaining=((Integer)firingsRemainingVector.get(currentActor)).intValue();
      firingsRemaining-=1;
      firingsRemainingVector.put(currentActor,new Integer(firingsRemaining));
      if (_debugging) {
        _debug(currentActor.getName() + "String_Node_Str" + firingsRemaining+ "String_Node_Str");
      }
      if (firingsRemaining < 0)       throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
 else {
        if (firingsRemaining == 0) {
          _debug("String_Node_Str" + currentActor);
          while (readyToScheduleActorList.remove(currentActor))           ;
          while (unscheduledActorList.remove(currentActor))           ;
          _debug("String_Node_Str");
          Iterator actorsLeft=readyToScheduleActorList.iterator();
          while (actorsLeft.hasNext()) {
            Entity e=(Entity)actorsLeft.next();
            if (_debugging)             _debug(e.getFullName());
          }
        }
 else {
          int inputCount=_countUnfulfilledInputs((Actor)currentActor,unscheduledActorList,waitingTokens);
          if (inputCount < 1 && unscheduledActorList.contains(currentActor))           readyToScheduleActorList.addLast(currentActor);
        }
      }
    }
  }
 catch (  IllegalActionException iae) {
    throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + iae.getMessage());
  }
 finally {
    if (_debugging)     _debug("String_Node_Str");
  }
  if (unscheduledActorList.size() > 0) {
    String s=new String("String_Node_Str");
    Iterator actors=unscheduledActorList.iterator();
    while (actors.hasNext()) {
      Entity actor=(Entity)actors.next();
      s+=actor.getFullName() + "String_Node_Str";
    }
    throw new NotSchedulableException(s);
  }
  Iterator eschedule=newSchedule.iterator();
  if (_debugging) {
    _debug("String_Node_Str");
    while (eschedule.hasNext()) {
      _debug(((ComponentEntity)eschedule.next()).toString());
    }
  }
  return newSchedule;
}

Fixed version (ground truth):
/** 
 * Create a schedule for a set of UnscheduledActors.  Given a valid firing vector, simulate the scheduling of the actors until the end of one synchronous dataflow iteration. Each actor will appear in the schedule exactly the number of times that minimally solves the balance equations and in an order where each actor has sufficient tokens on its inputs to fire.   Note that no claim is made that this is an optimal solution in any other sense.
 * @param UnscheduledActors The Actors that need to be scheduled.
 * @return A LinkedList of the Actors in the order they 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 LinkedList _scheduleConnectedActors(LinkedList actorList) throws NotSchedulableException {
  LinkedList readyToScheduleActorList=new LinkedList();
  LinkedList newSchedule=new LinkedList();
  Map waitingTokens=new TreeMap(new NamedObjComparator());
  Map firingsRemainingVector=new TreeMap(new NamedObjComparator());
  firingsRemainingVector.putAll(_firingvector);
  LinkedList unscheduledActorList=new LinkedList();
  unscheduledActorList.addAll(actorList);
  try {
    Iterator schedulableEntities=actorList.iterator();
    while (schedulableEntities.hasNext()) {
      Actor a=(Actor)schedulableEntities.next();
      Iterator ainputports=a.inputPortList().iterator();
      while (ainputports.hasNext()) {
        IOPort ainputport=(IOPort)ainputports.next();
        int[] tokencount=new int[ainputport.getWidth()];
        for (int channel=0; channel < tokencount.length; channel++)         tokencount[channel]=0;
        waitingTokens.put(ainputport,tokencount);
      }
    }
    schedulableEntities=actorList.iterator();
    while (schedulableEntities.hasNext()) {
      Actor a=(Actor)schedulableEntities.next();
      Iterator aoutputports=a.outputPortList().iterator();
      while (aoutputports.hasNext()) {
        IOPort aOutputPort=(IOPort)aoutputports.next();
        int count=getTokenInitProduction(aOutputPort);
        if (_debugging)         _debug("String_Node_Str" + count + "String_Node_Str"+ aOutputPort);
        if (count > 0) {
          _simulateTokensCreated(aOutputPort,count,actorList,readyToScheduleActorList,waitingTokens);
        }
      }
    }
    StaticSchedulingDirector dir=(StaticSchedulingDirector)getContainer();
    CompositeActor ca=(CompositeActor)(dir.getContainer());
    Iterator inputPorts=ca.inputPortList().iterator();
    while (inputPorts.hasNext()) {
      IOPort port=(IOPort)inputPorts.next();
      _simulateExternalInputs(port,actorList,waitingTokens);
    }
    schedulableEntities=actorList.iterator();
    while (schedulableEntities.hasNext()) {
      Actor a=(Actor)schedulableEntities.next();
      int inputCount=_countUnfulfilledInputs(a,actorList,waitingTokens);
      if (inputCount == 0)       readyToScheduleActorList.addFirst((ComponentEntity)a);
      if (_debugging)       _debug("String_Node_Str" + ((ComponentEntity)a).getName() + "String_Node_Str"+ inputCount+ "String_Node_Str");
    }
    while (readyToScheduleActorList.size() > 0) {
      if (_debugging)       _debug("String_Node_Str");
      Iterator ports=waitingTokens.keySet().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        int tokencount[]=(int[])waitingTokens.get(port);
        if (_debugging) {
          _debug("String_Node_Str" + port.getFullName());
          _debug("String_Node_Str" + tokencount.length);
        }
        for (int channel=0; channel < tokencount.length; channel++)         if (_debugging)         _debug("String_Node_Str" + channel + "String_Node_Str"+ tokencount[channel]+ "String_Node_Str");
      }
      if (_debugging) {
        _debug("String_Node_Str");
        Iterator actorsLeft=readyToScheduleActorList.iterator();
        while (actorsLeft.hasNext()) {
          Entity e=(Entity)actorsLeft.next();
          _debug(e.getFullName());
        }
        _debug("String_Node_Str");
        actorsLeft=unscheduledActorList.iterator();
        while (actorsLeft.hasNext()) {
          Entity e=(Entity)actorsLeft.next();
          _debug(e.getFullName());
        }
      }
      ComponentEntity currentActor=(ComponentEntity)readyToScheduleActorList.getFirst();
      while (readyToScheduleActorList.remove(currentActor))       ;
      if (_debugging) {
        _debug("String_Node_Str" + currentActor.getName());
      }
      _simulateInputConsumption(currentActor,waitingTokens);
      newSchedule.addLast(currentActor);
      Iterator aOutputPorts=((Actor)currentActor).outputPortList().iterator();
      while (aOutputPorts.hasNext()) {
        IOPort aOutputPort=(IOPort)aOutputPorts.next();
        int count=getTokenProductionRate(aOutputPort);
        _simulateTokensCreated(aOutputPort,count,unscheduledActorList,readyToScheduleActorList,waitingTokens);
      }
      int firingsRemaining=((Integer)firingsRemainingVector.get(currentActor)).intValue();
      firingsRemaining-=1;
      firingsRemainingVector.put(currentActor,new Integer(firingsRemaining));
      if (_debugging) {
        _debug(currentActor.getName() + "String_Node_Str" + firingsRemaining+ "String_Node_Str");
      }
      if (firingsRemaining < 0)       throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
 else {
        if (firingsRemaining == 0) {
          _debug("String_Node_Str" + currentActor);
          while (readyToScheduleActorList.remove(currentActor))           ;
          while (unscheduledActorList.remove(currentActor))           ;
          _debug("String_Node_Str");
          Iterator actorsLeft=readyToScheduleActorList.iterator();
          while (actorsLeft.hasNext()) {
            Entity e=(Entity)actorsLeft.next();
            if (_debugging)             _debug(e.getFullName());
          }
        }
 else {
          int inputCount=_countUnfulfilledInputs((Actor)currentActor,unscheduledActorList,waitingTokens);
          if (inputCount < 1 && unscheduledActorList.contains(currentActor))           readyToScheduleActorList.addLast(currentActor);
        }
      }
    }
  }
 catch (  IllegalActionException iae) {
    throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + iae.getMessage());
  }
 finally {
    if (_debugging)     _debug("String_Node_Str");
  }
  if (unscheduledActorList.size() > 0) {
    String s=new String("String_Node_Str");
    Iterator actors=unscheduledActorList.iterator();
    while (actors.hasNext()) {
      Entity actor=(Entity)actors.next();
      s+=actor.getFullName() + "String_Node_Str";
    }
    throw new NotSchedulableException(s);
  }
  Iterator eschedule=newSchedule.iterator();
  if (_debugging) {
    _debug("String_Node_Str");
    while (eschedule.hasNext()) {
      _debug(((ComponentEntity)eschedule.next()).toString());
    }
  }
  return newSchedule;
}