-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathjobScheduling.py
More file actions
30 lines (20 loc) · 820 Bytes
/
jobScheduling.py
File metadata and controls
30 lines (20 loc) · 820 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
from heapq import heappop, heappush
from collections import deque, namedtuple
Job = namedtuple('Job', ['jobProcess', 'requestTime', 'id'])
def jobScheduling(requestTime, jobProcess, timeFromStart):
jobs = deque(
Job(jp, rt, i)
for i, (rt, jp) in enumerate(zip(requestTime, jobProcess))
)
curr_job = next_finish = None
queue = []
for t in range(timeFromStart + 1):
while jobs and jobs[0].requestTime <= t:
heappush(queue, jobs.popleft())
if curr_job and t >= next_finish:
curr_job = next_finish = None
if next_finish is None and queue:
curr_job = heappop(queue)
next_finish = t + curr_job.jobProcess
size = len(queue)
return [j.id for j in sorted(queue)]