Skip to content
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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
76fd929
earliest deadline first scheduling algo added
Arunsiva003 Oct 14, 2023
4363669
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2023
bbac298
earliest deadline first scheduling algo added
Arunsiva003 Oct 14, 2023
4d156e5
earliest deadline first scheduling algo added 2
Arunsiva003 Oct 14, 2023
628b1b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2023
9397c73
ceil and floor and bst
Arunsiva003 Oct 14, 2023
31e43db
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2023
22f40d9
ceil and floor and bst 2
Arunsiva003 Oct 14, 2023
1f6eed8
ceil and floor and bst 2
Arunsiva003 Oct 14, 2023
6238c4a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2023
f845dd4
ceil and floor and bst 3
Arunsiva003 Oct 14, 2023
f31b31e
Merge branch 'create' of https://github.com/Arunsiva003/Python into c…
Arunsiva003 Oct 14, 2023
b7b7f3e
Merge branch 'TheAlgorithms:master' into master
Arunsiva003 Oct 19, 2023
242757a
Merge branch 'master' of https://github.com/Arunsiva003/Python into c…
Arunsiva003 Oct 20, 2023
21dfa20
optimized and corrected longest increasing subsequence problem
Arunsiva003 Oct 20, 2023
62b7d77
Merge branch 'TheAlgorithms:master' into master
Arunsiva003 Oct 23, 2023
3a1a6de
Merge branch 'TheAlgorithms:master' into optimize
Arunsiva003 Oct 23, 2023
0d054c9
Merge branch 'optimize' of https://github.com/Arunsiva003/Python
Arunsiva003 Oct 23, 2023
ff72709
Merge branch 'TheAlgorithms:master' into master
Arunsiva003 Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions scheduling/shortest_deadline_first.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'''
Earliest Deadline First (EDF) Scheduling Algorithm

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

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
'''

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

@Arunsiva003 Arunsiva003 Oct 16, 2023

Choose a reason for hiding this comment

The 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]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: x

Choose a reason for hiding this comment

The 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}")