Minimizing maximum lateness : Greedy algorithm – Algorithms and Me
We have a processor which can process one process a time and as always given list of processes to be scheduled on that process, with intention that maximum late process should be minimized. Contrary to previous problems, this time, we are not provided with start time and end time, but we are given length of time (ti) process will run and deadline it has to meet (di), fi is actual finish time of process completion.
Lateness of a process is defined asl(i) = max{0, fi − di}, i.e. the length of time past its deadline that it finishes.Goal here schedule all jobs to minimize maximum lateness L = max {l(i)}
1. Sort all job in ascending order of deadlines 2. Start with time t = 0; 3. For each job in list 3.1 Schedule the ob at time t 3.2 Finish time = t + processing time of job 3.3 t = finish time 4. Return (start time, finish time) for each job
- from operator import itemgetter
- jobs = [(1, 3, 6), (2, 2, 9), (3, 1, 8), (4, 4, 9), (5, 3, 14), (6, 2, 15)]
- def get_minimum_lateness():
- schedule =[];
- max_lateness = 0
- t = 0;
- sorted_jobs = sorted(jobs,key=itemgetter(2))
- for job in sorted_jobs:
- job_start_time = t
- job_finish_time = t + job[1] # add the processing time to currrent time
- # and that will be finish time
- t = job_finish_time
- if(job_finish_time > job[2]):
- max_lateness = max (max_lateness, (job_finish_time - job[2]))
- schedule.append((job_start_time, job_finish_time))
- return max_lateness, schedule
- max_lateness, sc = get_minimum_lateness();
- print "Maximum lateness will be :" + str(max_lateness)
- for t in sc:
- print t[0], t[1]