-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Job sequencing with deadlines #6854
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
Merged
cclauss
merged 18 commits into
TheAlgorithms:master
from
lakshayroop5:Job_Sequencing_with_Deadlines
Oct 9, 2022
Merged
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e22c1c5
completed optimised code for job sequencing with deadline problem
lavenroop5 d7cb01f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 388b978
completed optimised code for job sequencing with deadline problem
lavenroop5 f707dc2
completed optimized code for job sequencing with deadline problem
lakshayroop5 de476be
completed optimised code for job sequencing with deadline problem
lavenroop5 1545f2e
completed optimised code for job sequencing with deadline problem
lavenroop5 017b3af
completed optimised code for job sequencing with deadline problem
lavenroop5 51dcd9d
completed optimised code for job sequencing with deadline problem
lavenroop5 02b0e81
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 166dce9
completed optimized code for the issue "Job Scheduling with deadlines"
lakshayroop5 e49c8e1
completed optimized code for the issue "Job Scheduling with deadlines"
lakshayroop5 487829d
completed optimized code for the issue "Job Scheduling with deadlines"
lakshayroop5 3785de3
Update greedy_methods/job_sequencing_with_deadline.py
lakshayroop5 10e7276
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 500231b
Updated reviews
lakshayroop5 a0b4d52
Updated reviews
lakshayroop5 c577d7e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0eff505
Update and rename greedy_methods/job_sequencing_with_deadline.py to s…
cclauss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
This is a pure Python implementation of the greedy-merge-sort algorithm | ||
|
||
For doctests run following command: | ||
python3 -m doctest -v greedy_merge_sort.py | ||
""" | ||
|
||
|
||
# FUNCTION | ||
def job_sequencing_with_deadlines(num_jobs: int, jobs: list) -> list: | ||
""" | ||
Function to find the maximum profit by doing jobs in a given time frame | ||
|
||
Args: | ||
num_jobs [int]: Number of jobs | ||
jobs [list]: A list of tuples of (job_id, deadline, profit) | ||
|
||
Returns: | ||
max_profit [int]: Maximum profit that can be earned by doing jobs | ||
in a given time frame | ||
|
||
Examples: | ||
>>> job_sequencing_with_deadlines(4, [(1, 4, 20), (2, 1, 10), \ | ||
(3, 1, 40), (4, 1, 30)]) | ||
[2, 60] | ||
>>> job_sequencing_with_deadlines(5, [(1, 2, 100), (2, 1, 19), \ | ||
(3, 2, 27), (4, 1, 25), (5, 1, 15)]) | ||
[2, 127] | ||
""" | ||
|
||
# Sort the jobs in descending order of profit | ||
jobs = sorted(jobs, key=lambda value: value[2], reverse=True) | ||
|
||
# Create a list of size equal to the maximum deadline | ||
# and initialize it with -1 | ||
max_deadline = max(jobs, key=lambda value: value[1])[1] | ||
time_slots = [-1] * max_deadline | ||
|
||
# Finding the maximum profit and the count of jobs | ||
count = 0 | ||
max_profit = 0 | ||
for job in jobs: | ||
# Find a free time slot for this job | ||
# (Note that we start from the last possible slot) | ||
for i in range(job[1] - 1, -1, -1): | ||
if time_slots[i] == -1: | ||
time_slots[i] = job[0] | ||
count += 1 | ||
max_profit += job[2] | ||
break | ||
return [count, max_profit] | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.