Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C Compiler.
- Code, Compile, Run and Debug C program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <stdio.h>
- #define min(a, b) a <= b ? a : b;
- int
- main() {
- int queueLength[5] = {
- 1,
- 2,
- 1,
- 0,
- 5
- };
- int radioLinkQuality[5] = {
- 3,
- 3,
- 1,
- 2,
- 1
- }; // wi, configured at init
- int freeChannels = 10, intendedServedAmount = 0, actualServedAmount =
- 0, lastUserServed = 0, emptyQueues = 0;
- int i = 0, j = 0, n = 5;
- printf("\n\n");
- for (i = 0; i < n; i++)
- printf("Weight of %d is %d.\n", i + 1, radioLinkQuality[i]);
- printf("\n\n");
- for (i = lastUserServed; i <= n; i++) {
- if (i == n) {
- lastUserServed = 0;
- i = 0;
- }
- printf("\tQUEUE LENGTH OF %d IS %d (weight=%d, free=%d).\n", i + 1,
- queueLength[i], radioLinkQuality[i], freeChannels);
- for (j = 0; j < n; j++)
- if (queueLength[j] == 0)
- emptyQueues++;
- if (emptyQueues == n) {
- printf("ALL QUEUES ARE EMPTY.\n");
- break;
- } else {
- emptyQueues = 0;
- }
- if (freeChannels == 0) {
- break;
- } else {
- intendedServedAmount = min(radioLinkQuality[i], queueLength[i]);
- actualServedAmount = min(intendedServedAmount, freeChannels);
- if (actualServedAmount > 0) {
- // send packets
- printf("Served user %d %d channels.\n", i + 1,
- actualServedAmount);
- freeChannels -= actualServedAmount;
- queueLength[i] -= actualServedAmount;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement