-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
47 lines (42 loc) · 1.22 KB
/
util.py
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
43
44
45
46
47
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @File Name: util.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @File Name: util.py
import glb
import os.path
class Timekeeper():
"""Tracks time for all processes"""
def __init__(self):
self.now = 0
def tick(self):
self.now += 1
def getNow(self):
return self.now
class Random():
"""Random variable generator"""
def __init__(self, filename):
if not os.path.isfile(filename):
raise Exception('The input file does not exist. The input filename should be the last argument.')
self.file = open(filename,'r')
def randInt(self):
return int(self.file.readline().strip())
def randomOS(self, U):
randInt = self.randInt()
if glb.sr:
print('Find burst when choosing ready process to run', randInt)
return 1 + randInt % U
def parseInput(filename):
"""returns list of process specs"""
result = []
if not os.path.isfile(filename):
raise Exception('The input file does not exist. The input filename should be the last argument.')
with open(filename, 'r') as f:
nums = []
for l in f:
nums += [int(el) for el in l.strip().split() if el.isnumeric()]
psl = nums.pop(0) #processes (list) length
for i in range(psl):
result.append(nums[4*i:4*i+4])
return result