@@ -95,7 +95,9 @@ def calculate_average_times(
9595 return avg_wait , avg_turn
9696
9797
98- def plot_gantt_chart (timeline : list [tuple [int , int , int ]], processes : list [int ]) -> None :
98+ def plot_gantt_chart (
99+ timeline : list [tuple [int , int , int ]], processes : list [int ]
100+ ) -> None :
99101 """Plot a Gantt chart for process execution."""
100102 fig , ax = plt .subplots (figsize = (10 , 2 ))
101103 colors = plt .cm .tab10 .colors # Nice color set
@@ -108,14 +110,24 @@ def plot_gantt_chart(timeline: list[tuple[int, int, int]], processes: list[int])
108110 edgecolor = "black" ,
109111 label = f"P{ processes [pid ]} " ,
110112 )
111- ax .text ((start + end ) / 2 , 0 , f"P{ processes [pid ]} " , ha = "center" , va = "center" , color = "white" , fontsize = 9 )
113+ ax .text (
114+ (start + end ) / 2 ,
115+ 0 ,
116+ f"P{ processes [pid ]} " ,
117+ ha = "center" ,
118+ va = "center" ,
119+ color = "white" ,
120+ fontsize = 9 ,
121+ )
112122
113123 ax .set_xlabel ("Time" )
114124 ax .set_yticks ([])
115125 ax .set_title ("Gantt Chart - Shortest Job Remaining First (SJF Preemptive)" )
116126 handles , labels = plt .gca ().get_legend_handles_labels ()
117127 by_label = dict (zip (labels , handles ))
118- ax .legend (by_label .values (), by_label .keys (), bbox_to_anchor = (1.05 , 1 ), loc = "upper left" )
128+ ax .legend (
129+ by_label .values (), by_label .keys (), bbox_to_anchor = (1.05 , 1 ), loc = "upper left"
130+ )
119131 plt .tight_layout ()
120132 plt .show ()
121133
@@ -132,14 +144,24 @@ def plot_gantt_chart(timeline: list[tuple[int, int, int]], processes: list[int])
132144 print (f"Enter the arrival time and burst time for process { i + 1 } :" )
133145 arrival_time [i ], burst_time [i ] = map (int , input ().split ())
134146
135- waiting_time , timeline = calculate_waitingtime (arrival_time , burst_time , no_of_processes )
136- turn_around_time = calculate_turnaroundtime (burst_time , no_of_processes , waiting_time )
147+ waiting_time , timeline = calculate_waitingtime (
148+ arrival_time , burst_time , no_of_processes
149+ )
150+ turn_around_time = calculate_turnaroundtime (
151+ burst_time , no_of_processes , waiting_time
152+ )
137153 calculate_average_times (waiting_time , turn_around_time , no_of_processes )
138154
139155 # Display results table
140156 df = pd .DataFrame (
141157 list (zip (processes , arrival_time , burst_time , waiting_time , turn_around_time )),
142- columns = ["Process" , "ArrivalTime" , "BurstTime" , "WaitingTime" , "TurnAroundTime" ],
158+ columns = [
159+ "Process" ,
160+ "ArrivalTime" ,
161+ "BurstTime" ,
162+ "WaitingTime" ,
163+ "TurnAroundTime" ,
164+ ],
143165 )
144166 pd .set_option ("display.max_rows" , df .shape [0 ] + 1 )
145167 print ("\n --- Process Table ---" )
0 commit comments