Program: 74976
Project: 74976
Buggy source:
/** 
 * Return the CTSchedule. Caching of the schedule is done in the super class, so this method does not test for the validation of the schedule.
 */
protected Schedule _getSchedule() throws NotSchedulableException, IllegalActionException {
  HSSchedule ctSchedule=new HSSchedule();
  _signalTypeMap=new SignalTypeMap();
  LinkedList continuousActors=new LinkedList();
  LinkedList discreteActors=new LinkedList();
  LinkedList dynamicActors=new LinkedList();
  LinkedList arithmeticActors=new LinkedList();
  LinkedList eventGenerators=new LinkedList();
  LinkedList waveformGenerators=new LinkedList();
  LinkedList ctSubsystems=new LinkedList();
  LinkedList nonCTSubsystems=new LinkedList();
  Schedule continuousActorSchedule=new Schedule();
  Schedule discreteActorSchedule=new Schedule();
  Schedule dynamicActorSchedule=new Schedule();
  Schedule eventGeneratorSchedule=new Schedule();
  Schedule outputActorSchedule=new Schedule();
  Schedule outputSSCActorSchedule=new Schedule();
  Schedule statefulActorSchedule=new Schedule();
  Schedule stateSSCActorSchedule=new Schedule();
  CompositeActor container=(CompositeActor)getContainer().getContainer();
  boolean isCTCompositeActor=container instanceof CTCompositeActor;
  Iterator containerInPorts=container.inputPortList().iterator();
  while (containerInPorts.hasNext()) {
    IOPort inPort=(IOPort)containerInPorts.next();
    if (!isCTCompositeActor) {
      Receiver[][] localReceivers=inPort.getReceivers();
      Receiver localReceiver=localReceivers[0][0];
      if (localReceiver instanceof StateReceiver) {
        _signalTypeMap.setType(inPort,CONTINUOUS);
      }
 else {
        _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);
  }
  Iterator allActors=container.deepEntityList().iterator();
  while (allActors.hasNext()) {
    Actor a=(Actor)allActors.next();
    if (_debugging & _verbose) {
      _debug("String_Node_Str" + ((Nameable)a).getFullName() + "String_Node_Str");
    }
    if (a instanceof CompositeActor) {
      if (a instanceof CTCompositeActor) {
        dynamicActors.add(a);
        arithmeticActors.add(a);
        ctSubsystems.add(a);
        statefulActorSchedule.add(new Firing(a));
        waveformGenerators.add(a);
        eventGenerators.add(a);
      }
 else {
        nonCTSubsystems.add(a);
      }
    }
 else {
      if (a instanceof CTStatefulActor) {
        statefulActorSchedule.add(new Firing(a));
      }
      if (a instanceof CTWaveformGenerator) {
        waveformGenerators.add(a);
      }
 else       if (a instanceof CTEventGenerator) {
        eventGenerators.add(a);
      }
 else       if (a instanceof CTDynamicActor) {
        dynamicActors.add(a);
      }
 else {
        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 CompositeActor) && !(a instanceof CTCompositeActor)) {
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        if (port.isOutput()) {
          Receiver[][] insideReceivers=port.getInsideReceivers();
          Receiver insideReceiver=insideReceivers[0][0];
          if (insideReceiver instanceof StateReceiver) {
            _signalTypeMap.setType(port,CONTINUOUS);
          }
 else {
            _signalTypeMap.setType(port,DISCRETE);
          }
          _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) {
          if (_signalTypeMap.getType(port) == UNKNOWN) {
            _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 knownInputType=UNKNOWN;
    boolean needManuallySetType=true;
    while (inputPorts.hasNext()) {
      IOPort inputPort=(IOPort)inputPorts.next();
      if (inputPort.getWidth() != 0) {
        CTReceiver.SignalType inputType=_signalTypeMap.getType(inputPort);
        if (inputType == UNKNOWN) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + inputPort.getFullName() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
        }
 else         if (knownInputType == UNKNOWN) {
          knownInputType=inputType;
          needManuallySetType=false;
        }
 else         if (knownInputType != inputType) {
          needManuallySetType=true;
          break;
        }
      }
    }
    Iterator outputPorts=actor.outputPortList().iterator();
    while (outputPorts.hasNext()) {
      IOPort outputPort=(IOPort)outputPorts.next();
      if (outputPort.getWidth() != 0) {
        CTReceiver.SignalType outputType=_signalTypeMap.getType(outputPort);
        if (outputType == UNKNOWN) {
          if (needManuallySetType) {
            throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + outputPort.getFullName() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
          }
 else {
            _signalTypeMap.setType(outputPort,knownInputType);
          }
        }
        _signalTypeMap.propagateType(outputPort);
      }
    }
  }
  _setPortSignalTypes(_signalTypeMap);
  if (_debugging && _verbose) {
    _debug("String_Node_Str" + _signalTypeMap.toString() + "String_Node_Str");
  }
  discreteActors=_signalTypeMap.getDiscreteActors();
  discreteActors.removeAll(eventGenerators);
  discreteActors.addAll(eventGenerators);
  continuousActors=_signalTypeMap.getContinuousActors();
  continuousActors.removeAll(ctSubsystems);
  continuousActors.addAll(ctSubsystems);
  discreteActors.removeAll(ctSubsystems);
  discreteActors.addAll(ctSubsystems);
  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 (!eventGenerators.isEmpty()) {
    DirectedAcyclicGraph eventGraph=_toGraph(eventGenerators);
    Object[] eventSorted=eventGraph.topologicalSort();
    for (int i=0; i < eventSorted.length; i++) {
      Actor actor=(Actor)eventSorted[i];
      if (actor instanceof CTStepSizeControlActor) {
        outputSSCActorSchedule.add(new Firing(actor));
        eventGeneratorSchedule.add(new Firing(actor));
      }
    }
  }
  DirectedAcyclicGraph continuousGraph=_toArithmeticGraph(continuousActors);
  LinkedList sortedContinuousActors=new LinkedList();
  if (!dynamicActors.isEmpty()) {
    Object[] dynamicArray=dynamicActors.toArray();
    Object[] xSorted=dynamicGraph.topologicalSort(dynamicArray);
    for (int i=xSorted.length - 1; i >= 0; i--) {
      Actor dynamicActor=(Actor)xSorted[i];
      dynamicActorSchedule.add(new Firing(dynamicActor));
      stateSSCActorSchedule.add(new Firing(dynamicActor));
      sortedContinuousActors.add(dynamicActor);
    }
    for (int i=xSorted.length - 1; i >= 0; i--) {
      Actor dynamicActor=(Actor)xSorted[i];
      Object[] fx;
      fx=continuousGraph.backwardReachableNodes(dynamicActor);
      Object[] fxSorted=continuousGraph.topologicalSort(fx);
      for (int fxi=fxSorted.length - 1; fxi >= 0; fxi--) {
        Actor actor=(Actor)fxSorted[fxi];
        if (!sortedContinuousActors.contains(actor)) {
          sortedContinuousActors.add(0,actor);
        }
      }
    }
  }
  Iterator continuousSorted=sortedContinuousActors.iterator();
  while (continuousSorted.hasNext()) {
    Actor actor=(Actor)continuousSorted.next();
    continuousActorSchedule.add(new Firing(actor));
  }
  continuousActors.removeAll(sortedContinuousActors);
  continuousGraph=_toGraph(continuousActors);
  Object[] sinkActors=continuousGraph.topologicalSort();
  for (int i=0; i < sinkActors.length; i++) {
    Actor actor=(Actor)sinkActors[i];
    continuousActorSchedule.add(new Firing(actor));
    outputActorSchedule.add(new Firing(actor));
  }
  ctSchedule.add(continuousActorSchedule);
  ctSchedule.add(discreteActorSchedule);
  ctSchedule.add(dynamicActorSchedule);
  ctSchedule.add(eventGeneratorSchedule);
  ctSchedule.add(outputActorSchedule);
  ctSchedule.add(outputSSCActorSchedule);
  ctSchedule.add(statefulActorSchedule);
  ctSchedule.add(stateSSCActorSchedule);
  setValid(true);
  return ctSchedule;
}

Fixed version (ground truth):
/** 
 * Return the CTSchedule. Caching of the schedule is done in the super class, so this method does not test for the validation of the schedule.
 */
protected Schedule _getSchedule() throws NotSchedulableException, IllegalActionException {
  HSSchedule ctSchedule=new HSSchedule();
  _signalTypeMap=new SignalTypeMap();
  LinkedList continuousActors=new LinkedList();
  LinkedList discreteActors=new LinkedList();
  LinkedList dynamicActors=new LinkedList();
  LinkedList arithmeticActors=new LinkedList();
  LinkedList eventGenerators=new LinkedList();
  LinkedList waveformGenerators=new LinkedList();
  LinkedList ctSubsystems=new LinkedList();
  LinkedList nonCTSubsystems=new LinkedList();
  Schedule continuousActorSchedule=new Schedule();
  Schedule discreteActorSchedule=new Schedule();
  Schedule dynamicActorSchedule=new Schedule();
  Schedule eventGeneratorSchedule=new Schedule();
  Schedule outputActorSchedule=new Schedule();
  Schedule outputSSCActorSchedule=new Schedule();
  Schedule statefulActorSchedule=new Schedule();
  Schedule stateSSCActorSchedule=new Schedule();
  CompositeActor container=(CompositeActor)getContainer().getContainer();
  boolean isCTCompositeActor=container instanceof CTCompositeActor;
  Iterator containerInPorts=container.inputPortList().iterator();
  while (containerInPorts.hasNext()) {
    IOPort inPort=(IOPort)containerInPorts.next();
    if (!isCTCompositeActor) {
      Receiver[][] localReceivers=inPort.getReceivers();
      Receiver localReceiver=localReceivers[0][0];
      if (localReceiver instanceof StateReceiver) {
        _signalTypeMap.setType(inPort,CONTINUOUS);
      }
 else {
        _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);
  }
  Iterator allActors=container.deepEntityList().iterator();
  while (allActors.hasNext()) {
    Actor a=(Actor)allActors.next();
    if (_debugging & _verbose) {
      _debug("String_Node_Str" + ((Nameable)a).getFullName() + "String_Node_Str");
    }
    if (a instanceof CompositeActor) {
      if (a instanceof CTCompositeActor) {
        dynamicActors.add(a);
        arithmeticActors.add(a);
        ctSubsystems.add(a);
        statefulActorSchedule.add(new Firing(a));
        waveformGenerators.add(a);
        eventGenerators.add(a);
      }
 else {
        nonCTSubsystems.add(a);
      }
    }
 else {
      if (a instanceof CTStatefulActor) {
        statefulActorSchedule.add(new Firing(a));
      }
      if (a instanceof CTWaveformGenerator) {
        waveformGenerators.add(a);
      }
 else       if (a instanceof CTEventGenerator) {
        eventGenerators.add(a);
      }
 else       if (a instanceof CTDynamicActor) {
        dynamicActors.add(a);
      }
 else {
        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 CompositeActor) && !(a instanceof CTCompositeActor)) {
      Iterator ports=((Entity)a).portList().iterator();
      while (ports.hasNext()) {
        IOPort port=(IOPort)ports.next();
        if (port.isOutput()) {
          Receiver[][] insideReceivers=port.getInsideReceivers();
          Receiver insideReceiver=insideReceivers[0][0];
          if (insideReceiver instanceof StateReceiver) {
            _signalTypeMap.setType(port,CONTINUOUS);
          }
 else {
            _signalTypeMap.setType(port,DISCRETE);
          }
          _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) {
          if (_signalTypeMap.getType(port) == UNKNOWN) {
            _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 knownInputType=UNKNOWN;
    boolean needManuallySetType=true;
    while (inputPorts.hasNext()) {
      IOPort inputPort=(IOPort)inputPorts.next();
      if (inputPort.getWidth() != 0) {
        CTReceiver.SignalType inputType=_signalTypeMap.getType(inputPort);
        if (inputType == UNKNOWN) {
          throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + inputPort.getFullName() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
        }
 else         if (knownInputType == UNKNOWN) {
          knownInputType=inputType;
          needManuallySetType=false;
        }
 else         if (knownInputType != inputType) {
          needManuallySetType=true;
          break;
        }
      }
    }
    Iterator outputPorts=actor.outputPortList().iterator();
    while (outputPorts.hasNext()) {
      IOPort outputPort=(IOPort)outputPorts.next();
      if (outputPort.getWidth() != 0) {
        CTReceiver.SignalType outputType=_signalTypeMap.getType(outputPort);
        if (outputType == UNKNOWN) {
          if (needManuallySetType) {
            throw new NotSchedulableException("String_Node_Str" + "String_Node_Str" + outputPort.getFullName() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
          }
 else {
            _signalTypeMap.setType(outputPort,knownInputType);
          }
        }
        _signalTypeMap.propagateType(outputPort);
      }
    }
  }
  _setPortSignalTypes(_signalTypeMap);
  if (_debugging && _verbose) {
    _debug("String_Node_Str" + _signalTypeMap.toString() + "String_Node_Str");
  }
  discreteActors=_signalTypeMap.getDiscreteActors();
  discreteActors.removeAll(eventGenerators);
  discreteActors.addAll(eventGenerators);
  continuousActors=_signalTypeMap.getContinuousActors();
  continuousActors.removeAll(ctSubsystems);
  continuousActors.addAll(ctSubsystems);
  discreteActors.removeAll(ctSubsystems);
  discreteActors.addAll(ctSubsystems);
  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 (!eventGenerators.isEmpty()) {
    DirectedAcyclicGraph eventGraph=_toGraph(eventGenerators);
    Object[] eventSorted=eventGraph.topologicalSort();
    for (int i=0; i < eventSorted.length; i++) {
      Actor actor=(Actor)eventSorted[i];
      if (actor instanceof CTStepSizeControlActor) {
        outputSSCActorSchedule.add(new Firing(actor));
      }
      eventGeneratorSchedule.add(new Firing(actor));
    }
  }
  DirectedAcyclicGraph continuousGraph=_toArithmeticGraph(continuousActors);
  LinkedList sortedContinuousActors=new LinkedList();
  if (!dynamicActors.isEmpty()) {
    Object[] dynamicArray=dynamicActors.toArray();
    Object[] xSorted=dynamicGraph.topologicalSort(dynamicArray);
    for (int i=xSorted.length - 1; i >= 0; i--) {
      Actor dynamicActor=(Actor)xSorted[i];
      dynamicActorSchedule.add(new Firing(dynamicActor));
      stateSSCActorSchedule.add(new Firing(dynamicActor));
      sortedContinuousActors.add(dynamicActor);
    }
    for (int i=xSorted.length - 1; i >= 0; i--) {
      Actor dynamicActor=(Actor)xSorted[i];
      Object[] fx;
      fx=continuousGraph.backwardReachableNodes(dynamicActor);
      Object[] fxSorted=continuousGraph.topologicalSort(fx);
      for (int fxi=fxSorted.length - 1; fxi >= 0; fxi--) {
        Actor actor=(Actor)fxSorted[fxi];
        if (!sortedContinuousActors.contains(actor)) {
          sortedContinuousActors.add(0,actor);
        }
      }
    }
  }
  Iterator continuousSorted=sortedContinuousActors.iterator();
  while (continuousSorted.hasNext()) {
    Actor actor=(Actor)continuousSorted.next();
    continuousActorSchedule.add(new Firing(actor));
  }
  continuousActors.removeAll(sortedContinuousActors);
  continuousGraph=_toGraph(continuousActors);
  Object[] sinkActors=continuousGraph.topologicalSort();
  for (int i=0; i < sinkActors.length; i++) {
    Actor actor=(Actor)sinkActors[i];
    continuousActorSchedule.add(new Firing(actor));
    outputActorSchedule.add(new Firing(actor));
  }
  ctSchedule.add(continuousActorSchedule);
  ctSchedule.add(discreteActorSchedule);
  ctSchedule.add(dynamicActorSchedule);
  ctSchedule.add(eventGeneratorSchedule);
  ctSchedule.add(outputActorSchedule);
  ctSchedule.add(outputSSCActorSchedule);
  ctSchedule.add(statefulActorSchedule);
  ctSchedule.add(stateSSCActorSchedule);
  setValid(true);
  return ctSchedule;
}