Program: 75895
Project: 75895
Buggy source:
/** 
 * Sanity check the parameters; if the parameters are legal create a continuous-time subsystem that implement the model, preinitialize all the actors in the subsystem, and set the opaqueness of this actor to true. This method need the write access on the workspace.
 * @exception IllegalActionException If there is no CTDirector,or any contained actors throw it in its preinitialize() method.
 */
public void preinitialize() throws IllegalActionException {
  _checkParameters();
  DoubleMatrixToken a=(DoubleMatrixToken)A.getToken();
  int n=a.getRowCount();
  DoubleMatrixToken b=(DoubleMatrixToken)B.getToken();
  int m=b.getColumnCount();
  DoubleMatrixToken c=(DoubleMatrixToken)C.getToken();
  int r=c.getRowCount();
  DoubleMatrixToken d=(DoubleMatrixToken)D.getToken();
  DoubleMatrixToken x0=(DoubleMatrixToken)initialStates.getToken();
  try {
    _workspace.getWriteAccess();
    removeAllEntities();
    removeAllRelations();
    Integrator[] integrators=new Integrator[n];
    IORelation[] states=new IORelation[n];
    AddSubtract[] stateAdders=new AddSubtract[n];
    for (int i=0; i < n; i++) {
      integrators[i]=new Integrator(this,"String_Node_Str" + i);
      states[i]=new TypedIORelation(this,"String_Node_Str" + i);
      integrators[i].output.link(states[i]);
      stateAdders[i]=new AddSubtract(this,"String_Node_Str" + i);
      connect(stateAdders[i].output,integrators[i].input);
    }
    Scale[][] feedback=new Scale[n][n];
    for (int i=0; i < n; i++) {
      for (int j=0; j < n; j++) {
        Token tokenIJ=a.getElementAsToken(i,j);
        if (!(tokenIJ.isEqualTo(tokenIJ.zero())).booleanValue()) {
          feedback[i][j]=new Scale(this,"String_Node_Str" + i + "String_Node_Str"+ j);
          feedback[i][j].factor.setToken(tokenIJ);
          feedback[i][j].input.link(states[i]);
          connect(feedback[i][j].output,stateAdders[j].plus);
        }
      }
    }
    Scale[][] inputScales=new Scale[n][m];
    IORelation[] inputs=new IORelation[m];
    for (int j=0; j < m; j++) {
      inputs[j]=new TypedIORelation(this,"String_Node_Str" + j);
      input.link(inputs[j]);
      for (int i=0; i < n; i++) {
        inputScales[i][j]=new Scale(this,"String_Node_Str" + i + "String_Node_Str"+ j);
        inputScales[i][j].factor.setToken(b.getElementAsToken(i,j));
        inputScales[i][j].input.link(inputs[j]);
        connect(inputScales[i][j].output,stateAdders[i].plus);
      }
    }
    AddSubtract[] outputAdders=new AddSubtract[r];
    Scale[][] outputScales=new Scale[r][n];
    for (int l=0; l < r; l++) {
      outputAdders[l]=new AddSubtract(this,"String_Node_Str" + l);
      connect(outputAdders[l].output,output);
      for (int i=0; i < n; i++) {
        outputScales[l][i]=new Scale(this,"String_Node_Str" + l + "String_Node_Str"+ i);
        outputScales[l][i].factor.setToken(c.getElementAsToken(l,i));
        outputScales[l][i].input.link(states[i]);
        connect(outputScales[l][i].output,outputAdders[l].plus);
      }
    }
    Scale[][] feedThrough=new Scale[r][m];
    for (int l=0; l < r; l++) {
      for (int j=0; j < m; j++) {
        Token tokenLJ=d.getElementAsToken(l,j);
        if (!(tokenLJ.isEqualTo(tokenLJ.zero())).booleanValue()) {
          feedThrough[l][j]=new Scale(this,"String_Node_Str" + l + "String_Node_Str"+ j);
          feedThrough[l][j].factor.setToken(tokenLJ);
          feedThrough[l][j].input.link(inputs[j]);
          connect(feedThrough[l][j].output,outputAdders[l].plus);
        }
      }
    }
    _opaque=false;
    _workspace.incrVersion();
    System.out.println("String_Node_Str");
  }
 catch (  NameDuplicationException ex) {
    throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + ex.getMessage());
  }
 finally {
    _workspace.doneWriting();
  }
  for (Iterator i=deepEntityList().iterator(); i.hasNext(); ) {
    Actor actor=(Actor)i.next();
    actor.preinitialize();
  }
}

Fixed version (ground truth):
/** 
 * Sanity check the parameters; if the parameters are legal create a continuous-time subsystem that implement the model, preinitialize all the actors in the subsystem, and set the opaqueness of this actor to true. This method need the write access on the workspace.
 * @exception IllegalActionException If there is no CTDirector,or any contained actors throw it in its preinitialize() method.
 */
public void preinitialize() throws IllegalActionException {
  _checkParameters();
  DoubleMatrixToken a=(DoubleMatrixToken)A.getToken();
  int n=a.getRowCount();
  DoubleMatrixToken b=(DoubleMatrixToken)B.getToken();
  int m=b.getColumnCount();
  DoubleMatrixToken c=(DoubleMatrixToken)C.getToken();
  int r=c.getRowCount();
  DoubleMatrixToken d=(DoubleMatrixToken)D.getToken();
  DoubleMatrixToken x0=(DoubleMatrixToken)initialStates.getToken();
  try {
    _workspace.getWriteAccess();
    removeAllEntities();
    removeAllRelations();
    Integrator[] integrators=new Integrator[n];
    IORelation[] states=new IORelation[n];
    AddSubtract[] stateAdders=new AddSubtract[n];
    for (int i=0; i < n; i++) {
      integrators[i]=new Integrator(this,"String_Node_Str" + i);
      states[i]=new TypedIORelation(this,"String_Node_Str" + i);
      integrators[i].output.link(states[i]);
      stateAdders[i]=new AddSubtract(this,"String_Node_Str" + i);
      connect(stateAdders[i].output,integrators[i].input);
    }
    Scale[][] feedback=new Scale[n][n];
    for (int i=0; i < n; i++) {
      for (int j=0; j < n; j++) {
        Token tokenIJ=a.getElementAsToken(i,j);
        if (!(tokenIJ.isEqualTo(tokenIJ.zero())).booleanValue()) {
          feedback[i][j]=new Scale(this,"String_Node_Str" + i + "String_Node_Str"+ j);
          feedback[i][j].factor.setToken(tokenIJ);
          feedback[i][j].input.link(states[j]);
          connect(feedback[i][j].output,stateAdders[i].plus);
        }
      }
    }
    Scale[][] inputScales=new Scale[n][m];
    IORelation[] inputs=new IORelation[m];
    for (int j=0; j < m; j++) {
      inputs[j]=new TypedIORelation(this,"String_Node_Str" + j);
      input.link(inputs[j]);
      for (int i=0; i < n; i++) {
        inputScales[i][j]=new Scale(this,"String_Node_Str" + i + "String_Node_Str"+ j);
        inputScales[i][j].factor.setToken(b.getElementAsToken(i,j));
        inputScales[i][j].input.link(inputs[j]);
        connect(inputScales[i][j].output,stateAdders[i].plus);
      }
    }
    AddSubtract[] outputAdders=new AddSubtract[r];
    Scale[][] outputScales=new Scale[r][n];
    for (int l=0; l < r; l++) {
      outputAdders[l]=new AddSubtract(this,"String_Node_Str" + l);
      connect(outputAdders[l].output,output);
      for (int i=0; i < n; i++) {
        Token tokenLI=c.getElementAsToken(l,i);
        if (!(tokenLI.isEqualTo(tokenLI.zero())).booleanValue()) {
          outputScales[l][i]=new Scale(this,"String_Node_Str" + l + "String_Node_Str"+ i);
          outputScales[l][i].factor.setToken(tokenLI);
          outputScales[l][i].input.link(states[i]);
          connect(outputScales[l][i].output,outputAdders[l].plus);
        }
      }
    }
    Scale[][] feedThrough=new Scale[r][m];
    for (int l=0; l < r; l++) {
      for (int j=0; j < m; j++) {
        Token tokenLJ=d.getElementAsToken(l,j);
        if (!(tokenLJ.isEqualTo(tokenLJ.zero())).booleanValue()) {
          feedThrough[l][j]=new Scale(this,"String_Node_Str" + l + "String_Node_Str"+ j);
          feedThrough[l][j].factor.setToken(tokenLJ);
          feedThrough[l][j].input.link(inputs[j]);
          connect(feedThrough[l][j].output,outputAdders[l].plus);
        }
      }
    }
    _opaque=false;
    _workspace.incrVersion();
    System.out.println("String_Node_Str");
  }
 catch (  NameDuplicationException ex) {
    throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + ex.getMessage());
  }
 finally {
    _workspace.doneWriting();
  }
  for (Iterator i=deepEntityList().iterator(); i.hasNext(); ) {
    Actor actor=(Actor)i.next();
    actor.preinitialize();
  }
}