Advertisement
szilard-dobai

scheduling algorithm test (WRR)

Nov 15th, 2020
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C Compiler.
  4. Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10.  
  11. #define min(a, b) a <= b ? a : b;
  12.  
  13. int
  14. main() {
  15. int queueLength[5] = {
  16. 1,
  17. 2,
  18. 1,
  19. 0,
  20. 5
  21. };
  22. int radioLinkQuality[5] = {
  23. 3,
  24. 3,
  25. 1,
  26. 2,
  27. 1
  28. }; // wi, configured at init
  29.  
  30. int freeChannels = 10, intendedServedAmount = 0, actualServedAmount =
  31. 0, lastUserServed = 0, emptyQueues = 0;
  32.  
  33. int i = 0, j = 0, n = 5;
  34.  
  35. printf("\n\n");
  36. for (i = 0; i < n; i++)
  37. printf("Weight of %d is %d.\n", i + 1, radioLinkQuality[i]);
  38.  
  39. printf("\n\n");
  40. for (i = lastUserServed; i <= n; i++) {
  41. if (i == n) {
  42. lastUserServed = 0;
  43. i = 0;
  44. }
  45.  
  46. printf("\tQUEUE LENGTH OF %d IS %d (weight=%d, free=%d).\n", i + 1,
  47. queueLength[i], radioLinkQuality[i], freeChannels);
  48. for (j = 0; j < n; j++)
  49. if (queueLength[j] == 0)
  50. emptyQueues++;
  51. if (emptyQueues == n) {
  52. printf("ALL QUEUES ARE EMPTY.\n");
  53. break;
  54. } else {
  55. emptyQueues = 0;
  56. }
  57.  
  58. if (freeChannels == 0) {
  59. break;
  60. } else {
  61. intendedServedAmount = min(radioLinkQuality[i], queueLength[i]);
  62. actualServedAmount = min(intendedServedAmount, freeChannels);
  63.  
  64. if (actualServedAmount > 0) {
  65. // send packets
  66. printf("Served user %d %d channels.\n", i + 1,
  67. actualServedAmount);
  68. freeChannels -= actualServedAmount;
  69. queueLength[i] -= actualServedAmount;
  70. }
  71. }
  72.  
  73. }
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement