Program: 75465
Project: 75465
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();
  _signalTypeMap=new SignalTypeMap();
  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();
  boolean isCTComposite=false;
  if (container instanceof CTStepSizeControlActor) {
    isCTComposite=true;
  }
  Iterator containerInPorts=container.inputPortList().iterator();
  while (containerInPorts.hasNext()) {
    IOPort inPort=(IOPort)containerInPorts.next();
    if (!isCTComposite) {
      _signalTypeMap.setType(inPort,DISCRETE);
    }
 else {
      Parameter signalType=(Parameter)inPort.getAttribute("String_Node_Str");
      if (signalType != null) {
        String type=((StringToken)signalType.getToken()).stringValue();
        type=type.trim().toUpperCase();
        if (type.equals("String_Node_Str")) {
          _signalTypeMap.setType(inPort,CONTINUOUS);
        }
 else         if (type.equals("String_Node_Str")) {
          _signalTypeMap.setType(inPort,DISCRETE);
        }
 else {
          throw new IllegalActionException(inPort,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
        }
      }
 else {
        _signalTypeMap.setType(inPort,CONTINUOUS);
      }
    }
    _signalTypeMap.propagateTypeInside(inPort);
  }
  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();
        _signalTypeMap.setType(port,DISCRETE);
        if (port.isOutput()) {
          _signalTypeMap.propagateType(port);
        }
      }
    }
 else     if ((a instanceof TypedCompositeActor) && !(a instanceof CTStepSizeControlActor)) {
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        _signalTypeMap.setType(port,DISCRETE);
        if (port.isOutput()) {
          _signalTypeMap.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")) {
            _signalTypeMap.setType(port,CONTINUOUS);
            if (port.isOutput()) {
              _signalTypeMap.propagateType(port);
            }
          }
 else           if (type.equals("String_Node_Str")) {
            _signalTypeMap.setType(port,DISCRETE);
            if (port.isOutput()) {
              _signalTypeMap.propagateType(port);
            }
          }
 else {
            throw new InvalidStateException(port,"String_Node_Str");
          }
        }
 else         if (a instanceof CTCompositeActor) {
          _signalTypeMap.setType(port,CONTINUOUS);
          if (port.isOutput()) {
            _signalTypeMap.propagateType(port);
          }
        }
      }
      if (predecessorList(a).isEmpty()) {
        ports=((Entity)a).portList().iterator();
        while (ports.hasNext()) {
          IOPort port=(IOPort)ports.next();
          if (_signalTypeMap.getType(port) == UNKNOWN) {
            _signalTypeMap.setType(port,CONTINUOUS);
            if (port.isOutput()) {
              _signalTypeMap.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();
    CTReceiver.SignalType knownType=UNKNOWN;
    boolean needManuallySetType=true;
    while (inputPorts.hasNext()) {
      IOPort port=(IOPort)inputPorts.next();
      if (port.getWidth() != 0) {
        CTReceiver.SignalType type=_signalTypeMap.getType(port);
        if (type == UNKNOWN) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + port.getFullName() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
        }
 else         if (knownType == UNKNOWN) {
          knownType=type;
          needManuallySetType=false;
        }
 else         if (knownType != type) {
          needManuallySetType=true;
          break;
        }
      }
    }
    Iterator outputPorts=actor.outputPortList().iterator();
    while (outputPorts.hasNext()) {
      IOPort port=(IOPort)outputPorts.next();
      CTReceiver.SignalType type=_signalTypeMap.getType(port);
      if (type == UNKNOWN) {
        if (needManuallySetType) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + port.getFullName() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
        }
 else {
          _signalTypeMap.setType(port,knownType);
        }
      }
      _signalTypeMap.propagateType(port);
    }
  }
  _setPortSignalTypes(_signalTypeMap);
  if (_debugging)   _debug("String_Node_Str" + _signalTypeMap.toString() + "String_Node_Str");
  discreteActors=_signalTypeMap.getDiscreteActors();
  continuousActors=_signalTypeMap.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     if (!(actor instanceof CTDynamicActor)) {
      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();
  _signalTypeMap=new SignalTypeMap();
  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();
  boolean isCTComposite=false;
  if (container instanceof CTStepSizeControlActor) {
    isCTComposite=true;
  }
  Iterator containerInPorts=container.inputPortList().iterator();
  while (containerInPorts.hasNext()) {
    IOPort inPort=(IOPort)containerInPorts.next();
    if (!isCTComposite) {
      _signalTypeMap.setType(inPort,DISCRETE);
    }
 else {
      Parameter signalType=(Parameter)inPort.getAttribute("String_Node_Str");
      if (signalType != null) {
        String type=((StringToken)signalType.getToken()).stringValue();
        type=type.trim().toUpperCase();
        if (type.equals("String_Node_Str")) {
          _signalTypeMap.setType(inPort,CONTINUOUS);
        }
 else         if (type.equals("String_Node_Str")) {
          _signalTypeMap.setType(inPort,DISCRETE);
        }
 else {
          throw new IllegalActionException(inPort,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
        }
      }
 else {
        _signalTypeMap.setType(inPort,CONTINUOUS);
      }
    }
    _signalTypeMap.propagateTypeInside(inPort);
  }
  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();
        _signalTypeMap.setType(port,DISCRETE);
        if (port.isOutput()) {
          _signalTypeMap.propagateType(port);
        }
      }
    }
 else     if ((a instanceof TypedCompositeActor) && !(a instanceof CTStepSizeControlActor)) {
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        _signalTypeMap.setType(port,DISCRETE);
        if (port.isOutput()) {
          _signalTypeMap.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")) {
            _signalTypeMap.setType(port,CONTINUOUS);
            if (port.isOutput()) {
              _signalTypeMap.propagateType(port);
            }
          }
 else           if (type.equals("String_Node_Str")) {
            _signalTypeMap.setType(port,DISCRETE);
            if (port.isOutput()) {
              _signalTypeMap.propagateType(port);
            }
          }
 else {
            throw new InvalidStateException(port,"String_Node_Str");
          }
        }
 else         if (a instanceof CTCompositeActor) {
          _signalTypeMap.setType(port,CONTINUOUS);
          if (port.isOutput()) {
            _signalTypeMap.propagateType(port);
          }
        }
      }
      if (predecessorList(a).isEmpty()) {
        ports=((Entity)a).portList().iterator();
        while (ports.hasNext()) {
          IOPort port=(IOPort)ports.next();
          if (_signalTypeMap.getType(port) == UNKNOWN) {
            _signalTypeMap.setType(port,CONTINUOUS);
            if (port.isOutput()) {
              _signalTypeMap.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();
    CTReceiver.SignalType knownType=UNKNOWN;
    boolean needManuallySetType=true;
    while (inputPorts.hasNext()) {
      IOPort port=(IOPort)inputPorts.next();
      if (port.getWidth() != 0) {
        CTReceiver.SignalType type=_signalTypeMap.getType(port);
        if (type == UNKNOWN) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + port.getFullName() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
        }
 else         if (knownType == UNKNOWN) {
          knownType=type;
          needManuallySetType=false;
        }
 else         if (knownType != type) {
          needManuallySetType=true;
          break;
        }
      }
    }
    Iterator outputPorts=actor.outputPortList().iterator();
    while (outputPorts.hasNext()) {
      IOPort port=(IOPort)outputPorts.next();
      CTReceiver.SignalType type=_signalTypeMap.getType(port);
      if (type == UNKNOWN) {
        if (needManuallySetType) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + port.getFullName() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
        }
 else {
          _signalTypeMap.setType(port,knownType);
        }
      }
      _signalTypeMap.propagateType(port);
    }
  }
  _setPortSignalTypes(_signalTypeMap);
  if (_debugging)   _debug("String_Node_Str" + _signalTypeMap.toString() + "String_Node_Str");
  discreteActors=_signalTypeMap.getDiscreteActors();
  continuousActors=_signalTypeMap.getContinuousActors();
  DirectedAcyclicGraph discreteGraph=_toGraph(discreteActors);
  Object[] discreteSorted=discreteGraph.topologicalSort();
  for (int i=0; i < discreteSorted.length; i++) {
    Actor actor=(Actor)discreteSorted[i];
    discreteActorSchedule.add(new Firing(actor));
    if ((actor instanceof CompositeActor) && (actor instanceof CTStepSizeControlActor)) {
      if (!continuousActors.contains(actor)) {
        continuousActors.add(actor);
      }
    }
  }
  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     if (!(actor instanceof CTDynamicActor)) {
      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;
}