Skip to content

Commit 93b1530

Browse files
committed
Update
1 parent f4860bd commit 93b1530

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed
323 Bytes
Loading

CPU_Scheduler/PreemptivePriorityScheduling.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class _PreemptivePriorityScheduling: # Class for simulating Preemptive Priority
88
fourColumnProcessList = []
99
waitingTime = 0
1010
turnaroundTime = 0
11+
start_times = []
12+
end_times = []
13+
1114
def inputUser(self, no_of_processes): # USER INPUT
1215
for process_id in range(1, no_of_processes + 1): # Loop to enter user values for each process
1316
temporary = [] # Temporary list to store values
@@ -65,16 +68,11 @@ def inputRandom(self, no_of_processes, max_BT): # RANDOM INPUT
6568
return self.fourColumnProcessList
6669

6770
def schedulingProcess(self): # Scheduling Algorithm
68-
# Print input table
69-
print("\nProcess\tArrival Time\tBurst Time\tPriority Level")
70-
for process in self.process_list:
71-
print(f"{process[0]}\t{process[1]}\t\t{process[2]}\t\t{process[4]}")
7271

7372
current_time = 0 # Current Time Frame
7473
completed_list = [] # List for completed processes
7574
ready_queue = [] # Memory Queue
76-
start_times = []
77-
end_times = []
75+
7876
while len(completed_list) < len(self.process_list): # Loop for the Algorithm
7977
for process in self.process_list:
8078
if process[1] <= current_time and process not in completed_list and process not in ready_queue: # Inserting newly arrived processes to the Memory Queue
@@ -102,10 +100,10 @@ def schedulingProcess(self): # Scheduling Algorithm
102100
ready_queue.pop(0) # Remove current process from ready queue
103101
current_process[5] = current_time + 1 # Set completion time for current process
104102

105-
if len(start_times) < len(completed_list):
106-
start_times.append(current_time)
107-
if len(end_times) < len(completed_list):
108-
end_times.append(current_time + 1)
103+
if len(self.start_times) < len(completed_list):
104+
self.start_times.append(current_time)
105+
if len(self.end_times) < len(completed_list):
106+
self.end_times.append(current_time + 1)
109107

110108
current_time += 1 # Increment Current Time Frame
111109

@@ -125,7 +123,9 @@ def schedulingProcess(self): # Scheduling Algorithm
125123
avg_tt = total_tt / len(self.process_list)
126124

127125

128-
return
126+
self.waitingTime = avg_wt
127+
self.turnaroundTime = avg_wt
128+
return completed_list
129129
# # Print table results
130130
# print("\nProcess\tWaiting Time\tTurnaround Time")
131131
# for process in self.process_list:
221 Bytes
Binary file not shown.

CPU_Scheduler/main.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,19 @@ def __init__(self, master):
126126
def setBT(self, value):
127127
self.BTSlider_CurValue.configure(text=math.trunc(value))
128128

129-
def generateGC_PPS(self):
130-
pass
129+
def generateGC_PPS(self, completed_list, start_times, end_times):
130+
fig, ax = plt.subplots()
131+
for i, process in enumerate(completed_list):
132+
start_time = start_times[i]
133+
end_time = end_times[i]
134+
process_name = process[0]
135+
ax.barh(process_name, end_time - start_time, left=start_time, label=process_name)
131136

137+
ax.set_xlabel('Time', fontsize=9)
138+
ax.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))
139+
plt.grid(axis='x')
140+
plt.savefig("./GANTT_OUTPUT/GTChart.png", bbox_inches='tight', dpi=100)
132141
def GenerateGANTT_Chart(self, process_Timing):
133-
134142
fig, ax = plt.subplots()
135143
for i, (process, timings) in enumerate(process_Timing.items()):
136144
start, end = timings
@@ -146,17 +154,22 @@ def GenerateGANTT_Chart(self, process_Timing):
146154

147155
def startExecution(self):
148156
global NP
157+
global WT
158+
global TT
149159
NP = int(self.Process_Input.get())
150160
if self.AlgoMenu.get() == "Preemptive Priority Scheduling":
151-
global WT
152-
global TT
161+
153162
processList = self.PPS_Instance.inputRandom(int(self.Process_Input.get()), math.trunc(self.Burst_Time.get()))
163+
completed_list = self.PPS_Instance.schedulingProcess()
164+
WT = self.PPS_Instance.waitingTime
165+
TT = self.PPS_Instance.turnaroundTime
166+
start_times = self.PPS_Instance.start_times
167+
end_times = self.PPS_Instance.end_times
168+
self.generateGC_PPS(completed_list, start_times, end_times)
154169

155170

156171

157172
elif self.AlgoMenu.get() == "Non-Preemtive Priotity Scheduling":
158-
global WT
159-
global TT
160173
processList = self.PPS_Instance.inputRandom(int(self.Process_Input.get()), math.trunc(self.Burst_Time.get()))
161174
processTiming = self.NonPPS_Instance.Execute(processList)
162175
WT = self.NonPPS_Instance.waitingTime

0 commit comments

Comments
 (0)