double safety = determineSafetyIncrement(periodBegin, day-1, inventory); Task t = newProjectSupplyTask(inventory, start, start + (day - periodBegin) * TimeUtils.MSEC_PER_DAY, createIncrementedDailyRate(previous, safety));    projections.add(t); invpg.addDueIn(t);
ReorderIncrement si = determineReorderIncrement(periodBegin, day, inventory); int nDays; nDays = si.highestDay - periodBegin; if (nDays > 0) { long end = start + nDays * TimeUtils.MSEC_PER_DAY; double reorder = (si.highest - si.first) / nDays; Task t = newProjectSupplyTask(inventory, start, end, createIncrementedDailyRate(previous, reorder)); projections.add(t); invpg.addDueIn(t); start = end; } nDays = day - si.highestDay; if (nDays > 0) { long end = start + nDays * TimeUtils.MSEC_PER_DAY; double reorder = (si.last - si.highest) / nDays; Task t = newProjectSupplyTask(inventory, start, end, createIncrementedDailyRate(previous, reorder)); projections.add(t); invpg.addDueIn(t); }
    protected Enumeration generateProjections(Inventory inventory) {//  	printDebug("STEP 2:  GenerateProjections() for "+AssetUtils.getAssetIdentifier(inventory));	Vector projections = new Vector();	InventoryPG invpg = (InventoryPG) inventory.searchForPropertyGroup(InventoryPG.class);	int days = invpg.getPlanningDays();	int today = invpg.getFirstPlanningDay();	int periodBegin = today;	Scalar previous = invpg.getProjected(today);//  	printDebug(0, "!!!!!!!!!!!!!!!!! first day of demand : "//                 + TimeUtils.dateString(TimeUtils.addNDays(invpg.getStartTime(),today))//                 + ", INV START: "+TimeUtils.dateString(invpg.getStartTime()));        /* Loop from tomorrow to the day after the inventory planning         * window ends. The extra step at the end allow the final         * segment to be processed.         */	for (int day = today + 1; day <= days; day++) {            Scalar current = (day < days) ? invpg.getProjected(day) : null;            if (!previous.equals(current)) {                double value = convertScalarToDouble(previous);                if (!Double.isNaN(value) && value > 0.0) {                    long start = TimeUtils.addNDays(invpg.getStartTime(), periodBegin);                    // safety accounts for the safety level which the inventory attempts to maintain.                    // add the safety 'demand' to projected demand.                    double safety = determineSafetyIncrement(periodBegin, day-1, inventory);                    Task t = newProjectSupplyTask(inventory, start,                                                  start + (day - periodBegin) * TimeUtils.MSEC_PER_DAY,                                                   createIncrementedDailyRate(previous, safety));//                      if (safety > 0) {//                          printDebug(0, "  !!! projection with dailyRate=" + createDailyRate(previous)+" and safetyRate="+safety);//                      }                    projections.add(t);                    invpg.addDueIn(t);//                      printDebug("generateProjections(), created Projection task. Start: "//                                 + TimeUtils.dateString(start)+", End: "//                                 + TimeUtils.dateString(TimeUtils.addNDays(invpg.getStartTime(), day))//                                 + ", Value: "+previous);                }                periodBegin = day;	    }	    previous = current;	}	return projections.elements();    }