Skip to content

Commit 4a6ae85

Browse files
committed
update
1 parent 2e94251 commit 4a6ae85

File tree

5 files changed

+53
-43
lines changed

5 files changed

+53
-43
lines changed
17.8 KB
Loading

CPU_Scheduler/NonPreemptivePriorityScheduling.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class _NonPreemptivePriorityScheduling:
1212

1313
processList = []
14-
14+
process_Timing = {}
1515
# Function to get the user input for processes
1616
def User_Input(self, Num_Process):
1717
for IDprocess in range(1, Num_Process + 1):
@@ -51,21 +51,21 @@ def Random_Input(self, Num_Process, Max_Burst):
5151

5252
# Execution of the Algorithm
5353
def Execute(self, processList):
54-
table = Table(title="Non-Preemptive Priority Scheduling", style="bold white")
55-
table.add_column("Process ID", style="bold cyan", justify="center")
56-
table.add_column("Arrival Time", style="bold cyan", justify="center")
57-
table.add_column("Burst Time", style="bold cyan", justify="center")
58-
table.add_column("Priority Level", style="bold cyan", justify="center")
59-
60-
for process in self.processList:
61-
table.add_row(process[0], str(process[1]), str(process[2]), str(process[3]))
54+
# Gin comment out ko anay kay dire gamit
55+
# table = Table(title="Non-Preemptive Priority Scheduling", style="bold white")
56+
# table.add_column("Process ID", style="bold cyan", justify="center")
57+
# table.add_column("Arrival Time", style="bold cyan", justify="center")
58+
# table.add_column("Burst Time", style="bold cyan", justify="center")
59+
# table.add_column("Priority Level", style="bold cyan", justify="center")
60+
61+
# for process in self.processList:
62+
# table.add_row(process[0], str(process[1]), str(process[2]), str(process[3]))
63+
6264

63-
# console.print(table)
64-
6565
currentTime = 0
6666
ProcessComplete = []
6767
MemoryQueue = []
68-
68+
process_timings = {}
6969
print("\n\n--------Gantt Chart Simulation--------") # Simulation or displaying of process of the algorithm
7070
while len(ProcessComplete) < len(self.processList):
7171
for process in self.processList:
@@ -86,10 +86,13 @@ def Execute(self, processList):
8686

8787
current_process = MemoryQueue.pop(0) # pops the first elemnt stored in the memory queue
8888
ProcessComplete.append(current_process)
89+
self.process_Timing[current_process[0]] = (currentTime, currentTime+current_process[2])
90+
print(f"{current_process[0]} : {currentTime} - {currentTime+current_process[2]}")
8991
currentTime += current_process[2]
9092

93+
9194
console.print(f"Running: {current_process[0]}")
92-
console.print(f"Burst Time: 0")
95+
console.print(f"Burst Time: {current_process[2]}")
9396
console.print(f"Priority lvl: {current_process[3]}\n")
9497
console.rule(style="green", characters="-")
9598
sleep(1)
@@ -108,20 +111,22 @@ def Execute(self, processList):
108111
WT = totalWT / len(self.processList) # Waiting time
109112
TT = totalTT / len(self.processList) # Turnaround TIme
110113

111-
table2 = Table(title="Results", style="bold white")
112-
table2.add_column("Process ID", style="bold cyan", justify="center")
113-
table2.add_column("Waiting Time", style="bold cyan", justify="center")
114-
table2.add_column("Turnaround Time", style="bold cyan", justify="center")
115114

116-
for process in self.processList:
117-
waitingTime = currentTime - process[1] - process[2]
118-
turnarroundTime = waitingTime + process[2]
119-
table2.add_row(process[0], str(waitingTime), str(turnarroundTime))
115+
return self.process_Timing
116+
# table2 = Table(title="Results", style="bold white")
117+
# table2.add_column("Process ID", style="bold cyan", justify="center")
118+
# table2.add_column("Waiting Time", style="bold cyan", justify="center")
119+
# table2.add_column("Turnaround Time", style="bold cyan", justify="center")
120+
121+
# for process in self.processList:
122+
# waitingTime = currentTime - process[1] - process[2]
123+
# turnarroundTime = waitingTime + process[2]
124+
# table2.add_row(process[0], str(waitingTime), str(turnarroundTime))
120125

121-
console.print(table2)
126+
# console.print(table2)
122127

123-
console.print(f"WT average: {WT}")
124-
console.print(f"TT average: {TT}\n\n")
128+
# console.print(f"WT average: {WT}")
129+
# console.print(f"TT average: {TT}\n\n")
125130

126131

127132
# Main Function of the program
@@ -142,4 +147,4 @@ def mainFunction():
142147

143148

144149

145-
mainFunction()
150+
# mainFunction()
20.1 KB
Loading
Binary file not shown.

CPU_Scheduler/main.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, master):
2626
self.title.grid(row=0, column=0, sticky="ew", pady=20, padx=20)
2727
# The Table generated by Matplotlib that shows the process
2828
# this inlucdes the Process ID, Burst Time, Arrival Time and Priority Number
29-
self.myimg = customtkinter.CTkImage(Image.open("table.png"), size=(400, self.height))
29+
self.myimg = customtkinter.CTkImage(Image.open("./PROCESSTABLE_OUTPUT/table.png"), size=(400, self.height))
3030
self.imgLabel = customtkinter.CTkLabel(self, image=self.myimg, text="")
3131
self.imgLabel.grid(row=1, column=0, sticky="nsew")
3232

@@ -56,7 +56,7 @@ def __init__(self, master):
5656
self.title.grid(row=2, column=0, sticky="ew", pady=20, padx=20)
5757
self.TT_Result = customtkinter.CTkLabel(self, text="Result", fg_color="transparent", width=20)
5858

59-
self.myimg = customtkinter.CTkImage(Image.open("table.png"), size=(400, self.height))
59+
self.myimg = customtkinter.CTkImage(Image.open("./GANTT_OUTPUT/GTChart.png"), size=(400, self.height))
6060
self.imgLabel = customtkinter.CTkLabel(self, image=self.myimg, text="")
6161
self.imgLabel.grid(row=3, column=0, sticky="nsew")
6262

@@ -114,8 +114,7 @@ def __init__(self, master):
114114
def setBT(self, value):
115115
self.BTSlider_CurValue.configure(text=math.trunc(value))
116116

117-
def GenerateGANTT_Chart(self):
118-
pass
117+
119118

120119
def GenerateProcessTable(self):
121120
global NP
@@ -133,25 +132,40 @@ def GenerateProcessTable(self):
133132
self.table.set_fontsize(10)
134133
self.table.scale(1, 1.5)
135134
self.fig.tight_layout()
136-
plt.savefig("table.png", bbox_inches='tight', dpi=150)
135+
plt.savefig("./PROCESSTABLE_OUTPUT/table.png", bbox_inches='tight', dpi=150)
137136

137+
def GenerateGANTT_Chart(self):
138+
self.processList = self.NonPPS_Instance.Random_Input(int(self.Process_Input.get()), math.trunc(self.Burst_Time.get()))
139+
self.process_Timing = self.NonPPS_Instance.Execute(self.processList)
140+
fig, ax = plt.subplots()
141+
for i, (process, timings) in enumerate(self.process_Timing.items()):
142+
start, end = timings
143+
ax.barh(i, end - start, left=start, align='center', label=process)
144+
145+
ax.set_xlabel('Time')
146+
ax.set_yticks(range(len(self.process_Timing)))
147+
ax.set_yticklabels(self.process_Timing.keys())
148+
ax.set_title('Gantt Chart')
149+
plt.legend(loc='upper right')
150+
plt.grid(axis='x')
151+
plt.savefig("./GANTT_OUTPUT/GTChart.png", bbox_inches='tight', dpi=150)
152+
138153
def startExecution(self):
139154
if self.AlgoMenu.get() == "Preemptive Priority Scheduling":
140155
self.toplev = ToplevelWindow(self) ## This Generates the Top Level window that shows the charts and Table
141-
156+
142157
## Draw Table for processes
143158
pass
144159
## Draw GANTT Chart
145160

146161
elif self.AlgoMenu.get() == "Non-Preemtive Priotity Scheduling":
147-
self.toplev = ToplevelWindow(self) ## This Generates the Top Level window that shows the charts and Table
148-
149162
## Draw Table for processes
150163
self.GenerateProcessTable()
151164

152165
## Draw GANTT Chart
153-
166+
self.GenerateGANTT_Chart()
154167

168+
self.toplev = ToplevelWindow(self) ## This Generates the Top Level window that shows the charts and Table
155169

156170

157171
class App(customtkinter.CTk):
@@ -181,15 +195,6 @@ def __init__(self):
181195
### OPTION MENU
182196
self.optionMenu = OptionWindow(self)
183197
self.optionMenu.grid(row=4, column=0, sticky="ew", columnspan=2, padx=50, pady=10)
184-
185-
### PLOT Window
186-
# self.plotWindow = PlotWindow(self)
187-
# self.plotWindow.grid(row=0, column=0, columnspan=2, sticky="nesw", padx=20, pady=20)
188-
189-
190-
191-
192-
193198

194199
app = App()
195200
app.mainloop()

0 commit comments

Comments
 (0)