How to create queue priority
Show older comments
Hi, I'm trying to create a simple code to generate a priority queue for two different customers in MatLab. The customers have different arrival rates but go through the same server.
To create the priority, I initialized a queue of 500 and made the entries zeros. Then using if statements, I said that if there are the priority arrivals that i would create a loop from 1 to priorityarrivals and set the value in the vector equal to zero. If not the new arrival would join the end of the queue.
Then, to simulate Q(1), the next customer in line that would then leave the server, I would set Q(k)=Q(k+1).
For some reason my current code takes so long to run it is not finishing. Is there a more simple way to do this in MatLab? Any suggestions are appreciated.
2 Comments
Geoff Hayes
on 17 May 2017
Payton - you may need to post some of your code so that we can get an idea of what you have written. Else, you can try to use the MATLAB profiling tool, profile, in order to determine where the most time is being spent within your code.
John D'Errico
on 17 May 2017
You've described what you are doing only in very broad terms, and then asked why your code runs so slowly.
Possibly you have a bug in what you wrote. Possibly you have just coded what you did do in some unimaginably convoluted way. (Honest, I've NEVER seen that done on this forum.)
If you want a serious answer to your question, then you need to show your code. If your code is too long and convoluted for someone to read through and understand (perhaps why you have not shown what you did) then you will probably not get an answer. But that just means that you need to learn to debug your code. Use the debugger, with logical breakpoints set, to see if your code is running properly. Test the code on smaller problems, verify that it does indeed run properly. Finally, spend some time, learning MATLAB better, and how to model the system under study. Odds are there are better ways to solve almost any problem. But asking a very general question will not get you much of an intelligent answer.
Answers (0)
Categories
Find more on Marine and Underwater Vehicles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!