double lastlevel = (thePG.getCriticalLevel(startReorderBucket) + startTarget) / 2; thePG.setLevel(startReorderBucket, lastlevel);
if (startReorderBucket != -1 ) { double lastlevel = (thePG.getCriticalLevel(startReorderBucket) + startTarget) / 2; thePG.setLevel(startReorderBucket, lastlevel); }
  private void setTargetForProjectionPeriod(LogisticsInventoryPG thePG, int startBucket){    int currentBucket = startBucket;    int reorderPeriod = (int)thePG.getReorderPeriod();    int reorderPeriodEndBucket = startBucket + reorderPeriod;    int lastDemandBucket = thePG.getLastDemandBucket();    double criticalLevelBegin, criticalLevelEnd;    int startReorderBucket = -1;    double startTarget = -1;    while (currentBucket <= lastDemandBucket) {      criticalLevelBegin = thePG.getCriticalLevel(currentBucket);      criticalLevelEnd = thePG.getCriticalLevel(reorderPeriodEndBucket);      double demand = calculateDemandForPeriod(thePG, currentBucket, reorderPeriodEndBucket);      double target = (criticalLevelEnd - criticalLevelBegin) + demand;      logger.debug("bucket: "+currentBucket+", reorderPeriod end bucket: "+reorderPeriodEndBucket+		   ", critical begin: "+criticalLevelBegin+", critical end: "+criticalLevelEnd+		   ", demand: "+demand+", Target: "+target);      if (target < 0.0) {	target = 0.0;      }            // fill in the inventory levels for projections based on the target levels      // but don't start until we have two target points      if (startReorderBucket != -1) {        // set the inventory levels for the entire reorder period based on the two        // target levels we have        int levelBucket = startReorderBucket;        double calcTarget;        while (levelBucket < currentBucket) {          if ( (levelBucket == startReorderBucket) || (startTarget == target) ) {            calcTarget = startTarget;          } else {            int bucketsSpanned = currentBucket - startReorderBucket;            int bucketDiff = levelBucket - startReorderBucket;            double diff = target - startTarget;             calcTarget = startTarget + ((diff/bucketsSpanned) * bucketDiff);          }          //inv level in projection land is the average of the critcial and target levels          double level = (thePG.getCriticalLevel(levelBucket) + calcTarget) / 2;          thePG.setLevel(levelBucket, level);          levelBucket = levelBucket + 1;        }      }      thePG.setTarget(currentBucket, target);      startReorderBucket = currentBucket;      startTarget = target;      currentBucket += reorderPeriod;      reorderPeriodEndBucket = currentBucket + reorderPeriod;    }    //at the end fill in the last inv level based on the last target level    double lastlevel = (thePG.getCriticalLevel(startReorderBucket) + startTarget) / 2;    thePG.setLevel(startReorderBucket, lastlevel);  }