Program: 11697
Project: 11697
Buggy source:
/** 
 * Optimize a   {@link Collection} of connected {@link SpringMesh SpringMeshes}.
 * @param maxError do not accept convergence if error is > max_error
 * @param maxIterations stop after that many iterations even if there wasno minimum found
 * @param maxPlateauwidth convergence is reached if the average slope inan interval of this size is 0.0 (in double accuracy).  This prevents the algorithm from stopping at plateaus smaller than this value.
 */
public static void optimizeMeshes(final Collection<SpringMesh> meshes,final float maxError,final int maxIterations,final int maxPlateauwidth,final boolean visualize) throws NotEnoughDataPointsException {
  final ErrorStatistic observer=new ErrorStatistic(maxPlateauwidth + 1);
  final ErrorStatistic singleMeshObserver=new ErrorStatistic(maxPlateauwidth + 1);
  int i=0;
  double force=0;
  double maxForce=0;
  double minForce=0;
  boolean proceed=i < maxIterations;
  final ImageStack stackAnimation=new ImageStack(VIS_SIZE,VIS_SIZE);
  final ImagePlus impAnimation=new ImagePlus();
  println("String_Node_Str");
  while (proceed) {
    force=0;
    maxForce=-Double.MAX_VALUE;
    minForce=Double.MAX_VALUE;
    if (visualize) {
      stackAnimation.addSlice("String_Node_Str" + i,paintSprings(meshes,VIS_SIZE,VIS_SIZE,maxError));
      impAnimation.setStack(stackAnimation);
      impAnimation.updateAndDraw();
      if (i == 1) {
        impAnimation.show();
      }
    }
    for (    final SpringMesh mesh : meshes) {
      mesh.optimizeStep(singleMeshObserver);
      force+=mesh.getForce();
      final double meshMaxForce=mesh.maxForce;
      final double meshMinForce=mesh.minForce;
      if (meshMaxForce > maxForce)       maxForce=meshMaxForce;
      if (meshMinForce < minForce)       minForce=meshMinForce;
    }
    observer.add(force / meshes.size());
    println(new StringBuffer(i + "String_Node_Str").append(force / meshes.size()).append("String_Node_Str").append(minForce).append("String_Node_Str").append(maxForce).toString());
    if (i > maxPlateauwidth) {
      proceed=force > maxError;
      int d=maxPlateauwidth;
      while (!proceed && d >= 1) {
        try {
          proceed|=Math.abs(observer.getWideSlope(d)) > 0.0001;
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
        d/=2;
      }
    }
    proceed&=++i < maxIterations;
  }
  for (  final SpringMesh mesh : meshes) {
    mesh.updateAffines();
    mesh.updatePassiveVertices();
  }
  System.out.println("String_Node_Str" + meshes.size() + "String_Node_Str"+ i+ "String_Node_Str");
  System.out.println("String_Node_Str" + decimalFormat.format(force / meshes.size()) + "String_Node_Str");
  System.out.println("String_Node_Str" + decimalFormat.format(minForce) + "String_Node_Str");
  System.out.println("String_Node_Str" + decimalFormat.format(maxForce) + "String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Optimize a   {@link Collection} of connected {@link SpringMesh SpringMeshes}.
 * @param maxError do not accept convergence if error is > max_error
 * @param maxIterations stop after that many iterations even if there wasno minimum found
 * @param maxPlateauwidth convergence is reached if the average slope inan interval of this size is 0.0 (in double accuracy).  This prevents the algorithm from stopping at plateaus smaller than this value.
 */
public static void optimizeMeshes(final Collection<SpringMesh> meshes,final float maxError,final int maxIterations,final int maxPlateauwidth,final boolean visualize) throws NotEnoughDataPointsException {
  final ErrorStatistic observer=new ErrorStatistic(maxPlateauwidth + 1);
  final ErrorStatistic singleMeshObserver=new ErrorStatistic(maxPlateauwidth + 1);
  int i=0;
  double force=0;
  double maxForce=0;
  double minForce=0;
  boolean proceed=i < maxIterations;
  final ImageStack stackAnimation=new ImageStack(VIS_SIZE,VIS_SIZE);
  final ImagePlus impAnimation=new ImagePlus();
  println("String_Node_Str");
  while (proceed) {
    force=0;
    maxForce=0;
    minForce=Double.MAX_VALUE;
    double maxSpeed=0;
    if (visualize) {
      stackAnimation.addSlice("String_Node_Str" + i,paintSprings(meshes,VIS_SIZE,VIS_SIZE,maxError));
      impAnimation.setStack(stackAnimation);
      impAnimation.updateAndDraw();
      if (i == 1) {
        impAnimation.show();
      }
    }
    for (    final SpringMesh mesh : meshes) {
      mesh.calculateForceAndSpeed(singleMeshObserver);
      force+=mesh.getForce();
      if (mesh.maxSpeed > maxSpeed)       maxSpeed=mesh.maxSpeed;
      final double meshMaxForce=mesh.maxForce;
      final double meshMinForce=mesh.minForce;
      if (meshMaxForce > maxForce)       maxForce=meshMaxForce;
      if (meshMinForce < minForce)       minForce=meshMinForce;
    }
    observer.add(force / meshes.size());
    final float dt=(float)Math.min(1000,1.0 / maxSpeed);
    for (    final SpringMesh mesh : meshes) {
      mesh.update(dt);
    }
    println(new StringBuffer(i + "String_Node_Str").append(force / meshes.size()).append("String_Node_Str").append(minForce).append("String_Node_Str").append(maxForce).toString());
    if (i > maxPlateauwidth) {
      proceed=force > maxError;
      int d=maxPlateauwidth;
      while (!proceed && d >= 1) {
        try {
          proceed|=Math.abs(observer.getWideSlope(d)) > 0.0001;
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
        d/=2;
      }
    }
    proceed&=++i < maxIterations;
  }
  for (  final SpringMesh mesh : meshes) {
    mesh.updateAffines();
    mesh.updatePassiveVertices();
  }
  System.out.println("String_Node_Str" + meshes.size() + "String_Node_Str"+ i+ "String_Node_Str");
  System.out.println("String_Node_Str" + decimalFormat.format(force / meshes.size()) + "String_Node_Str");
  System.out.println("String_Node_Str" + decimalFormat.format(minForce) + "String_Node_Str");
  System.out.println("String_Node_Str" + decimalFormat.format(maxForce) + "String_Node_Str");
}