round robin schedule(循环日程表)
Posted diamondDemand
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了round robin schedule(循环日程表)相关的知识,希望对你有一定的参考价值。
the source of the article:https://github.com/Fibird/Round-robin-schedule
#include <iostream>
#include <math.h>
#define N 3
using namespace std;
int main()
{
int sche = pow(2.0, N); //the number of athlete
int **arr = new int*[sche];
int bw = 1;
for(int i=0; i<sche; i++)
{
arr[i] = new int[sche];
}
int bid; //the id of block
int c_offset, r_offset;
//init line 1 with 1 to 8
for(int i=0; i<sche; i++)
arr[0][i] = i + 1;
for(int j=0; j<N; j++)
{
for(int r=0; r<bw; r++)
{
for(int c=0; c<sche; c++)
{
bid = (c + bw) / bw;
c_offset = pow(-1.0, bid+1) * bw; //move to right or move to left bw location
r_offset = bw;
arr[r + r_offset][c + c_offset] = arr[r][c];
}
}
bw = bw * 2; //every loop the problem will double
}
// outputs the schedule of the round robin
cout << "N/D";
for(int i=1; i<sche; i++)
cout << "\t" << i;
cout << endl;
for(int i=0; i<sche; i++)
{
cout << arr[i][0];
for(int j=1; j<sche; j++)
{
cout << "\t" << arr[i][j];
}
cout << endl;
}
//free memory
for(int i=0; i<sche; i++)
delete arr[i];
delete arr;
return 0;
}
以上是关于round robin schedule(循环日程表)的主要内容,如果未能解决你的问题,请参考以下文章
java 这是一种用Java实现的循环算法。 #round-robin #scheduling #algorithm #java
RR调度(Round-robin scheduling)简单介绍