-
-
Notifications
You must be signed in to change notification settings - Fork 46.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added earliest deadline first scheduling algo #10431
base: master
Are you sure you want to change the base?
Changes from 1 commit
76fd929
4363669
bbac298
4d156e5
628b1b3
9397c73
31e43db
22f40d9
1f6eed8
6238c4a
f845dd4
f31b31e
b7b7f3e
242757a
21dfa20
62b7d77
3a1a6de
0d054c9
ff72709
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
''' | ||
Earliest Deadline First (EDF) Scheduling Algorithm | ||
|
||
This code implements the Earliest Deadline First (EDF) | ||
scheduling algorithm, which schedules processes based on their deadlines. | ||
If a process cannot meet its deadline, it is marked as "Idle." | ||
|
||
Reference: | ||
https://www.geeksforgeeks.org/earliest-deadline-first-edf-cpu-scheduling-algorithm/ | ||
|
||
Author: Arunkumar | ||
Date: 14th October 2023 | ||
''' | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation |
||
def earliest_deadline_first_scheduling(processes: list[tuple[str, int, int, int]]) -> list[str]: | ||
""" | ||
Perform Earliest Deadline First (EDF) scheduling. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Input Validation: You may want to add some input validation to ensure that the input list of processes is well-formed. For example, you can check if the arrival time is less than or equal to the deadline for each process There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once the code is merged, make a pull request on enhancement and do it! 👍 |
||
Args: | ||
processes (List[Tuple[str, int, int, int]]): A list of processes with their names, | ||
arrival times, deadlines, and execution times. | ||
|
||
Returns: | ||
List[str]: A list of process names in the order they are executed. | ||
|
||
Examples: | ||
>>> processes = [("A", 1, 5, 2), ("B", 2, 8, 3), ("C", 3, 4, 1)] | ||
>>> execution_order = earliest_deadline_first_scheduling(processes) | ||
>>> execution_order | ||
['Idle', 'A', 'C', 'B'] | ||
|
||
""" | ||
result = [] | ||
current_time = 0 | ||
|
||
while processes: | ||
available_processes = [ | ||
process for process in processes if process[1] <= current_time | ||
] | ||
|
||
if not available_processes: | ||
result.append("Idle") | ||
current_time += 1 | ||
else: | ||
next_process = min( | ||
available_processes, key=lambda x: x[2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide descriptive name for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test are failing |
||
) | ||
name, _ , deadline, execution_time = next_process | ||
|
||
if current_time + execution_time <= deadline: | ||
result.append(name) | ||
current_time += execution_time | ||
processes.remove(next_process) | ||
else: | ||
result.append("Idle") | ||
current_time += 1 | ||
|
||
return result | ||
|
||
if __name__ == "__main__": | ||
processes = [("A", 1, 5, 2), ("B", 2, 8, 3), ("C", 3, 4, 1)] | ||
execution_order = earliest_deadline_first_scheduling(processes) | ||
for i, process in enumerate(execution_order): | ||
print(f"Time {i}: Executing process {process}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code currently sorts processes by deadline each time it needs to find the next process to execute