-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterval.py
More file actions
42 lines (32 loc) · 816 Bytes
/
Copy pathinterval.py
File metadata and controls
42 lines (32 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
# Greedy Scheduling algorithm for earliest finish
# time first
def earliest_finish_time (jobs):
sched = []
sched.append( jobs[0] )
k = 0
for i in range(1, len(jobs) ):
if jobs[i].start >= jobs[k].finish:
sched.append( jobs[i] )
k = i
return sched
class Job:
name = ''
start = int()
finish = int()
def __init__(self, n, s, f):
self.name = n
self.start = int(s)
self.finish = int(f)
# List of jobs
job_queue = []
with open( sys.argv[1], 'r' ) as f:
for line in f:
line = line.split()
job = Job( line[0], line[1], line[2] )
job_queue.append(job)
# Sort the jobs by finish time
job_queue.sort(key=lambda obj: obj.finish)
sched = earliest_finish_time(job_queue)
for job in sched:
print(job.name)