-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.py
164 lines (122 loc) · 3.58 KB
/
input.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
class CPUBurst:
time: int = None
def __init__(self, time: int) -> None:
self.time = time
def clone(self):
return CPUBurst(self.time)
class IOWait:
time: int = None
def __init__(self, time: int) -> None:
self.time = time
def clone(self):
return IOWait(self.time)
class Sequence:
seq = None
def __init__(self) -> None:
self.seq = []
def clone(self):
s = SequenceBuilder()
for x in self.seq:
s.addtoSeq(x.clone())
return s.getSequence()
def printSequence(self, front=""):
# print(front, end="")
for item in self.seq:
print(item.time, end=" ")
print()
class SequenceBuilder:
sequence: Sequence = None
def __init__(self) -> None:
self.sequence = Sequence()
def addtoSeq(self, item):
self.sequence.seq.append(item)
def getSequence(self) -> Sequence:
t: Sequence = self.sequence
self.sequence = Sequence()
return t
class Job:
name: str = None
priority: int = None
arrTime: int = None
curr: int = 97
seq: Sequence = None
def __init__(self) -> None:
self.priority = 0
self.arrTime = 0
self.name = chr(Job.curr)
self.seq = Sequence()
Job.curr += 1
if (Job.curr > 97 + 26):
Job.curr = 97
def timeLeft(self):
sum = 0
for x in self.seq.seq:
sum += x.time
return sum
def decrementTime(self, time):
i = 0
for i in range(len(self.seq.seq)):
if (self.seq.seq[i].time != 0):
self.seq.seq[i].time -= time
return True
return False
def clone(self):
j = Job()
j.priority = self.priority
j.arrTime = self.arrTime
j.name = self.name
j.seq = self.seq.clone()
return j
def printJob(self, front=""):
print(front, "Name: ", self.name)
print(front, "Priority: ", self.priority)
print(front, "Arrival Time: ", self.arrTime)
print(front, "Sequence: ", end="")
self.seq.printSequence(front=front + "\t")
class JobBuilder:
job: Job = None
def __init__(self) -> None:
self.job = Job()
def setPriority(self, priority: int):
self.job.priority = priority
def setName(self, name: str):
self.job.name = name
def setSequence(self, seq: Sequence):
self.job.seq = seq
def setArrivalTime(self, time: int):
self.job.arrTime = time
def getJob(self) -> Job:
t: Job = self.job
self.job = Job()
return t
class Input:
jobs: list[Job] = None
primitive: bool = None
time_quantum: int = None
def __init__(self) -> None:
self.jobs = []
self.primitive = False
self.time_quantum = 3
def printInput(self) -> None:
print("Primitve: ", self.primitive)
if (self.primitive):
print("Time Quantum: ", self.time_quantum)
print("Jobs: ")
for job in self.jobs:
job.printJob(front="\t")
print()
class InputBuilder:
input_var: Input = None
def __init__(self) -> None:
self.input_var = Input()
def addJob(self, job: Job) -> None:
if (self.input_var):
self.input_var.jobs.append(job)
def setPrimitive(self, val: bool):
self.input_var.primitive = val
def setTQ(self, val: int):
self.input_var.time_quantum = val
def getInput(self) -> Input:
t: Input = self.input_var
self.input_var = Input()
return t