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

Implemented a new code for Priority Scheduling #2278

Open
wants to merge 12 commits into
base: master
from

Conversation

@Lownish
Copy link

Lownish commented Aug 4, 2020

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
@TravisBuddy
Copy link

TravisBuddy commented Aug 4, 2020

Hey @Lownish,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 6f17e4d0-d6ab-11ea-8693-3322afd57804
@TravisBuddy
Copy link

TravisBuddy commented Aug 4, 2020

Hey @Lownish,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: c54a6ed0-d6ac-11ea-8693-3322afd57804
@Lownish Lownish requested a review from cclauss Aug 5, 2020
Refactor
@Lownish Thanks for this submission!

I do not know scheduling and I am struggling to understand this algorithm.  Sometimes it goes in an infinite loop and other times it delivers all zeros.

Can you please provide a set of input data and expected output data?

I created a separate `priority_schedule()` function with a doctest that never seems to calculate a schedule.  Can you please fix that function so that it provides the correct schedule for that input data?
@TravisBuddy
Copy link

TravisBuddy commented Aug 5, 2020

Hey @Lownish,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 90fd1860-d721-11ea-85fc-4b61cecd2c91
@Lownish
Copy link
Author

Lownish commented Aug 5, 2020

@cclauss , Priority Scheduling is a scheduling algorithm which decides which process to execute, given the priority of each process in the queue. Whenever there are processes of the same priority, it follows FCFS. The code prints the sequence of the processes to be run, as well as its waiting time and turn around time. The greater the priority number, the higher priority the process has. Priority ranges from 1 onwards.

This algorithm is usually covered as part of the Operating System component. You can find more details on the link below:
https://www.javatpoint.com/os-preemptive-priority-scheduling

The link above is of a set of data, but the priority must be incremented by 1, since it should be from 1 onwards.

Output must be:
Process_no Trun_Around_Time Wating_Time
1 3 0
2 8 2
4 9 7
3 9 8
5 12 8

@TravisBuddy
Copy link

TravisBuddy commented Aug 5, 2020

Hey @Lownish,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: bb783300-d725-11ea-85fc-4b61cecd2c91
@TravisBuddy
Copy link

TravisBuddy commented Aug 5, 2020

Travis tests have failed

Hey @Lownish,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: cf3a2ec0-d725-11ea-85fc-4b61cecd2c91
@TravisBuddy
Copy link

TravisBuddy commented Aug 5, 2020

Travis tests have failed

Hey @Lownish,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 7592de70-d726-11ea-85fc-4b61cecd2c91
@cclauss
Copy link
Member

cclauss commented Aug 5, 2020

Priority schedule for processes:
Enter number of processes: 5
Enter Name of process 0: P1
Enter Arrival time: 0
Enter Burst time: 11
Enter Priority: 2
Enter Name of process 1: P2
Enter Arrival time: 5
Enter Burst time: 28
Enter Priority: 0
Enter Name of process 2: P3
Enter Arrival time: 12
Enter Burst time: 2
Enter Priority: 3
Enter Name of process 3: P4
Enter Arrival time: 2
Enter Burst time: 10
Enter Priority: 1
Enter Name of process 4: P5
Enter Arrival time: 9
Enter Burst time: 16
Enter Priority: 4
Process(name='P1', arrival_time=0, burst_time=11, priority=2)
Process(name='P2', arrival_time=5, burst_time=28, priority=0)
Process(name='P3', arrival_time=12, burst_time=2, priority=3)
Process(name='P4', arrival_time=2, burst_time=10, priority=1)
Process(name='P5', arrival_time=9, burst_time=16, priority=4)

Priority schedule:
Process Name	Waiting Time	 Turn Around Time
P1		0		11
P5		2		18
P3		15		17
P4		27		37
P2		34		62
Copy link
Member

cclauss left a comment

Needs work.

@Lownish
Copy link
Author

Lownish commented Aug 5, 2020

Priority schedule for processes:
Enter number of processes: 5
Enter Name of process 0: P1
Enter Arrival time: 0
Enter Burst time: 11
Enter Priority: 2
Enter Name of process 1: P2
Enter Arrival time: 5
Enter Burst time: 28
Enter Priority: 0
Enter Name of process 2: P3
Enter Arrival time: 12
Enter Burst time: 2
Enter Priority: 3
Enter Name of process 3: P4
Enter Arrival time: 2
Enter Burst time: 10
Enter Priority: 1
Enter Name of process 4: P5
Enter Arrival time: 9
Enter Burst time: 16
Enter Priority: 4
Process(name='P1', arrival_time=0, burst_time=11, priority=2)
Process(name='P2', arrival_time=5, burst_time=28, priority=0)
Process(name='P3', arrival_time=12, burst_time=2, priority=3)
Process(name='P4', arrival_time=2, burst_time=10, priority=1)
Process(name='P5', arrival_time=9, burst_time=16, priority=4)

Priority schedule:
Process Name	Waiting Time	 Turn Around Time
P1		0		11
P5		2		18
P3		15		17
P4		27		37
P2		34		62

The priority is starting with 0. It should start with 1. This will require incrementing all priorities by 1

@cclauss
Copy link
Member

cclauss commented Aug 5, 2020

The doctest increments all priorities by one and still fails. Please ensure the doctest passes.

@cclauss
Copy link
Member

cclauss commented Aug 5, 2020

If priority is [0, 1, 2, 3, 4] or [1, 2, 3, 4, 5] should not change the outcome of the schedule.

@TravisBuddy
Copy link

TravisBuddy commented Aug 5, 2020

Travis tests have failed

Hey @Lownish,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 4eca5cd0-d728-11ea-85fc-4b61cecd2c91
@TravisBuddy
Copy link

TravisBuddy commented Aug 5, 2020

Travis tests have failed

Hey @Lownish,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 083abe80-d729-11ea-85fc-4b61cecd2c91
@Lownish
Copy link
Author

Lownish commented Aug 5, 2020

It seems there is some error in the logic when the arrival time for all processes are not 0. Looking into it

@thunderstorm2kN
Copy link

thunderstorm2kN commented Aug 5, 2020

@Lownish
Copy link
Author

Lownish commented Aug 5, 2020

Screenshot 2020-08-05 21 02 48

We were working with the wrong data. This one should be doing good.
Sequence will be as follows: P1, P3, P6, P4, P2, P5, P7


The data above is for processes with arrival time 0 for all

Processes Burst time Waiting time Turn around time
1 10 0 10
3 8 10 18
2 5 18 23

@cclauss
Copy link
Member

cclauss commented Aug 5, 2020

The waiting time for process 7 is wrong but the rest is correct. Where did that chart come from?

Process(name='1', arrival_time=0, burst_time=3, priority=2)
Process(name='2', arrival_time=2, burst_time=5, priority=3)
Process(name='3', arrival_time=1, burst_time=4, priority=6)
Process(name='4', arrival_time=4, burst_time=2, priority=4)
Process(name='5', arrival_time=6, burst_time=9, priority=2)
Process(name='6', arrival_time=5, burst_time=4, priority=5)
Process(name='7', arrival_time=7, burst_time=10, priority=1)

Priority schedule:
Process Name	Waiting Time	 Turn Around Time
1		0		3
3		2		6
6		2		6
4		7		9
2		11		16
5		12		21
7		20		30
@Lownish
Copy link
Author

Lownish commented Aug 5, 2020

The waiting time for process 7 is wrong but the rest is correct. Where did that chart come from?

Process(name='1', arrival_time=0, burst_time=3, priority=2)
Process(name='2', arrival_time=2, burst_time=5, priority=3)
Process(name='3', arrival_time=1, burst_time=4, priority=6)
Process(name='4', arrival_time=4, burst_time=2, priority=4)
Process(name='5', arrival_time=6, burst_time=9, priority=2)
Process(name='6', arrival_time=5, burst_time=4, priority=5)
Process(name='7', arrival_time=7, burst_time=10, priority=1)

Priority schedule:
Process Name	Waiting Time	 Turn Around Time
1		0		3
3		2		6
6		2		6
4		7		9
2		11		16
5		12		21
7		20		30

https://www.javatpoint.com/os-non-preemptive-priority-scheduling

The chart uses a reverse logic where lowest priority number means highest priority. I made the change while running it.
Regarding to the Waiting Time value,
Waiting Time = Turn Around Time - Burst Time
The value in the chart is wrong. If you do the calculation using the equation above, you will get 20

@Lownish Lownish requested a review from cclauss Aug 7, 2020
@Lownish
Copy link
Author

Lownish commented Aug 13, 2020

@cclauss , are there any modifications required to have the pull request merged? Have not received any other reviews for almost a week now.

@cclauss
Copy link
Member

cclauss commented Aug 13, 2020

A single source for both the code and the expected results is not making me comfortable because I do not know scheduling so I am not a strong reviewer of this submission. Perhaps a different reviewer would be more comfortable with this work.

For me, there needs to be a published source on scheduling algoritms that agrees with your results. If your results do not match any published resource then perhaps we should close this PR.

@Lownish
Copy link
Author

Lownish commented Aug 13, 2020

Meanwhile, I'll search for some legitimate sources for such problems along with the results.

@Lownish
Copy link
Author

Lownish commented Aug 13, 2020

http://www.uobabylon.edu.iq/download/M.S%202013-2014/Operating_System_Concepts,_8th_Edition%5BA4%5D.pdf

This book explains about different process scheduling algorithms. Chapter 5, on page 192, covers the priority scheduling algorithm covered here, with arrival time 0 for all processes.

The book also mentioned that there is no actual agreement whether the lowest number represents the highest or the lowest priority, but it chose it to be, the lower the number, the higher the priority in this case, contrary to the program submitted here,

@Lownish
Copy link
Author

Lownish commented Aug 15, 2020

@itsvinayak , can you please review the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.