Program: 76339
Project: 76339
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. FIXME: This method destroys the firing vector.  This is not nice.
 * @param UnscheduledActors The Actors that need to be scheduled.
 * @return A CircularList 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 CircularList _scheduleConnectedActors(CircularList actorList) throws NotSchedulableException {
  CircularList readyToScheduleActorList=new CircularList();
  CircularList newSchedule=new CircularList();
  LLMap waitingTokens=new LLMap();
  CircularList unscheduledActorList=new CircularList();
  unscheduledActorList.appendElements(actorList.elements());
  try {
    Enumeration schedulableEntities=actorList.elements();
    while (schedulableEntities.hasMoreElements()) {
      Actor a=(Actor)schedulableEntities.nextElement();
      Enumeration ainputports=a.inputPorts();
      while (ainputports.hasMoreElements()) {
        IOPort ainputport=(IOPort)ainputports.nextElement();
        int[] tokencount=new int[ainputport.getWidth()];
        for (int channel=0; channel < tokencount.length; channel++)         tokencount[channel]=0;
        waitingTokens.putAt(ainputport,tokencount);
      }
    }
    schedulableEntities=actorList.elements();
    while (schedulableEntities.hasMoreElements()) {
      Actor a=(Actor)schedulableEntities.nextElement();
      Enumeration aoutputports=a.outputPorts();
      while (aoutputports.hasMoreElements()) {
        IOPort aOutputPort=(IOPort)aoutputports.nextElement();
        int count=_getTokenInitProduction(aOutputPort);
        _debug("String_Node_Str" + count + "String_Node_Str"+ aOutputPort);
        if (count > 0) {
          _simulateTokensCreated(aOutputPort,count,actorList,readyToScheduleActorList,waitingTokens);
        }
      }
    }
    schedulableEntities=actorList.elements();
    while (schedulableEntities.hasMoreElements()) {
      Actor a=(Actor)schedulableEntities.nextElement();
      int inputCount=_countUnfulfilledInputs(a,actorList,waitingTokens);
      if (inputCount == 0)       readyToScheduleActorList.insertFirst((ComponentEntity)a);
      _debug("String_Node_Str" + ((ComponentEntity)a).getName() + "String_Node_Str"+ inputCount+ "String_Node_Str");
    }
    while (readyToScheduleActorList.size() > 0) {
      _debug("String_Node_Str");
      Enumeration ports=waitingTokens.keys();
      while (ports.hasMoreElements()) {
        IOPort port=(IOPort)ports.nextElement();
        _debug("String_Node_Str" + port.getFullName());
        int tokencount[]=(int[])waitingTokens.at(port);
        _debug("String_Node_Str" + tokencount.length);
        for (int channel=0; channel < tokencount.length; channel++)         _debug("String_Node_Str" + channel + "String_Node_Str"+ tokencount[channel]+ "String_Node_Str");
      }
      _debug("String_Node_Str");
      Enumeration actorsLeft=readyToScheduleActorList.elements();
      while (actorsLeft.hasMoreElements()) {
        Entity e=(Entity)actorsLeft.nextElement();
        _debug(e.getFullName());
      }
      ComponentEntity currentActor=(ComponentEntity)readyToScheduleActorList.at(0);
      readyToScheduleActorList.exclude(currentActor);
      _debug("String_Node_Str" + currentActor.getName());
      _simulateInputConsumption(currentActor,waitingTokens);
      newSchedule.insertLast(currentActor);
      Enumeration aOutputPorts=((Actor)currentActor).outputPorts();
      while (aOutputPorts.hasMoreElements()) {
        IOPort aOutputPort=(IOPort)aOutputPorts.nextElement();
        int count=_getTokenProductionRate(aOutputPort);
        _simulateTokensCreated(aOutputPort,count,actorList,readyToScheduleActorList,waitingTokens);
      }
      int firingsRemaining=_getFiringCount(currentActor);
      firingsRemaining-=1;
      _setFiringCount(currentActor,firingsRemaining);
      _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) {
          unscheduledActorList.exclude(currentActor);
        }
 else {
          int inputCount=_countUnfulfilledInputs((Actor)currentActor,unscheduledActorList,waitingTokens);
          if (inputCount < 1)           readyToScheduleActorList.insertLast(currentActor);
        }
      }
    }
  }
 catch (  IllegalActionException iae) {
    throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + iae.getMessage());
  }
 finally {
    _debug("String_Node_Str");
  }
  if (unscheduledActorList.size() > 0) {
    String s=new String("String_Node_Str");
    Enumeration actors=unscheduledActorList.elements();
    while (actors.hasMoreElements()) {
      Entity actor=(Entity)actors.nextElement();
      s+=actor.getFullName() + "String_Node_Str";
    }
    throw new NotSchedulableException(s);
  }
  Enumeration eschedule=newSchedule.elements();
  _debug("String_Node_Str");
  while (eschedule.hasMoreElements())   _debug(((ComponentEntity)eschedule.nextElement()).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();
      Enumeration ainputports=a.inputPorts();
      while (ainputports.hasMoreElements()) {
        IOPort ainputport=(IOPort)ainputports.nextElement();
        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();
      Enumeration aoutputports=a.outputPorts();
      while (aoutputports.hasMoreElements()) {
        IOPort aOutputPort=(IOPort)aoutputports.nextElement();
        int count=_getTokenInitProduction(aOutputPort);
        _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);
      _debug("String_Node_Str" + ((ComponentEntity)a).getName() + "String_Node_Str"+ inputCount+ "String_Node_Str");
    }
    while (readyToScheduleActorList.size() > 0) {
      _debug("String_Node_Str");
      Iterator ports=waitingTokens.keySet().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        _debug("String_Node_Str" + port.getFullName());
        int tokencount[]=(int[])waitingTokens.get(port);
        _debug("String_Node_Str" + tokencount.length);
        for (int channel=0; channel < tokencount.length; channel++)         _debug("String_Node_Str" + channel + "String_Node_Str"+ tokencount[channel]+ "String_Node_Str");
      }
      _debug("String_Node_Str");
      Iterator actorsLeft=readyToScheduleActorList.iterator();
      while (actorsLeft.hasNext()) {
        Entity e=(Entity)actorsLeft.next();
        _debug(e.getFullName());
      }
      ComponentEntity currentActor=(ComponentEntity)readyToScheduleActorList.getFirst();
      while (readyToScheduleActorList.remove(currentActor))       ;
      _debug("String_Node_Str" + currentActor.getName());
      _simulateInputConsumption(currentActor,waitingTokens);
      newSchedule.addLast(currentActor);
      Enumeration aOutputPorts=((Actor)currentActor).outputPorts();
      while (aOutputPorts.hasMoreElements()) {
        IOPort aOutputPort=(IOPort)aOutputPorts.nextElement();
        int count=_getTokenProductionRate(aOutputPort);
        _simulateTokensCreated(aOutputPort,count,actorList,readyToScheduleActorList,waitingTokens);
      }
      int firingsRemaining=((Integer)firingsRemainingVector.get(currentActor)).intValue();
      firingsRemaining-=1;
      firingsRemainingVector.put(currentActor,new Integer(firingsRemaining));
      _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) {
          while (unscheduledActorList.remove(currentActor))           ;
        }
 else {
          int inputCount=_countUnfulfilledInputs((Actor)currentActor,unscheduledActorList,waitingTokens);
          if (inputCount < 1)           readyToScheduleActorList.addLast(currentActor);
        }
      }
    }
  }
 catch (  IllegalActionException iae) {
    throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + iae.getMessage());
  }
 finally {
    _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();
  _debug("String_Node_Str");
  while (eschedule.hasNext())   _debug(((ComponentEntity)eschedule.next()).toString());
  return newSchedule;
}