| | |
Homework Help!! Priority Queue ??
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
Please help me! Some homework help appreciated here, thanks!
I'm trying to simulate a server (e.g. a cpu) which accepts requests (e.g. processes). All requests (theoretically) come in at the same time. Each request consists of the amount of cpu time it needs in addition to a priority on a scale of 1-5 or 1-10 or something to the like. I need a function which calculates a Priority Rating (PR) as well as a "penalty" which manipulates these two variables. My server's queue is then ordered by the PR to decrease the amount of cpu time while still handling priority. In other words, some form of a penalty must be in place the longer high priority processes have to wait in the queue.
Does anyone have any ideas of some general algorithm I can consider? Or somewhere I could go for some help on this. My entire program is written except for this one function:
I'm trying to simulate a server (e.g. a cpu) which accepts requests (e.g. processes). All requests (theoretically) come in at the same time. Each request consists of the amount of cpu time it needs in addition to a priority on a scale of 1-5 or 1-10 or something to the like. I need a function which calculates a Priority Rating (PR) as well as a "penalty" which manipulates these two variables. My server's queue is then ordered by the PR to decrease the amount of cpu time while still handling priority. In other words, some form of a penalty must be in place the longer high priority processes have to wait in the queue.
Does anyone have any ideas of some general algorithm I can consider? Or somewhere I could go for some help on this. My entire program is written except for this one function:
// THIS IS A DUMMY FUNCTION // AN APPROPRIATE ALGORITHM WILL BE DETERMINED IN THE FUTURE int calc_pr(int cpu_time, int request_priority) { return (cpu_time * request_priority); }
If anyone's curious, here's what my lil fake server does as of now
My goal is to have a more robust way of queueing processes.
My goal is to have a more robust way of queueing processes. •
•
•
•
Originally Posted by cscgal
If anyone's curious, here's what my lil fake server does as of nowMy goal is to have a more robust way of queueing processes.
Are you allowed to use the Standard Template Library or do you need to implement your own heap with heap sort? Do you know how heap sort works?
Because processes are added to the queue in random places, based on their PR, they're stored via a binary tree. One of my original implementations of this is available at http://www.daniweb.com/forums/thread895.html although it's gone through a few lives since then. (BTW thanks for responding to that thread, too, subtronic).
In any case, my binary queue is sorted based on PR. I've already implemented an inorder traversal function which touches each process from lower PR to higher PR. In addition, I'm currently working on something like a "reheapify" function which can be called at any time, and it "fixes" any inconsistencies in the binary tree should the PR of a process be changed.
Basically what I'm looking for is a nice algorithm to calculate PR given cpu_time, request_priority, and wait_time (how long the server must wait in the queue). In other words, should cpu_time be weighted higher than the priority or vice versa?
In any case, my binary queue is sorted based on PR. I've already implemented an inorder traversal function which touches each process from lower PR to higher PR. In addition, I'm currently working on something like a "reheapify" function which can be called at any time, and it "fixes" any inconsistencies in the binary tree should the PR of a process be changed.
Basically what I'm looking for is a nice algorithm to calculate PR given cpu_time, request_priority, and wait_time (how long the server must wait in the queue). In other words, should cpu_time be weighted higher than the priority or vice versa?
•
•
•
•
Originally Posted by cscgal
Basically what I'm looking for is a nice algorithm to calculate PR given cpu_time, request_priority, and wait_time (how long the server must wait in the queue). In other words, should cpu_time be weighted higher than the priority or vice versa?
? I'm assuming your data will look near linear as you won't have negative times or priorities. Last edited by subtronic; Aug 27th, 2003 at 2:51 am.
Subtronic, I really do appreciate all your help. I'm going to read your response and get back to you as soon as I can. Just give me a day or two. Unfortunately I came down with a really, really horrible cold and can't even think about programming right now.
•
•
Join Date: Oct 2003
Posts: 16
Reputation:
Solved Threads: 0
Just out of curiousity what class is this ?
As well as do you have to error check? Like for invalid input such as .3 or A.
You want your scheme to go like
Time <-shorter longer-> 1-10
PR <-BEST WORST-> 1-10
A quick easy way is to add the priority with the time length. You will have values ranging from 2 till 20.
2 would be priority of 1 and time of 1. Which i would assume you would want to be first processed. the last item to be processed would be one that has a pr of 10 and a time of 10. You could also make the value of the priority worth more if you want. I can help with that too. Also are you going to constantly be having values come in? if so i think i have a way to deal with that and make sure that
As well as do you have to error check? Like for invalid input such as .3 or A.
You want your scheme to go like
Time <-shorter longer-> 1-10
PR <-BEST WORST-> 1-10
A quick easy way is to add the priority with the time length. You will have values ranging from 2 till 20.
2 would be priority of 1 and time of 1. Which i would assume you would want to be first processed. the last item to be processed would be one that has a pr of 10 and a time of 10. You could also make the value of the priority worth more if you want. I can help with that too. Also are you going to constantly be having values come in? if so i think i have a way to deal with that and make sure that
"Beware of computer programmers that carry screwdrivers."
Leonard Brandwein.
Leonard Brandwein.
![]() |
Similar Threads
Other Threads in the Computer Science Forum
- Previous Thread: Gaussian elimination with row interchange
- Next Thread: Turing Machines
| Thread Tools | Search this Thread |
ai algorithm algorithms amazon assignment assignmenthelp assignments automata battery bigbrother binary bittorrent bizarre bletchleypark blogging bomb business cern codebreaker compiler computer computers computerscience computertrackingsoftware connect conversion csc dataanalysis dataintepretation development dfa dissertation dissertations dissertationtopic ebook employment energy floatingpoint foreclosure foreclosuresoftware fuel gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea ideas internet iphone ipod jobs laser laws linkbait lsmeans mainframes marketing mobileapplication msaccess nano netbeans networking news os p2p piracy piratebay principles programming rasterizer research sam-being-cute sas science security sex simulation software spying stephenfry study supercomputer supercomputing sweden technology textfield turing turingtest two'scompliment uk virus ww2






