There is a proof that states that sorting a list of Tasks by their start times will make use of the least amount of machines needed to perform the tasks. I found a case where sorting by their total time makes use of less machines.
Scheduling method: This algorithm makes use of this post to see if times overlap. If they do overlap we make a new machine. If not then we reassign the machine
private static void schedule(ArrayList<Task> tasks, ArrayList<Machine> machines) {
for (Task t : tasks){
boolean canProcess = false;
for(Machine m : machines){
if(t.startTime < m.task.endTime && t.endTime > m.task.startTime)
continue;//this machine is running during this time; look at next machine
canProcess = true;
m.task = t;
break; //go on to the next task
}
if(canProcess == false){
//create a new machine
Machine m = new Machine();
m.task = t;
machines.add(m);
}
}
}
Here is an example of sorting by start time
Start Time: 4 End Time: 7 Total Time: 3
Start Time: 5 End Time: 9 Total Time: 4
Start Time: 6 End Time: 20 Total Time: 14
Start Time: 12 End Time: 21 Total Time: 9
Start Time: 19 End Time: 22 Total Time: 3
Sorting by start time: 3 machines
And here is sorting by Total Time:
Start Time: 4 End Time: 7 Total Time: 3
Start Time: 19 End Time: 22 Total Time: 3
Start Time: 5 End Time: 9 Total Time: 4
Start Time: 12 End Time: 21 Total Time: 9
Start Time: 6 End Time: 20 Total Time: 14
Sorting by total time: 2 machines
Is the theorem broken then or am I not implementing Greedy Scheduling correctly?