-
Notifications
You must be signed in to change notification settings - Fork 0
/
Discscheduling.py
1221 lines (1047 loc) · 47.3 KB
/
Discscheduling.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from tkinter import ttk
from matplotlib import pyplot as plt
from functools import partial
from tkinter import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
from matplotlib.animation import FuncAnimation
from gtts import gTTS
import os
from operator import itemgetter
import pyttsx3
from fpdf import FPDF
from tkinter.filedialog import asksaveasfile
def Discscheduling():
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.setProperty('rate', 130)
root = Tk()
root.title("Disk Scheduling")
root.geometry("1000x800")
my_notebook = ttk.Notebook(root, width=3000, height=1000)
my_notebook.grid(row=30, column=30)
my_notebook.pack(pady=1)
my_frame1 = Frame(my_notebook)
my_frame2 = Frame(my_notebook)
my_frame3 = Frame(my_notebook)
my_frame1.pack()
my_frame2.pack()
my_frame3.pack()
my_notebook.add(my_frame1, text="Practice")
my_notebook.add(my_frame2, text="Simulation")
my_notebook.add(my_frame3, text="Comparison")
def speak(audio):
engine.say(audio)
engine.runAndWait()
def fcfs(arr, head, directions, mi_cyl, ma_cyl, num):
initial_head = head
seek_count = 0;
distance, cur_track = 0, mi_cyl;
q = []
arr = [initial_head] + arr
for i in range(len(arr)):
cur_track = arr[i]
distance = abs(cur_track - head)
seek_count += distance
q.append(seek_count)
head = cur_track
a = "Total number of seek operations = " + str(seek_count) + "\n"
print(a)
print(l, "1")
print(l, "2")
if num == "2":
report.delete("1.0", "end")
report.insert(INSERT, a)
report.insert(INSERT, arr[0:])
elif num == "4":
report2.delete("1.0", "end")
report2.insert(INSERT, a)
report2.insert(INSERT, arr[0:])
else:
T1.insert(INSERT, seek_count)
# T11.insert(INSERT,arr[1:])
if num == "2" or num == "4":
x = arr
y = q
# mylabel=Label(root,text=a).grid(row=4,column=4)
fig = Figure(figsize=(3, 3), dpi=130)
ax = fig.add_subplot()
ax.set_xlim(mi_cyl, ma_cyl)
ax.set_ylim(0, max(y) + 100)
ax.set_xlabel('READ/WRITE HEAD POSITION')
ax.set_ylabel('SEEK TIME SPENT')
fig.tight_layout()
x_data = []
y_data = []
line, = ax.plot(0, 0, marker='o', color='r')
def animation_frame(i):
x_data.append(x[i])
y_data.append(y[i])
line.set_xdata(x_data)
line.set_ydata(y_data)
return line
if num == "2":
canvas = FigureCanvasTkAgg(fig, master=my_frame1)
canvas.get_tk_widget().grid(row=3, column=5, columnspan=10, rowspan=20, padx=0, pady=0)
else:
canvas = FigureCanvasTkAgg(fig, master=my_frame2)
canvas.get_tk_widget().grid(row=12, column=3, columnspan=10, rowspan=20, padx=0, pady=0)
animation = FuncAnimation(fig, func=animation_frame, frames=np.arange(0, len(x), 1), interval=1000,
repeat=False)
"""plt.plot(arr,q).grid(row=10,column=2)
ax = plt.gca()
ax.axes.yaxis.set_visible(False)
ax.xaxis.set_ticks_position('top')
plt.gca().invert_yaxis()"""
for i in range(len(x)):
ax.annotate(x[i], (x[i], y[i]))
canvas.draw()
if num == "3":
return seek_count
# mylabel=Label(root,text="okay").grid(row=3)
# root.grid()
def scan(arr, head, directions, mi_cyl, ma_cyl, num):
array = sorted(arr)
Starting_posi = head
answer = 0;
y = [mi_cyl]
total_tracks = ma_cyl;
maximum = max(array)
minimum = min(array)
l = [head]
a = ""
if (directions == "LEFT"):
for i in range(len(array)):
if (array[i] <= Starting_posi):
i = i + 1
else:
break
i = i - 1
d = i + 1
while (i >= 0):
answer += abs(array[i] - Starting_posi)
y.append(answer)
l.append(array[i])
Starting_posi = array[i]
i = i - 1
answer += abs(mi_cyl - Starting_posi)
y.append(answer)
l.append(mi_cyl)
Starting_posi = mi_cyl
while (d < len(array)):
answer += abs(array[d] - Starting_posi)
y.append(answer)
l.append(array[d])
Starting_posi = array[d]
d = d + 1
a = "Total no of movements it will require is :" + str(answer) + "\n"
if (directions == "RIGHT"):
for i in range(len(array)):
if (array[i] <= Starting_posi):
i = i + 1
else:
break
d = i - 1
while (i < len(array)):
answer += abs(array[i] - Starting_posi)
y.append(answer)
l.append(array[i])
Starting_posi = array[i]
i = i + 1
answer += abs((ma_cyl - 1) - Starting_posi)
y.append(answer)
l.append(ma_cyl - 1)
Starting_posi = ma_cyl - 1
while (d >= 0):
answer += abs(array[d] - Starting_posi)
y.append(answer)
l.append(array[d])
Starting_posi = array[d]
d = d - 1
a = "Total no of movements it will require is :" + str(answer) + "\n"
if num == "2":
report.delete("1.0", "end")
report.insert(INSERT, a)
report.insert(INSERT, l[1:])
elif num == "4":
report2.delete("1.0", "end")
report2.insert(INSERT, a)
report2.insert(INSERT, l[1:])
else:
T3.insert(INSERT, answer)
# T77.insert(INSERT,l[1:])
x = l
if num == "2" or num == "4":
fig = Figure(figsize=(3, 3), dpi=130)
ax = fig.add_subplot()
ax.set_xlim(mi_cyl, ma_cyl)
ax.set_ylim(0, max(y) + 100)
ax.set_xlabel('READ/WRITE HEAD POSITION')
ax.set_ylabel('SEEK TIME SPENT')
fig.tight_layout()
x_data = []
y_data = []
line, = ax.plot(0, 0, marker='o', color='r')
print(x)
print(y)
def animation_frame(i):
x_data.append(x[i])
y_data.append(y[i])
line.set_xdata(x_data)
line.set_ydata(y_data)
return line
if num == "2":
canvas = FigureCanvasTkAgg(fig, master=my_frame1)
canvas.get_tk_widget().grid(row=3, column=5, columnspan=10, rowspan=20, padx=0, pady=0)
else:
canvas = FigureCanvasTkAgg(fig, master=my_frame2)
canvas.get_tk_widget().grid(row=12, column=3, columnspan=10, rowspan=20, padx=0, pady=0)
animation = FuncAnimation(fig, func=animation_frame, frames=np.arange(0, len(x), 1), interval=1000,
repeat=False)
for i in range(len(x)):
ax.annotate(x[i], (x[i], y[i]))
canvas.draw()
if num == "3":
return answer
def cscan(arr, head, directions, mi_cyl, ma_cyl, num):
array = sorted(arr)
Starting_posi = head
answer = 0;
y = [mi_cyl]
total_tracks = ma_cyl;
maximum = max(array)
minimum = min(array)
l = [head]
a = ""
if (directions == "LEFT"):
for i in range(len(array)):
if (array[i] <= Starting_posi):
i = i + 1
else:
break
i = i - 1
m = len(array)
d = i + 1
while (i >= 0):
answer += abs(array[i] - Starting_posi)
y.append(answer)
l.append(array[i])
Starting_posi = array[i]
i = i - 1
answer += abs(mi_cyl - Starting_posi)
y.append(answer)
l.append(mi_cyl)
Starting_posi = mi_cyl
answer += abs(Starting_posi - (ma_cyl - 1))
y.append(answer)
l.append(ma_cyl - 1)
Starting_posi = ma_cyl
while (m > d):
answer += abs(array[m - 1] - Starting_posi)
y.append(answer)
l.append(array[m - 1])
Starting_posi = array[m - 1]
m = m - 1
a = "Total no of movements it will require is :" + str(answer) + "\n"
if (directions == "RIGHT"):
for i in range(len(array)):
if (array[i] <= Starting_posi):
i = i + 1
else:
break
d = i - 1
print(i)
print(array)
while (i < len(array)):
answer += abs(array[i] - Starting_posi)
y.append(answer)
l.append(array[i])
Starting_posi = array[i]
i = i + 1
answer += abs((ma_cyl - 1) - Starting_posi)
y.append(answer)
l.append(ma_cyl - 1)
Starting_posi = ma_cyl
answer += abs(Starting_posi - (mi_cyl))
y.append(answer)
l.append(mi_cyl)
Starting_posi = mi_cyl
j = 0
while (j <= d):
answer += abs(array[j] - Starting_posi)
y.append(answer)
l.append(array[j])
Starting_posi = array[j]
j = j + 1
a = "Total no of movements it will require is :" + str(answer) + "\n"
if num == "2":
report.delete("1.0", "end")
report.insert(INSERT, a)
report.insert(INSERT, l[1:])
elif num == "4":
report2.delete("1.0", "end")
report2.insert(INSERT, a)
report2.insert(INSERT, l[1:])
else:
T5.insert(INSERT, answer)
# T77.insert(INSERT,l[1:])
x = l
if num == "2" or num == "4":
fig = Figure(figsize=(3, 3), dpi=130)
ax = fig.add_subplot()
ax.set_xlim(mi_cyl, ma_cyl)
ax.set_ylim(0, max(y) + 100)
ax.set_xlabel('READ/WRITE HEAD POSITION')
ax.set_ylabel('SEEK TIME SPENT')
fig.tight_layout()
x_data = []
y_data = []
line, = ax.plot(0, 0, marker='o', color='r')
def animation_frame(i):
x_data.append(x[i])
y_data.append(y[i])
line.set_xdata(x_data)
line.set_ydata(y_data)
return line
if num == "2":
canvas = FigureCanvasTkAgg(fig, master=my_frame1)
canvas.get_tk_widget().grid(row=3, column=5, columnspan=10, rowspan=20, padx=0, pady=0)
else:
canvas = FigureCanvasTkAgg(fig, master=my_frame2)
canvas.get_tk_widget().grid(row=12, column=3, columnspan=10, rowspan=20, padx=0, pady=0)
animation = FuncAnimation(fig, func=animation_frame, frames=np.arange(0, len(x), 1), interval=1000,
repeat=False)
for i in range(len(x)):
ax.annotate(x[i], (x[i], y[i]))
canvas.draw()
if num == "3":
return answer
def calculateDifference(queue, head, diff):
for i in range(len(diff)):
diff[i][0] = abs(queue[i] - head)
# find unaccessed track which is
# at minimum distance from head
def findMin(diff):
index = -1
minimum = 999999999
for i in range(len(diff)):
if (not diff[i][1] and
minimum > diff[i][0]):
minimum = diff[i][0]
index = i
return index
def sstgraph(request, head, directions, mi_cyl, ma_cyl, num):
initial_head = head
if (len(request) == 0):
return
l = len(request)
diff = [0] * l
# initialize array
for i in range(l):
diff[i] = [0, 0]
# count total number of seek operation
seek_count = 0
q = [0]
# stores sequence in which disk
# access is done
seek_sequence = [0] * (l + 1)
x_array = []
for i in range(l):
seek_sequence[i] = head
calculateDifference(request, head, diff)
index = findMin(diff)
diff[index][1] = True
cur_track = request[index]
x_array.append(cur_track)
# increase the total count
seek_count += diff[index][0]
q.append(seek_count)
# accessed track is now new head
head = request[index]
# for last accessed track
seek_sequence[len(seek_sequence) - 1] = head
a = "Total number of seek operations = " + str(seek_count) + "\n"
# mylabel=Label(root,text=a).grid(row=3,column=1)
x_array.insert(0, initial_head)
if num == "2":
report.delete("1.0", "end")
report.insert(INSERT, a)
report.insert(INSERT, x_array[1:])
elif num == "4":
report2.delete("1.0", "end")
report2.insert(INSERT, a)
report2.insert(INSERT, x_array[1:])
else:
T2.insert(INSERT, seek_count)
# T22.insert(INSERT,x_array[1:])
if num == "2" or num == "4":
x = x_array
y = q
fig = Figure(figsize=(3, 3), dpi=130)
ax = fig.add_subplot()
ax.set_xlim(mi_cyl, ma_cyl)
ax.set_ylim(mi_cyl, max(q) + 100)
ax.set_xlabel('READ/WRITE HEAD POSITION')
ax.set_ylabel('SEEK TIME SPENT')
fig.tight_layout()
x_data = []
y_data = []
line, = ax.plot(0, 0, marker='o', color='r')
def animation_frame(i):
x_data.append(x[i])
y_data.append(y[i])
line.set_xdata(x_data)
line.set_ydata(y_data)
return line
if num == "2":
canvas = FigureCanvasTkAgg(fig, master=my_frame1)
canvas.get_tk_widget().grid(row=3, column=5, columnspan=10, rowspan=20, padx=0, pady=0)
else:
canvas = FigureCanvasTkAgg(fig, master=my_frame2)
canvas.get_tk_widget().grid(row=12, column=3, columnspan=10, rowspan=20, padx=0, pady=0)
animation = FuncAnimation(fig, func=animation_frame, frames=np.arange(0, len(x), 1), interval=1000,
repeat=False)
"""plt.plot(x_array,q)
ax = plt.gca()
ax.axes.yaxis.set_visible(False)
ax.xaxis.set_ticks_position('top')
plt.gca().invert_yaxis()"""
for i in range(len(x)):
ax.annotate(x[i], (x[i], y[i]))
canvas.draw()
if num == "3":
return seek_count
def LIFO(arr, head, directions, mi_cyl, ma_cyl, num):
initial_head = head
seek_counts = 0
distance, cur_track = 0, mi_cyl
q = [0]
x_array = [head]
for i in range(len(arr)):
cur_track = arr[len(arr) - i - 1]
x_array.append(cur_track)
distance = abs(cur_track - head)
seek_counts += distance
q.append(seek_counts)
head = cur_track
a = "Total number of seek operations = " + str(seek_counts) + "\n"
# mylabel=Label(root,text=a).grid(row=4,column=1)
print(seek_counts)
# arr.insert(0,initial_head)
if num == "2":
report.delete("1.0", "end")
report.insert(INSERT, a)
report.insert(INSERT, x_array[1:])
elif num == "4":
report2.delete("1.0", "end")
report2.insert(INSERT, a)
report2.insert(INSERT, x_array[1:])
else:
T4.insert(INSERT, seek_counts)
# T44.insert(INSERT,x_array[1:])
if num == "2" or num == "4":
x = x_array
y = q
fig = Figure(figsize=(3, 3), dpi=130)
ax = fig.add_subplot()
ax.set_xlim(mi_cyl, ma_cyl)
ax.set_ylim(0, max(q) + 100)
ax.set_xlabel('READ/WRITE HEAD POSITION')
ax.set_ylabel('SEEK TIME SPENT')
fig.tight_layout()
x_data = []
y_data = []
line, = ax.plot(0, 0, marker='o', color='r')
def animation_frame(i):
x_data.append(x[i])
y_data.append(y[i])
line.set_xdata(x_data)
line.set_ydata(y_data)
return line
if num == "2":
canvas = FigureCanvasTkAgg(fig, master=my_frame1)
canvas.get_tk_widget().grid(row=3, column=5, columnspan=10, rowspan=20, padx=0, pady=0)
else:
canvas = FigureCanvasTkAgg(fig, master=my_frame2)
canvas.get_tk_widget().grid(row=12, column=3, columnspan=10, rowspan=20, padx=0, pady=0)
animation = FuncAnimation(fig, func=animation_frame, frames=np.arange(0, len(x), 1), interval=1000,
repeat=False)
"""plt.plot(x_array,q)
ax = plt.gca()
ax.axes.yaxis.set_visible(False)
ax.xaxis.set_ticks_position('top')
plt.gca().invert_yaxis()"""
for i in range(len(x)):
ax.annotate(x[i], (x[i], y[i]))
canvas.draw()
if num == "3":
return seek_counts
def LOOK(arr, head, directions, mi_cyl, ma_cyl, num):
array = sorted(arr)
Starting_posi = head
answer = 0;
y = [mi_cyl]
total_tracks = ma_cyl;
maximum = max(array)
minimum = min(array)
l = [head]
a = ""
if (directions == "LEFT"):
for i in range(len(array)):
if (array[i] <= Starting_posi):
i = i + 1
else:
break
i = i - 1
d = i + 1
while (i >= 0):
answer += abs(array[i] - Starting_posi)
y.append(answer)
l.append(array[i])
Starting_posi = array[i]
i = i - 1
while (d < len(array)):
answer += abs(array[d] - Starting_posi)
y.append(answer)
l.append(array[d])
Starting_posi = array[d]
d = d + 1
a = "Total no of movements it will require is :" + str(answer) + "\n"
if (directions == "RIGHT"):
for i in range(len(array)):
if (array[i] <= Starting_posi):
i = i + 1
else:
break
d = i - 1
while (i < len(array)):
answer += abs(array[i] - Starting_posi)
y.append(answer)
l.append(array[i])
Starting_posi = array[i]
i = i + 1
while (d >= 0):
answer += abs(array[d] - Starting_posi)
y.append(answer)
l.append(array[d])
Starting_posi = array[d]
d = d - 1
a = "Total no of movements it will require is :" + str(answer) + "\n"
if num == "2":
report.delete("1.0", "end")
report.insert(INSERT, a)
report.insert(INSERT, l[1:])
elif num == "4":
report2.delete("1.0", "end")
report2.insert(INSERT, a)
report2.insert(INSERT, l[1:])
else:
T7.insert(INSERT, answer)
# T77.insert(INSERT,l[1:])
x = l
if num == "2" or num == "4":
fig = Figure(figsize=(3, 3), dpi=130)
ax = fig.add_subplot()
ax.set_xlim(mi_cyl, ma_cyl)
ax.set_ylim(0, max(y) + 100)
ax.set_xlabel('READ/WRITE HEAD POSITION')
ax.set_ylabel('SEEK TIME SPENT')
fig.tight_layout()
x_data = []
y_data = []
line, = ax.plot(0, 0, marker='o', color='r')
print(x)
print(y)
def animation_frame(i):
x_data.append(x[i])
y_data.append(y[i])
line.set_xdata(x_data)
line.set_ydata(y_data)
return line
if num == "2":
canvas = FigureCanvasTkAgg(fig, master=my_frame1)
canvas.get_tk_widget().grid(row=3, column=5, columnspan=10, rowspan=20, padx=0, pady=0)
else:
canvas = FigureCanvasTkAgg(fig, master=my_frame2)
canvas.get_tk_widget().grid(row=12, column=3, columnspan=10, rowspan=20, padx=0, pady=0)
animation = FuncAnimation(fig, func=animation_frame, frames=np.arange(0, len(x), 1), interval=1000,
repeat=False)
for i in range(len(x)):
ax.annotate(x[i], (x[i], y[i]))
canvas.draw()
if num == "3":
return answer
def C_LOOK(arr, head, directions, mi_cyl, ma_cyl, num):
array = sorted(arr)
Starting_posi = head
answer = 0;
y = [mi_cyl]
total_tracks = ma_cyl;
maximum = max(array)
minimum = min(array)
l = [head]
a = ""
if (directions == "LEFT"):
for i in range(len(array)):
if (array[i] <= Starting_posi):
i = i + 1
else:
break
i = i - 1
m = len(array) - 1
d = i + 1
while (i >= 0):
answer += abs(array[i] - Starting_posi)
y.append(answer)
l.append(array[i])
Starting_posi = array[i]
i = i - 1
answer += abs(array[i] - array[m])
Starting_posi = array[m]
l.append(array[m])
y.append(answer)
while (m > d):
answer += abs(array[m - 1] - Starting_posi)
y.append(answer)
l.append(array[m - 1])
Starting_posi = array[m - 1]
m = m - 1
a = "Total no of movements it will require is :" + str(answer) + "\n"
if (directions == "RIGHT"):
for i in range(len(array)):
if (array[i] <= Starting_posi):
i = i + 1
else:
break
d = i - 1
print(i)
print(array)
while (i < len(array)):
answer += abs(array[i] - Starting_posi)
y.append(answer)
l.append(array[i])
Starting_posi = array[i]
i = i + 1
m = 0
answer += abs(array[i - 1] - array[m])
Starting_posi = array[m]
l.append(array[m])
y.append(answer)
while (m < d):
answer += abs(array[m + 1] - Starting_posi)
y.append(answer)
l.append(array[m + 1])
Starting_posi = array[m + 1]
m = m + 1
a = "Total no of movements it will require is :" + str(answer) + "\n"
if num == "2":
report.delete("1.0", "end")
report.insert(INSERT, a)
report.insert(INSERT, l[1:])
elif num == "4":
report2.delete("1.0", "end")
report2.insert(INSERT, a)
report2.insert(INSERT, l[1:])
else:
T8.insert(INSERT, answer)
# T77.insert(INSERT,l[1:])
x = l
if num == "2" or num == "4":
fig = Figure(figsize=(3, 3), dpi=130)
ax = fig.add_subplot()
ax.set_xlim(mi_cyl, ma_cyl)
ax.set_ylim(0, max(y) + 100)
ax.set_xlabel('READ/WRITE HEAD POSITION')
ax.set_ylabel('SEEK TIME SPENT')
fig.tight_layout()
x_data = []
y_data = []
line, = ax.plot(0, 0, marker='o', color='r')
def animation_frame(i):
x_data.append(x[i])
y_data.append(y[i])
line.set_xdata(x_data)
line.set_ydata(y_data)
return line
if num == "2":
canvas = FigureCanvasTkAgg(fig, master=my_frame1)
canvas.get_tk_widget().grid(row=3, column=5, columnspan=10, rowspan=20, padx=0, pady=0)
else:
canvas = FigureCanvasTkAgg(fig, master=my_frame2)
canvas.get_tk_widget().grid(row=12, column=3, columnspan=10, rowspan=20, padx=0, pady=0)
animation = FuncAnimation(fig, func=animation_frame, frames=np.arange(0, len(x), 1), interval=1000,
repeat=False)
for i in range(len(x)):
ax.annotate(x[i], (x[i], y[i]))
canvas.draw()
if num == "3":
return answer
k = Label(my_frame1, text=" Enter Request Points :").grid(row=3, column=0)
l = []
def comman():
try:
l.clear()
INPUT = inputtxt.get("1.0", "end-1c")
for i in INPUT.split(","):
l.append(int(i))
a = variablem.get()
directions = variable1.get()
initial_hp = int(head_texto.get("1.0", "end-1c"))
mi_cyl = int(mincyl_text.get("1.0", "end-1c"))
ma_cyl = int(maxcyl_text.get("1.0", "end-1c"))
print(ma_cyl)
if a == "LIFO":
LIFO(l, initial_hp, directions, mi_cyl, ma_cyl, "2")
elif a == "SSTF":
sstgraph(l, initial_hp, directions, mi_cyl, ma_cyl, "2")
elif a == "SCAN":
scan(l, initial_hp, directions, mi_cyl, ma_cyl, "2")
elif a == "LOOK":
LOOK(l, initial_hp, directions, mi_cyl, ma_cyl, "2")
elif a == "FCFS":
fcfs(l, initial_hp, directions, mi_cyl, ma_cyl, "2")
elif a == "CLOOK":
C_LOOK(l, initial_hp, directions, mi_cyl, ma_cyl, "2")
elif a == "CSCAN":
cscan(l, initial_hp, directions, mi_cyl, ma_cyl, "2")
except Exception as e:
print(e)
report.insert(INSERT, "Enter the points properly")
def pdfconversion():
try:
INPUT2 = inputtxt.get("1.0", "end-1c")
directions2 = variable1.get()
initial_hp2 = head_texto.get("1.0", "end-1c")
mi_cyl2 = mincyl_text.get("1.0", "end-1c")
ma_cyl2 = maxcyl_text.get("1.0", "end-1c")
ans2 = report.get("1.0", "end-1c")
a2 = variablem.get()
out = a2 + "\n" + "The request points are " + INPUT2 + "\n" + "The initial head position " + initial_hp2 + "\n" + "The direction is " + directions2 + "\n" + "The Maximum cylinder is " + ma_cyl2 + "\n" + "The Minimum Cylinder is " + mi_cyl2 + "\n" + "The output is " + ans2
files = [('All Files', '*.*'), ('Text Document', '*.txt')]
file = asksaveasfile(filetypes=files, defaultextension="w")
file.write(out)
file.close()
"""pdf.cell(200, 10, txt = ,ln = 3, align = 'L')
pdf.cell(200, 10, txt =,ln = 4, align = 'L')
pdf.cell(200, 10, txt = ,ln = 5, align = 'L')
pdf.cell(200, 10, txt = ,ln = 6, align = 'L')
pdf.cell(200, 10, txt =,ln = 7, align = 'L')
pdf.output("OutputFile.pdf")"""
except Exception as e:
print(e)
# first frame
variablem = StringVar(my_frame1)
variable1 = StringVar(my_frame1)
inputtxt = Text(my_frame1, height=3, width=25, bg="light yellow")
inputtxt.grid(row=3, column=1)
blank1 = Label(my_frame1, text=" ").grid(row=0, columnspan=2)
variablem.set("LIFO") # default value
k1 = Label(my_frame1, text="Select the Algorithm :").grid(row=1, column=0)
w = OptionMenu(my_frame1, variablem, "LIFO", "SSTF", "SCAN", "CSCAN", "LOOK", "CLOOK", "FCFS")
w.grid(row=1, column=1)
button = Button(my_frame1, text="RUN", command=comman, padx=85).grid(row=15, column=1)
blank4 = Label(my_frame1, text=" ").grid(row=2, column=0)
blank2 = Label(my_frame1, text=" ").grid(row=4, column=0)
head = Label(my_frame1, text="Intial Head Position :").grid(row=5, column=0)
head_texto = Text(my_frame1, height=1, width=25, bg="light yellow")
head_texto.grid(row=5, column=1, padx=50)
blank5 = Label(my_frame1, text=" ").grid(row=6, column=0)
variable1.set("RIGHT")
direction = Label(my_frame1, text="Direction:").grid(row=7, column=0)
direction_op = OptionMenu(my_frame1, variable1, "RIGHT", "LEFT").grid(row=7, column=1)
blank6 = Label(my_frame1, text=" ").grid(row=8, column=0)
max_cyl = Label(my_frame1, text="Maximum Cylinder :").grid(row=9, column=0)
maxcyl_text = Text(my_frame1, height=1, width=25, bg="light yellow")
maxcyl_text.grid(row=9, column=1)
blank7 = Label(my_frame1, text=" ").grid(row=10, column=0)
min_cyl = Label(my_frame1, text="Minimum Cylinder :").grid(row=11, column=0)
mincyl_text = Text(my_frame1, height=1, width=25, bg="light yellow")
mincyl_text.grid(row=11, column=1)
answer = Label(my_frame1, text="Answer :")
answer.grid(row=13, column=0)
blank3 = Label(my_frame1, text=" ").grid(row=12, column=0)
blank8 = Label(my_frame1, text=" ").grid(row=14, column=0)
blank9 = Label(my_frame1, text=" ").grid(row=16, column=0)
save = Button(my_frame1, text="SAVE", command=pdfconversion, padx=85).grid(row=17, column=1)
blank8 = Label(my_frame1, text=" ").grid(row=18, column=0)
report = Text(my_frame1, height=3, width=25, bg="light yellow")
report.grid(row=13, column=1)
# second frame
def comman2():
tex.delete("1.0", "end")
a = variables.get()
li = [176, 79, 34, 60, 92, 11, 41, 114]
if a == "LIFO":
LIFO(li, 50, "RIGHT", 0, 200, "4")
tex.insert(INSERT, "In LIFO (Last In, First Out) algorithm, newest jobs are serviced before the existing ones")
speak("In LIFO (Last In, First Out) algorithm, newest jobs are serviced before the existing ones")
elif a == "SSTF":
sstgraph(li, 50, "RIGHT", 0, 200, "4")
tex.insert(INSERT,
"In SSTF (Shortest Seek Time First), requests having shortest seek time are executed first. So, the seek time of every request is calculated in advance in the queue and then they are scheduled according to their calculated seek time. As a result, the request near the disk arm will get executed first. SSTF is certainly an improvement over FCFS as it decreases the average response time and increases the throughput of system.")
speak(
"In SSTF (Shortest Seek Time First), requests having shortest seek time are executed first. So, the seek time of every request is calculated in advance in the queue and then they are scheduled according to their calculated seek time. As a result, the request near the disk arm will get executed first. SSTF is certainly an improvement over FCFS as it decreases the average response time and increases the throughput of system.")
elif a == "SCAN":
scan(li, 50, "RIGHT", 0, 200, "4")
tex.insert(INSERT,
"In SCAN algorithm the disk arm moves into a particular direction and services the requests coming in its path and after reaching the end of disk, it reverses its direction and again services the request arriving in its path. So, this algorithm works as an elevator and hence also known as elevator algorithm. As a result, the requests at the midrange are serviced more and those arriving behind the disk arm will have to wait.")
speak(
"In SCAN algorithm the disk arm moves into a particular direction and services the requests coming in its path and after reaching the end of disk, it reverses its direction and again services the request arriving in its path. So, this algorithm works as an elevator and hence also known as elevator algorithm. As a result, the requests at the midrange are serviced more and those arriving behind the disk arm will have to wait.")
elif a == "LOOK":
LOOK(li, 50, "RIGHT", 0, 200, "4")
tex.insert(INSERT,
"Disk arm goes only to the last request to be serviced in front of the head and then reverses its direction from there only. Thus it prevents the extra delay which occurred due to unnecessary traversal to the end of the disk.")
speak(
"disk arm goes only to the last request to be serviced in front of the head and then reverses its direction from there only. Thus it prevents the extra delay which occurred due to unnecessary traversal to the end of the disk.")
elif a == "FCFS":
fcfs(li, 50, "RIGHT", 0, 200, "4")
tex.insert(INSERT, "In FCFS, the requests are addressed in the order they arrive in the disk queue.")
speak(" In FCFS, the requests are addressed in the order they arrive in the disk queue.")
elif a == "CSCAN":
cscan(li, 50, "RIGHT", 0, 200, "4")
tex.insert(INSERT,
"In CSCAN algorithm in which the disk arm instead of reversing its direction goes to the other end of the disk and starts servicing the requests from there. So, the disk arm moves in a circular fashion and this algorithm is also similar to SCAN algorithm and hence it is known as C-SCAN (Circular SCAN)")
speak(
"In CSCAN algorithm in which the disk arm instead of reversing its direction goes to the other end of the disk and starts servicing the requests from there. So, the disk arm moves in a circular fashion and this algorithm is also similar to SCAN algorithm and hence it is known as C-SCAN (Circular SCAN)")
elif a == "CLOOK":
C_LOOK(li, 50, "RIGHT", 0, 200, "4")
tex.insert(INSERT,
"Disk arm goes only to the last request to be serviced in front of the head and then from there goes to the other end’s last request. Thus, it also prevents the extra delay which occurred due to unnecessary traversal to the end of the disk.")
speak(
"Disk arm goes only to the last request to be serviced in front of the head and then from there goes to the other end’s last request. Thus, it also prevents the extra delay which occurred due to unnecessary traversal to the end of the disk.")
""""try:
l=[176, 79, 34, 60, 92, 11, 41, 114]
if a=="LIFO":
LIFO(l,50,"RIGHT",0,200,"4")
elif a=="SSTF":
print(a)
sstgraph(l,50,"RIGHT",0,200,"4")
elif a=="SCAN":
scan(l,50,"RIGHT",0,200,"4")
elif a=="LOOK":
LOOK(l,50,"RIGHT",0,200,"4")
elif a=="FCFS":
fcfs(l,50,"RIGHT",0,200,"4")
except :
report2.insert(INSERT,"Enter the points properly")"""
variables = StringVar(my_frame2)
k3 = Label(my_frame2, text=" Enter Request Points :").grid(row=3, column=0)
v = StringVar(my_frame2, value='default text')
inputtxt2 = Text(my_frame2, height=3, width=25, bg="lightgreen")
inputtxt2.grid(row=3, column=1)
inputtxt2.insert(INSERT, "176, 79, 34, 60, 92, 11, 41, 114")
inputtxt2.config(state="disabled")
blank1 = Label(my_frame2, text=" ").grid(row=0, columnspan=2)
b0 = Label(my_frame2, text=" ").grid(row=0, column=1)
variables.set("LIFO") # default value
k1 = Label(my_frame2, text="Select the Algorithm :").grid(row=1, column=0)
w = OptionMenu(my_frame2, variables, "LIFO", "SSTF", "SCAN", "CSCAN", "LOOK", "CLOOK", "FCFS").grid(row=1, column=1)
button = Button(my_frame2, text="RUN", command=comman2, padx=85).grid(row=15, column=1)
blank4 = Label(my_frame2, text=" ").grid(row=2, column=0)
b2 = Label(my_frame2, text=" ").grid(row=2, column=1)
blank2 = Label(my_frame2, text=" ").grid(row=4, column=0)
b4 = Label(my_frame2, text=" ").grid(row=4, column=1)
head = Label(my_frame2, text="Intial Head Position :").grid(row=5, column=0)
head_text = Text(my_frame2, height=1, width=25, bg="lightgreen")
head_text.grid(row=5, column=1, padx=50)
head_text.insert(INSERT, "50")
head_text.config(state="disabled")
blank5 = Label(my_frame2, text=" ").grid(row=6, column=0)
b6 = Label(my_frame2, text=" ").grid(row=6, column=1)
variable1.set("RIGHT")
direction = Label(my_frame2, text="Direction:").grid(row=7, column=0)
direction_op = Text(my_frame2, height=1, width=25, bg="lightgreen")
direction_op.grid(row=7, column=1)
direction_op.insert(INSERT, "RIGHT")