Last active
November 20, 2023 15:36
-
-
Save Xnuvers007/f58b8940fa7d2ccd941aa4d283592b3d to your computer and use it in GitHub Desktop.
Fcfs disk scheduling algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| def fcfs_disk_scheduling(sequence, initial_seek): | |
| sequence.insert(0, initial_seek) | |
| total_head_movements = 0 | |
| head_movements = [initial_seek] | |
| for i in range(1, len(sequence)): | |
| head_movement = abs(sequence[i] - sequence[i-1]) | |
| total_head_movements += head_movement | |
| head_movements.append(sequence[i]) | |
| return total_head_movements, head_movements | |
| sequence = [150, 40, 30, 54, 13, 80, 70, 20] | |
| initial_seek = 50 | |
| total_head_movements, head_movements = fcfs_disk_scheduling( | |
| sequence, initial_seek) | |
| sequence_labels = [str(val) for val in sequence] | |
| sequence_labels.insert(0, str(initial_seek)) | |
| plt.text(0.5, 0.5, f'Total Head Movements: {total_head_movements}', | |
| horizontalalignment='center', verticalalignment='center', transform=plt.gca().transAxes) | |
| plt.plot(range(len(head_movements)), head_movements, marker='o') | |
| plt.title('FCFS Disk Scheduling\nIndra Dwi Aryadi (211011450468)') | |
| plt.xlabel('Disk Position') | |
| plt.ylabel('Sequence Index') | |
| plt.xticks(range(len(sequence_labels)), sequence_labels) | |
| for i in range(1, len(sequence)): | |
| plt.text(i, -10, f'{sequence[i]} - {sequence[i-1]} = {abs(sequence[i] - sequence[i-1])}', | |
| fontsize=8, ha='center', va='bottom') | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| size = 8 | |
| def FCFS(arr, head): | |
| seek_count = 0 | |
| distance, cur_track = 0, 0 | |
| for i in range(size): | |
| cur_track = arr[i] | |
| distance = abs(cur_track - head) | |
| seek_count += distance | |
| head = cur_track | |
| # Tampilkan perhitungan | |
| print(f"{distance} ({cur_track} - {head})") | |
| print("\nTotal jumlah operasi pencarian = ", seek_count) | |
| print("Urutan pencarian adalah") | |
| for i in range(size): | |
| print(arr[i]) | |
| # Driver code | |
| if __name__ == '__main__': | |
| arr = [106, 79, 31, 60, 90, 10, 39, 110] | |
| head = 50 | |
| FCFS(arr, head) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| size = 9 # Menyesuaikan ukuran array | |
| def FCFS(arr, head): | |
| seek_count = 0 | |
| distance, cur_track = 0, head | |
| for i in range(size): | |
| cur_track = arr[i] | |
| distance = abs(cur_track - head) | |
| seek_count += distance | |
| # Tampilkan perhitungan | |
| print(f"{distance} ({cur_track} - {head})") | |
| head = cur_track | |
| print("\nTotal jumlah operasi pencarian = ", seek_count) | |
| print("Urutan pencarian adalah") | |
| for i in range(size): | |
| print(arr[i]) | |
| print("\nIndra Dwi Aryadi (211011450468)") | |
| # Driver code | |
| if __name__ == '__main__': | |
| arr = [106, 79, 31, 60, 90, 10, 39, 44, 110] | |
| head = 40 | |
| FCFS(arr, head) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GrafikFCFS.py
