How to create queue priority
이전 댓글 표시
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
Geoff Hayes
2017년 5월 17일
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
2017년 5월 17일
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.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Marine and Underwater Vehicles에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!