[780] | 1 | package test; |
---|
| 2 | |
---|
| 3 | import java.util.Map; |
---|
| 4 | |
---|
| 5 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 6 | import schedframe.resources.units.PEUnit; |
---|
| 7 | import schedframe.resources.units.ResourceUnit; |
---|
| 8 | import schedframe.resources.units.ResourceUnitName; |
---|
| 9 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 10 | import dcworms.schedframe.scheduling.ExecTask; |
---|
| 11 | import example.timeestimation.BaseTimeEstimationPlugin; |
---|
| 12 | |
---|
| 13 | public class PhaseTimeEstimationPlugin extends BaseTimeEstimationPlugin{ |
---|
| 14 | |
---|
| 15 | /* |
---|
| 16 | * This method should return an estimation of time required to execute the task. |
---|
| 17 | * Requested calculation should be done based on the resources allocated for the task, |
---|
| 18 | * task description and task completion percentage. |
---|
| 19 | * |
---|
| 20 | * Example implementation calculate the estimation based on cpu processing power. |
---|
| 21 | * There is also a simple assumption, that cpu processing power is a linear function |
---|
| 22 | * of number of allocated cpus and their speed. |
---|
| 23 | */ |
---|
| 24 | public double execTimeEstimation(SchedulingEvent event, ExecTask task, |
---|
| 25 | Map<ResourceUnitName, ResourceUnit> allocatedResources, |
---|
| 26 | double completionPercentage) { |
---|
| 27 | |
---|
| 28 | // collect all information necessary to do the calculation |
---|
| 29 | PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); |
---|
| 30 | |
---|
| 31 | // obtain single pe speed |
---|
| 32 | int speed = peUnit.getSpeed(); |
---|
| 33 | |
---|
| 34 | // number of used pe |
---|
| 35 | int cnt = peUnit.getUsedAmount(); |
---|
| 36 | |
---|
| 37 | // estimate remainingTaskLength |
---|
| 38 | double remainingLength = task.getLength() * (1 - completionPercentage/100); |
---|
| 39 | |
---|
| 40 | // do the calculation |
---|
| 41 | double execTime = (remainingLength / (cnt * speed)); |
---|
| 42 | |
---|
| 43 | // if the result is very close to 0, but less then one millisecond then round this result to 0.001 |
---|
| 44 | if (Double.compare(execTime, 0.001) < 0) { |
---|
| 45 | execTime = 0.001; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | // time is measured in integer units, so get the nearest execTime int value. |
---|
| 49 | execTime = Math.round(execTime); |
---|
| 50 | return execTime; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | } |
---|