long days_per_bucket = MSEC_PER_BUCKET/TimeUtils.MSEC_PER_DAY; double cl_per_bucket = (double)criticalLevel/(double)days_per_bucket; int mode = (int)Math.floor(cl_per_bucket); double Ci; criticalLevelsArray = new double[projectedDemandArray.length];  if (mode == 0) { for (int i=0; i < projectedDemandArray.length; i++) { Ci =  projectedDemandArray[i] * cl_per_bucket; criticalLevelsArray[i] = Ci; } } else { int buckets = (int)Math.floor(cl_per_bucket); double fe = cl_per_bucket - buckets; Ci = 0.0; for (int i=1; i <= buckets; i++) { Ci += projectedDemandArray[i]; } Ci += projectedDemandArray[buckets+1]*fe; criticalLevelsArray[0] = Ci; for (int i=1; i < projectedDemandArray.length-buckets-1; i++) { Ci =  Ci - projectedDemandArray[i] + projectedDemandArray[i+buckets]*(1-fe)+ projectedDemandArray[i+buckets+1]*fe; criticalLevelsArray[i] = Ci; } for (int i=projectedDemandArray.length-buckets-1; i < projectedDemandArray.length; i++) { Ci =  Ci - projectedDemandArray[i]; criticalLevelsArray[i] = Ci; } } return criticalLevelsArray; }
  private double[] computeCriticalLevels() {    if (regenerate_projected_demand) {      regenerateProjectedDemandList();      regenerate_projected_demand = false;    }    long days_per_bucket = MSEC_PER_BUCKET/TimeUtils.MSEC_PER_DAY;    double cl_per_bucket = (double)criticalLevel/(double)days_per_bucket;    int mode = (int)Math.floor(cl_per_bucket);    double Ci;    criticalLevelsArray = new double[projectedDemandArray.length];    // Number of days in criticalLevel falls within a single bucket    if (mode == 0) {       for (int i=0; i < projectedDemandArray.length; i++) {	Ci =  projectedDemandArray[i] * cl_per_bucket;	criticalLevelsArray[i] = Ci;      }    } else { // Number of days in criticalLevel spans multiple buckets      int buckets = (int)Math.floor(cl_per_bucket);      double fe = cl_per_bucket - buckets;      Ci = 0.0;      for (int i=1; i <= buckets; i++) {	Ci += projectedDemandArray[i];      }      Ci += projectedDemandArray[buckets+1]*fe;      criticalLevelsArray[0] = Ci;      for (int i=1; i < projectedDemandArray.length-buckets-1; i++) {	Ci =  Ci - projectedDemandArray[i] + projectedDemandArray[i+buckets]*(1-fe)+	  projectedDemandArray[i+buckets+1]*fe;	criticalLevelsArray[i] = Ci;      }      for (int i=projectedDemandArray.length-buckets-1; i < projectedDemandArray.length; i++) {	Ci =  Ci - projectedDemandArray[i];	criticalLevelsArray[i] = Ci;      }    }    return criticalLevelsArray;  }