}
long mediumScore = 0L;
long softScore = 0L;
List<PeriodPowerPrice> periodPowerPriceList = solution.getPeriodPowerPriceList();
for (TaskAssignment taskAssignment : solution.getTaskAssignmentList()) {
Machine machine = taskAssignment.getMachine();
Integer startPeriod = taskAssignment.getStartPeriod();
if (machine != null && startPeriod != null) {
List<MachinePeriodPart> machinePeriodList = machinePeriodListMap.get(machine);
int endPeriod = taskAssignment.getEndPeriod();
for (int period = startPeriod; period < endPeriod; period++) {
MachinePeriodPart machinePeriodPart = machinePeriodList.get(period);
machinePeriodPart.addTaskAssignment(taskAssignment);
PeriodPowerPrice periodPowerPrice = periodPowerPriceList.get(period);
mediumScore -= CheapTimeCostCalculator.multiplyTwoMicros(taskAssignment.getTask().getPowerConsumptionMicros(),
periodPowerPrice.getPowerPriceMicros());
}
softScore -= startPeriod;
}
}
long hardScore = 0L;
for (Map.Entry<Machine, List<MachinePeriodPart>> entry : machinePeriodListMap.entrySet()) {
Machine machine = entry.getKey();
List<MachinePeriodPart> machinePeriodList = entry.getValue();
MachinePeriodStatus previousStatus = MachinePeriodStatus.OFF;
long idleCostMicros = 0L;
for (int period = 0; period < globalPeriodRangeTo; period++) {
PeriodPowerPrice periodPowerPrice = periodPowerPriceList.get(period);
MachinePeriodPart machinePeriodPart = machinePeriodList.get(period);
boolean active = machinePeriodPart.isActive();
if (active) {
if (previousStatus == MachinePeriodStatus.OFF) {
// Spin up
mediumScore -= machine.getSpinUpDownCostMicros();
} else if (previousStatus == MachinePeriodStatus.IDLE) {
// Pay idle cost
mediumScore -= idleCostMicros;
idleCostMicros = 0L;
}
hardScore += machinePeriodPart.getHardScore();
mediumScore -= CheapTimeCostCalculator.multiplyTwoMicros(machine.getPowerConsumptionMicros(),
periodPowerPrice.getPowerPriceMicros());
previousStatus = MachinePeriodStatus.ACTIVE;
} else {
if (previousStatus != MachinePeriodStatus.OFF) {
idleCostMicros += CheapTimeCostCalculator.multiplyTwoMicros(machine.getPowerConsumptionMicros(),
periodPowerPrice.getPowerPriceMicros());
if (idleCostMicros > machine.getSpinUpDownCostMicros()) {
idleCostMicros = 0L;
previousStatus = MachinePeriodStatus.OFF;
} else {
previousStatus = MachinePeriodStatus.IDLE;
}