Program: 73451
Project: 73451
Buggy source:
/** 
 * Calculate the delayOffset for each input port in the model, and annotate the ports with these offsets. This causality analysis usually happens at the preinitialize phase. <p> Start from each input port that is connected to the outside of the platform (These input ports indicate sensors and network interfaces, call them startPorts), and traverse the graph until we reach the output port connected to the outside of the platform (actuators/network ports). For each input port in between, annotate it with a delayOffset parameter. This parameter is an array of doubles, where each double corresponds to the minimum delay offset for a particular channel of that port. This minimum delay offset is used for the safe to process analysis. <p> Note: for all transparent composite actors, the delayOffsets are not calculated for their input ports. Instead, the offsets are calculated and annotated for input ports that are inside of these actors.
 * @exception IllegalActionException If failed to clear or calculate delayOffset,cannot check whether the current port is a network port, cannot get the network delay of the current port, cannot get the real time delay of the current port, cannot get remote receivers, or cannot get the port channel for a particular receiver.
 */
protected void _calculateDelayOffsets() throws IllegalActionException {
  _visitedActors=new HashSet<Actor>();
  _clearDelayOffsets();
  _inputModelTimeDelays=new HashMap<IOPort,Map<Integer,SuperdenseDependency>>();
  _portDelays=new HashMap<IOPort,SuperdenseDependency>();
  if (getContainer() instanceof TypedCompositeActor) {
    for (    Actor actor : (List<Actor>)(((TypedCompositeActor)getContainer()).deepEntityList())) {
      for (      TypedIOPort inputPort : (List<TypedIOPort>)(actor.inputPortList())) {
        _portDelays.put(inputPort,SuperdenseDependency.OPLUS_IDENTITY);
      }
      for (      TypedIOPort outputPort : (List<TypedIOPort>)(actor.outputPortList())) {
        _portDelays.put(outputPort,SuperdenseDependency.OPLUS_IDENTITY);
      }
    }
    for (    TypedIOPort inputPort : (List<TypedIOPort>)(((Actor)getContainer()).inputPortList())) {
      SuperdenseDependency startDelay;
      Double start=null;
      if (_isNetworkPort(inputPort)) {
        start=_getNetworkTotalDelay(inputPort);
        if (start != null) {
          start+=getAssumedSynchronizationErrorBound();
        }
 else {
          start=getAssumedSynchronizationErrorBound();
        }
      }
 else {
        start=_getRealTimeDelay(inputPort);
      }
      if (start == null) {
        start=0.0;
      }
      startDelay=SuperdenseDependency.valueOf(-start,0);
      _portDelays.put(inputPort,startDelay);
    }
    for (    TypedIOPort startPort : (List<TypedIOPort>)(((TypedCompositeActor)getContainer()).inputPortList())) {
      _traverseToCalcMinDelay(startPort);
    }
    for (    Actor actor : (List<Actor>)((CompositeActor)getContainer()).deepEntityList()) {
      if (!_visitedActors.contains(actor)) {
        for (        IOPort port : (List<IOPort>)actor.outputPortList()) {
          Receiver[][] remoteReceivers=port.getRemoteReceivers();
          for (int i=0; i < remoteReceivers.length; i++) {
            if (remoteReceivers[0] != null) {
              for (int j=0; j < remoteReceivers[i].length; j++) {
                Receiver receiver=remoteReceivers[i][j];
                IOPort receivePort=receiver.getContainer();
                int channel=receivePort.getChannelForReceiver(receiver);
                Map<Integer,SuperdenseDependency> channelDependency=(Map<Integer,SuperdenseDependency>)_inputModelTimeDelays.get(receivePort);
                if (channelDependency == null) {
                  channelDependency=new HashMap<Integer,SuperdenseDependency>();
                }
                channelDependency.put(Integer.valueOf(channel),SuperdenseDependency.OPLUS_IDENTITY);
                _inputModelTimeDelays.put(receivePort,channelDependency);
              }
            }
          }
        }
      }
    }
  }
  for (  IOPort inputPort : (Set<IOPort>)_inputModelTimeDelays.keySet()) {
    Map<Integer,SuperdenseDependency> channelDependency=(Map<Integer,SuperdenseDependency>)_inputModelTimeDelays.get(inputPort);
    double[] delayOffsets=new double[channelDependency.size()];
    for (    Integer portChannelMinDelay : channelDependency.keySet()) {
      delayOffsets[portChannelMinDelay.intValue()]=_calculateMinDelayForPortChannel(inputPort,portChannelMinDelay);
    }
    _setDelayOffset(inputPort,delayOffsets);
  }
}

Fixed version (ground truth):
/** 
 * Calculate the delayOffset for each input port in the model, and annotate the ports with these offsets. This causality analysis usually happens at the preinitialize phase. <p> Start from each input port that is connected to the outside of the platform (These input ports indicate sensors and network interfaces, call them startPorts), and traverse the graph until we reach the output port connected to the outside of the platform (actuators/network ports). For each input port in between, annotate it with a delayOffset parameter. This parameter is an array of doubles, where each double corresponds to the minimum delay offset for a particular channel of that port. This minimum delay offset is used for the safe to process analysis. <p> Note: for all transparent composite actors, the delayOffsets are not calculated for their input ports. Instead, the offsets are calculated and annotated for input ports that are inside of these actors.
 * @exception IllegalActionException If failed to clear or calculate delayOffset,cannot check whether the current port is a network port, cannot get the network delay of the current port, cannot get the real time delay of the current port, cannot get remote receivers, or cannot get the port channel for a particular receiver.
 */
protected void _calculateDelayOffsets() throws IllegalActionException {
  _visitedActors=new HashSet<Actor>();
  _clearDelayOffsets();
  _inputModelTimeDelays=new HashMap<IOPort,Map<Integer,SuperdenseDependency>>();
  _portDelays=new HashMap<IOPort,SuperdenseDependency>();
  if (getContainer() instanceof TypedCompositeActor) {
    for (    Actor actor : (List<Actor>)(((TypedCompositeActor)getContainer()).deepEntityList())) {
      for (      TypedIOPort inputPort : (List<TypedIOPort>)(actor.inputPortList())) {
        _portDelays.put(inputPort,SuperdenseDependency.OPLUS_IDENTITY);
      }
      for (      TypedIOPort outputPort : (List<TypedIOPort>)(actor.outputPortList())) {
        _portDelays.put(outputPort,SuperdenseDependency.OPLUS_IDENTITY);
      }
    }
    for (    TypedIOPort inputPort : (List<TypedIOPort>)(((Actor)getContainer()).inputPortList())) {
      SuperdenseDependency startDelay;
      Double start=null;
      if (_isNetworkPort(inputPort)) {
        start=_getNetworkTotalDelay(inputPort);
        if (start != null) {
          start+=getAssumedSynchronizationErrorBound();
        }
 else {
          start=getAssumedSynchronizationErrorBound();
        }
      }
 else {
        start=_getRealTimeDelay(inputPort);
      }
      if (start == null) {
        start=0.0;
      }
      startDelay=SuperdenseDependency.valueOf(-start,0);
      _portDelays.put(inputPort,startDelay);
    }
    for (    TypedIOPort startPort : (List<TypedIOPort>)(((TypedCompositeActor)getContainer()).inputPortList())) {
      _traverseToCalcMinDelay(startPort);
    }
    for (    Actor actor : (List<Actor>)((CompositeActor)getContainer()).deepEntityList()) {
      if (!_visitedActors.contains(actor)) {
        for (        IOPort port : (List<IOPort>)actor.outputPortList()) {
          Receiver[][] remoteReceivers=port.getRemoteReceivers();
          for (int i=0; i < remoteReceivers.length; i++) {
            if (remoteReceivers[0] != null) {
              for (int j=0; j < remoteReceivers[i].length; j++) {
                Receiver receiver=remoteReceivers[i][j];
                IOPort receivePort=receiver.getContainer();
                int channel=receivePort.getChannelForReceiver(receiver);
                Map<Integer,SuperdenseDependency> channelDependency=(Map<Integer,SuperdenseDependency>)_inputModelTimeDelays.get(receivePort);
                if (channelDependency == null) {
                  channelDependency=new HashMap<Integer,SuperdenseDependency>();
                }
                channelDependency.put(Integer.valueOf(channel),SuperdenseDependency.OPLUS_IDENTITY);
                _inputModelTimeDelays.put(receivePort,channelDependency);
              }
            }
          }
        }
      }
    }
  }
  for (  IOPort inputPort : (Set<IOPort>)_inputModelTimeDelays.keySet()) {
    Map<Integer,SuperdenseDependency> channelDependency=(Map<Integer,SuperdenseDependency>)_inputModelTimeDelays.get(inputPort);
    int size=1;
    for (    Integer portChannelMinDelay : channelDependency.keySet()) {
      if (portChannelMinDelay.intValue() >= size) {
        size=portChannelMinDelay.intValue() + 1;
      }
    }
    double[] delayOffsets=new double[size];
    for (    Integer portChannelMinDelay : channelDependency.keySet()) {
      delayOffsets[portChannelMinDelay.intValue()]=_calculateMinDelayForPortChannel(inputPort,portChannelMinDelay);
    }
    _setDelayOffset(inputPort,delayOffsets);
  }
}