Program: 75790
Project: 75790
Buggy source:
/** 
 * Return the CTSchedule. Caching of the schedule is done in the director class, so this method does not test for the validation of the schedule.
 */
protected Schedule _getSchedule() throws NotSchedulableException, IllegalActionException {
  CTSchedule ctSchedule=new CTSchedule();
  SignalTypes signalTypes=new SignalTypes();
  LinkedList sinkActors=new LinkedList();
  LinkedList dynamicActors=new LinkedList();
  LinkedList discreteActors=new LinkedList();
  LinkedList arithmeticActors=new LinkedList();
  LinkedList eventGenerators=new LinkedList();
  LinkedList waveformGenerators=new LinkedList();
  LinkedList continuousActors=new LinkedList();
  Schedule discreteActorSchedule=new Schedule();
  Schedule continuousActorSchedule=new Schedule();
  Schedule dynamicActorSchedule=new Schedule();
  Schedule eventGeneratorSchedule=new Schedule();
  Schedule outputSchedule=new Schedule();
  Schedule outputSSCActors=new Schedule();
  Schedule stateTransitionSchedule=new Schedule();
  Schedule statefulActors=new Schedule();
  Schedule stateSSCActors=new Schedule();
  Schedule waveformGeneratorSchedule=new Schedule();
  CompositeActor container=(CompositeActor)getContainer().getContainer();
  continuousActors=(LinkedList)((LinkedList)container.deepEntityList()).clone();
  Iterator allActors=container.deepEntityList().iterator();
  while (allActors.hasNext()) {
    Actor a=(Actor)allActors.next();
    if (a instanceof CTStatefulActor) {
      statefulActors.add(new Firing(a));
    }
    if (a instanceof CTWaveformGenerator) {
      waveformGenerators.add(a);
    }
    if (a instanceof CTEventGenerator) {
      eventGenerators.add(a);
    }
    if (a instanceof CTDynamicActor) {
      dynamicActors.addLast(a);
    }
 else     if (!(a instanceof CTWaveformGenerator)) {
      arithmeticActors.add(a);
    }
    if (a instanceof SequenceActor) {
      if (predecessorList(a).isEmpty()) {
        throw new NotSchedulableException(((Nameable)a).getName() + "String_Node_Str" + "String_Node_Str");
      }
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        signalTypes.setType(port,DISCRETE);
        if (port.isOutput()) {
          signalTypes.propagateType(port);
        }
      }
    }
 else     if ((a instanceof TypedCompositeActor) && !(a instanceof CTStepSizeControlActor)) {
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        signalTypes.setType(port,DISCRETE);
        if (port.isOutput()) {
          signalTypes.propagateType(port);
        }
      }
    }
 else {
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        Parameter signalType=(Parameter)port.getAttribute("String_Node_Str");
        if (signalType != null) {
          String type=((StringToken)signalType.getToken()).stringValue();
          type=type.trim().toUpperCase();
          if (type.equals("String_Node_Str")) {
            signalTypes.setType(port,CONTINUOUS);
            if (port.isOutput()) {
              signalTypes.propagateType(port);
            }
          }
 else           if (type.equals("String_Node_Str")) {
            signalTypes.setType(port,DISCRETE);
            if (port.isOutput()) {
              signalTypes.propagateType(port);
            }
          }
 else {
            throw new InvalidStateException(port,"String_Node_Str");
          }
        }
 else         if (a instanceof CTCompositeActor) {
          signalTypes.setType(port,CONTINUOUS);
          if (port.isOutput()) {
            signalTypes.propagateType(port);
          }
        }
      }
      if (predecessorList(a).isEmpty()) {
        ports=((Entity)a).portList().iterator();
        while (ports.hasNext()) {
          IOPort port=(IOPort)ports.next();
          if (signalTypes.getType(port).equals(UNKNOWN)) {
            signalTypes.setType(port,CONTINUOUS);
            if (port.isOutput()) {
              signalTypes.propagateType(port);
            }
          }
        }
      }
    }
  }
  DirectedAcyclicGraph arithmeticGraph=_toGraph(arithmeticActors);
  if (!arithmeticGraph.isAcyclic()) {
    throw new NotSchedulableException("String_Node_Str");
  }
  DirectedAcyclicGraph dynamicGraph=_toGraph(dynamicActors);
  if (!dynamicGraph.isAcyclic()) {
    throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
  }
  Object[] sortedArithmeticActors=arithmeticGraph.topologicalSort();
  for (int i=0; i < sortedArithmeticActors.length; i++) {
    Actor actor=(Actor)sortedArithmeticActors[i];
    Iterator inputPorts=actor.inputPortList().iterator();
    Integer knownType=UNKNOWN;
    boolean needManuallySetType=true;
    while (inputPorts.hasNext()) {
      IOPort port=(IOPort)inputPorts.next();
      if (port.getWidth() != 0) {
        Integer type=signalTypes.getType(port);
        if (type.equals(UNKNOWN)) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + port.getFullName());
        }
 else         if (knownType == UNKNOWN) {
          knownType=type;
          needManuallySetType=false;
        }
 else         if (!knownType.equals(type)) {
          needManuallySetType=true;
          break;
        }
      }
    }
    Iterator outputPorts=actor.outputPortList().iterator();
    while (outputPorts.hasNext()) {
      IOPort port=(IOPort)outputPorts.next();
      Integer type=signalTypes.getType(port);
      if (type.equals(UNKNOWN)) {
        if (needManuallySetType) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + port.getFullName());
        }
 else {
          signalTypes.setType(port,knownType);
        }
      }
      signalTypes.propagateType(port);
    }
  }
  discreteActors=signalTypes.getDiscreteActors();
  continuousActors=signalTypes.getContinuousActors();
  DirectedAcyclicGraph discreteGraph=_toGraph(discreteActors);
  Object[] discreteSorted=discreteGraph.topologicalSort();
  for (int i=0; i < discreteSorted.length; i++) {
    discreteActorSchedule.add(new Firing((Actor)discreteSorted[i]));
  }
  Iterator continuousIterator=continuousActors.iterator();
  while (continuousIterator.hasNext()) {
    Actor actor=(Actor)continuousIterator.next();
    if ((actor instanceof SequenceActor) || ((actor instanceof CompositeActor) && (!(actor instanceof CTStepSizeControlActor)))) {
      throw new NotSchedulableException((Nameable)actor,"String_Node_Str" + "String_Node_Str");
    }
    continuousActorSchedule.add(new Firing(actor));
    if (actor instanceof CTEventGenerator) {
      sinkActors.add(actor);
    }
 else {
      List successorList=successorList(actor);
      if (successorList.isEmpty()) {
        sinkActors.add(actor);
      }
 else {
        Iterator successors=successorList.iterator();
        boolean isSink=true;
        while (successors.hasNext()) {
          Actor successor=(Actor)successors.next();
          if (continuousActors.contains(successor)) {
            isSink=false;
            break;
          }
        }
        if (isSink) {
          sinkActors.add(actor);
        }
      }
    }
  }
  Iterator generators=waveformGenerators.iterator();
  while (generators.hasNext()) {
    Actor generator=(Actor)generators.next();
    waveformGeneratorSchedule.add(new Firing(generator));
  }
  if (!eventGenerators.isEmpty()) {
    DirectedAcyclicGraph eventGraph=_toGraph(eventGenerators);
    Object[] eventSorted=eventGraph.topologicalSort();
    for (int i=0; i < eventSorted.length; i++) {
      eventGeneratorSchedule.add(new Firing((Actor)eventSorted[i]));
    }
  }
  arithmeticGraph=_toArithmeticGraph(continuousActors);
  if (!dynamicActors.isEmpty()) {
    Object[] dynamicArray=dynamicActors.toArray();
    Object[] xSorted=dynamicGraph.topologicalSort(dynamicArray);
    for (int i=0; i < xSorted.length; i++) {
      Actor a=(Actor)xSorted[i];
      dynamicActorSchedule.add(0,new Firing(a));
      if (a instanceof CTStepSizeControlActor) {
        stateSSCActors.add(new Firing(a));
      }
    }
    Object[] fx=arithmeticGraph.backwardReachableNodes(dynamicArray);
    Object[] fxSorted=arithmeticGraph.topologicalSort(fx);
    for (int i=0; i < fxSorted.length; i++) {
      Actor a=(Actor)fxSorted[i];
      stateTransitionSchedule.add(new Firing(a));
      if (a instanceof CTStepSizeControlActor) {
        stateSSCActors.add(new Firing(a));
      }
    }
  }
  if (!sinkActors.isEmpty()) {
    Object[] sinkArray=sinkActors.toArray();
    Object[] gx=arithmeticGraph.backwardReachableNodes(sinkArray);
    Object[] gxSorted=arithmeticGraph.topologicalSort(gx);
    for (int i=0; i < gxSorted.length; i++) {
      Actor a=(Actor)gxSorted[i];
      outputSchedule.add(new Firing(a));
      if (a instanceof CTStepSizeControlActor) {
        outputSSCActors.add(new Firing(a));
      }
    }
    Iterator sinks=sinkActors.iterator();
    while (sinks.hasNext()) {
      Actor a=(Actor)sinks.next();
      outputSchedule.add(new Firing(a));
      if (a instanceof CTStepSizeControlActor) {
        outputSSCActors.add(new Firing(a));
      }
    }
  }
  ctSchedule.add(discreteActorSchedule);
  ctSchedule.add(continuousActorSchedule);
  ctSchedule.add(dynamicActorSchedule);
  ctSchedule.add(eventGeneratorSchedule);
  ctSchedule.add(outputSchedule);
  ctSchedule.add(outputSSCActors);
  ctSchedule.add(stateTransitionSchedule);
  ctSchedule.add(statefulActors);
  ctSchedule.add(stateSSCActors);
  ctSchedule.add(waveformGeneratorSchedule);
  setValid(true);
  return ctSchedule;
}

Fixed version (ground truth):
/** 
 * Return the CTSchedule. Caching of the schedule is done in the director class, so this method does not test for the validation of the schedule.
 */
protected Schedule _getSchedule() throws NotSchedulableException, IllegalActionException {
  CTSchedule ctSchedule=new CTSchedule();
  SignalTypes signalTypes=new SignalTypes();
  LinkedList sinkActors=new LinkedList();
  LinkedList dynamicActors=new LinkedList();
  LinkedList discreteActors=new LinkedList();
  LinkedList arithmeticActors=new LinkedList();
  LinkedList eventGenerators=new LinkedList();
  LinkedList waveformGenerators=new LinkedList();
  LinkedList continuousActors=new LinkedList();
  Schedule discreteActorSchedule=new Schedule();
  Schedule continuousActorSchedule=new Schedule();
  Schedule dynamicActorSchedule=new Schedule();
  Schedule eventGeneratorSchedule=new Schedule();
  Schedule outputSchedule=new Schedule();
  Schedule outputSSCActors=new Schedule();
  Schedule stateTransitionSchedule=new Schedule();
  Schedule statefulActors=new Schedule();
  Schedule stateSSCActors=new Schedule();
  Schedule waveformGeneratorSchedule=new Schedule();
  CompositeActor container=(CompositeActor)getContainer().getContainer();
  continuousActors=(LinkedList)((LinkedList)container.deepEntityList()).clone();
  Iterator allActors=container.deepEntityList().iterator();
  while (allActors.hasNext()) {
    Actor a=(Actor)allActors.next();
    System.out.println("String_Node_Str" + ((Nameable)a).getFullName());
    if (a instanceof CTStatefulActor) {
      statefulActors.add(new Firing(a));
    }
    if (a instanceof CTWaveformGenerator) {
      waveformGenerators.add(a);
    }
    if (a instanceof CTEventGenerator) {
      eventGenerators.add(a);
    }
    if (a instanceof CTDynamicActor) {
      dynamicActors.addLast(a);
    }
 else     if (!(a instanceof CTWaveformGenerator)) {
      arithmeticActors.add(a);
    }
    if (a instanceof SequenceActor) {
      if (predecessorList(a).isEmpty()) {
        throw new NotSchedulableException(((Nameable)a).getName() + "String_Node_Str" + "String_Node_Str");
      }
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        signalTypes.setType(port,DISCRETE);
        if (port.isOutput()) {
          signalTypes.propagateType(port);
        }
      }
    }
 else     if ((a instanceof TypedCompositeActor) && !(a instanceof CTStepSizeControlActor)) {
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        signalTypes.setType(port,DISCRETE);
        if (port.isOutput()) {
          signalTypes.propagateType(port);
        }
      }
    }
 else {
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        Parameter signalType=(Parameter)port.getAttribute("String_Node_Str");
        if (signalType != null) {
          String type=((StringToken)signalType.getToken()).stringValue();
          type=type.trim().toUpperCase();
          if (type.equals("String_Node_Str")) {
            signalTypes.setType(port,CONTINUOUS);
            if (port.isOutput()) {
              signalTypes.propagateType(port);
            }
          }
 else           if (type.equals("String_Node_Str")) {
            signalTypes.setType(port,DISCRETE);
            if (port.isOutput()) {
              signalTypes.propagateType(port);
            }
          }
 else {
            throw new InvalidStateException(port,"String_Node_Str");
          }
        }
 else         if (a instanceof CTCompositeActor) {
          signalTypes.setType(port,CONTINUOUS);
          if (port.isOutput()) {
            signalTypes.propagateType(port);
          }
        }
      }
      if (predecessorList(a).isEmpty()) {
        ports=((Entity)a).portList().iterator();
        while (ports.hasNext()) {
          IOPort port=(IOPort)ports.next();
          if (signalTypes.getType(port).equals(UNKNOWN)) {
            signalTypes.setType(port,CONTINUOUS);
            if (port.isOutput()) {
              signalTypes.propagateType(port);
            }
          }
        }
      }
    }
  }
  DirectedAcyclicGraph arithmeticGraph=_toGraph(arithmeticActors);
  if (!arithmeticGraph.isAcyclic()) {
    throw new NotSchedulableException("String_Node_Str");
  }
  DirectedAcyclicGraph dynamicGraph=_toGraph(dynamicActors);
  if (!dynamicGraph.isAcyclic()) {
    throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
  }
  Object[] sortedArithmeticActors=arithmeticGraph.topologicalSort();
  for (int i=0; i < sortedArithmeticActors.length; i++) {
    Actor actor=(Actor)sortedArithmeticActors[i];
    Iterator inputPorts=actor.inputPortList().iterator();
    Integer knownType=UNKNOWN;
    boolean needManuallySetType=true;
    while (inputPorts.hasNext()) {
      IOPort port=(IOPort)inputPorts.next();
      if (port.getWidth() != 0) {
        Integer type=signalTypes.getType(port);
        if (type.equals(UNKNOWN)) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + port.getFullName());
        }
 else         if (knownType == UNKNOWN) {
          knownType=type;
          needManuallySetType=false;
        }
 else         if (!knownType.equals(type)) {
          needManuallySetType=true;
          break;
        }
      }
    }
    Iterator outputPorts=actor.outputPortList().iterator();
    while (outputPorts.hasNext()) {
      IOPort port=(IOPort)outputPorts.next();
      Integer type=signalTypes.getType(port);
      if (type.equals(UNKNOWN)) {
        if (needManuallySetType) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + port.getFullName());
        }
 else {
          signalTypes.setType(port,knownType);
        }
      }
      signalTypes.propagateType(port);
    }
  }
  discreteActors=signalTypes.getDiscreteActors();
  continuousActors=signalTypes.getContinuousActors();
  DirectedAcyclicGraph discreteGraph=_toGraph(discreteActors);
  Object[] discreteSorted=discreteGraph.topologicalSort();
  for (int i=0; i < discreteSorted.length; i++) {
    discreteActorSchedule.add(new Firing((Actor)discreteSorted[i]));
  }
  Iterator continuousIterator=continuousActors.iterator();
  while (continuousIterator.hasNext()) {
    Actor actor=(Actor)continuousIterator.next();
    if ((actor instanceof SequenceActor) || ((actor instanceof CompositeActor) && (!(actor instanceof CTStepSizeControlActor)))) {
      throw new NotSchedulableException((Nameable)actor,"String_Node_Str" + "String_Node_Str");
    }
    continuousActorSchedule.add(new Firing(actor));
    if (actor instanceof CTEventGenerator) {
      sinkActors.add(actor);
    }
 else {
      List successorList=successorList(actor);
      if (successorList.isEmpty()) {
        sinkActors.add(actor);
      }
 else {
        Iterator successors=successorList.iterator();
        boolean isSink=true;
        while (successors.hasNext()) {
          Actor successor=(Actor)successors.next();
          if (continuousActors.contains(successor)) {
            isSink=false;
            break;
          }
        }
        if (isSink) {
          sinkActors.add(actor);
        }
      }
    }
  }
  Iterator generators=waveformGenerators.iterator();
  while (generators.hasNext()) {
    Actor generator=(Actor)generators.next();
    waveformGeneratorSchedule.add(new Firing(generator));
  }
  if (!eventGenerators.isEmpty()) {
    DirectedAcyclicGraph eventGraph=_toGraph(eventGenerators);
    Object[] eventSorted=eventGraph.topologicalSort();
    for (int i=0; i < eventSorted.length; i++) {
      eventGeneratorSchedule.add(new Firing((Actor)eventSorted[i]));
    }
  }
  arithmeticGraph=_toArithmeticGraph(continuousActors);
  if (!dynamicActors.isEmpty()) {
    Object[] dynamicArray=dynamicActors.toArray();
    Object[] xSorted=dynamicGraph.topologicalSort(dynamicArray);
    for (int i=0; i < xSorted.length; i++) {
      Actor a=(Actor)xSorted[i];
      dynamicActorSchedule.add(0,new Firing(a));
      if (a instanceof CTStepSizeControlActor) {
        stateSSCActors.add(new Firing(a));
      }
    }
    Object[] fx=arithmeticGraph.backwardReachableNodes(dynamicArray);
    Object[] fxSorted=arithmeticGraph.topologicalSort(fx);
    for (int i=0; i < fxSorted.length; i++) {
      Actor a=(Actor)fxSorted[i];
      stateTransitionSchedule.add(new Firing(a));
      if (a instanceof CTStepSizeControlActor) {
        stateSSCActors.add(new Firing(a));
      }
    }
  }
  if (!sinkActors.isEmpty()) {
    Object[] sinkArray=sinkActors.toArray();
    Object[] gx=arithmeticGraph.backwardReachableNodes(sinkArray);
    Object[] gxSorted=arithmeticGraph.topologicalSort(gx);
    for (int i=0; i < gxSorted.length; i++) {
      Actor a=(Actor)gxSorted[i];
      outputSchedule.add(new Firing(a));
      if (a instanceof CTStepSizeControlActor) {
        outputSSCActors.add(new Firing(a));
      }
    }
    Iterator sinks=sinkActors.iterator();
    while (sinks.hasNext()) {
      Actor a=(Actor)sinks.next();
      outputSchedule.add(new Firing(a));
      if (a instanceof CTStepSizeControlActor) {
        outputSSCActors.add(new Firing(a));
      }
    }
  }
  ctSchedule.add(discreteActorSchedule);
  ctSchedule.add(continuousActorSchedule);
  ctSchedule.add(dynamicActorSchedule);
  ctSchedule.add(eventGeneratorSchedule);
  ctSchedule.add(outputSchedule);
  ctSchedule.add(outputSSCActors);
  ctSchedule.add(stateTransitionSchedule);
  ctSchedule.add(statefulActors);
  ctSchedule.add(stateSSCActors);
  ctSchedule.add(waveformGeneratorSchedule);
  setValid(true);
  return ctSchedule;
}