📄 rrrxin.cpp
字号:
}
void throughput2()
{
int i,j;
int B1=10,B2=5;
int LAMBDA1,LAMBDA2;
long int LAMBDA,LAMBDA1Remain,LAMBDA2Remain;
struct tongguoliang tongji[maxand]; //,LAMBDA1tongji[maxand],LAMBDA2tongji[maxand]
float tongguotemp;
float result,result1,result2;
float total;
int LAMBDAAll;
float temp;
int maxandtemp;
int LAMBDAnum = 0;
int OldFlag = 0;
float throughput1 = 0;
float throughput2 = 0;
FILE *fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9;
for(i=0;i<maxand;i++)
{
tongji[i].times = 0;
tongji[i].tongguo = 0;
tongji[i].tongguo1 = 0;
tongji[i].tongguo2 = 0;
}
fp1 = fopen("data1.txt","r");
fp2 = fopen("data2.txt","r");
for(i=0;i<cycle;i++)
{
fscanf(fp1,"%d ",&LAMBDA1);
fscanf(fp2,"%d ",&LAMBDA2);
LAMBDA = LAMBDA1 + LAMBDA2;
tongji[LAMBDA].times ++ ;
LAMBDA1Remain = 0;
LAMBDA2Remain = 0;
tongguotemp = 0;
throughput1 = 0;
throughput2 = 0;
fp3 = fopen("gaosi1.txt","r");
for(j=0;j<cycle;j++)
{
LAMBDA1Remain += LAMBDA1;
LAMBDA2Remain += LAMBDA2;
fscanf(fp3,"%d ",&channel);
if(channel % 2 == 0)
{
channel1 = channel / 2;
channel2 = channel / 2;
}
else
{
if(OldFlag == 1)
{
channel1 = channel / 2;
channel2 = channel / 2 + 1;
}
else
{
channel1 = channel / 2 + 1;
channel2 = channel / 2;
}
OldFlag = (OldFlag + 1) % 2;
}
// LAMBDA1 process
if(LAMBDA1Remain <= channel1)
{
tongguotemp += LAMBDA1Remain * B1;
throughput1 += LAMBDA1Remain * B1;
LAMBDA1Remain = 0;
}
else
{
tongguotemp += channel1 * B1;
throughput1 += channel1 * B1;
LAMBDA1Remain = LAMBDA1Remain - channel1;
}
// LAMBDA2 process
if(LAMBDA2Remain <= channel2)
{
tongguotemp += LAMBDA2Remain * B2;
throughput2 += LAMBDA2Remain * B2;
LAMBDA2Remain = 0;
}
else
{
tongguotemp += channel2 * B2;
throughput2 += channel2 * B2;
LAMBDA2Remain = LAMBDA2Remain - channel2;
}
}
tongguotemp = tongguotemp / cycle;
tongji[LAMBDA].tongguo += tongguotemp;
tongguotemp = throughput1/cycle;
tongji[LAMBDA].tongguo1 += tongguotemp;
tongguotemp = throughput2/cycle;
tongji[LAMBDA].tongguo2 += tongguotemp;
fclose(fp3);
if(i%100 == 0)
{
temp = 100*i/((float)cycle);
system("cls");
printf("The 3 part finish %4.2f %% \n",temp);
}
}
fclose(fp1);
fclose(fp2);
fp1 = fopen("result.txt","w+");
fp2 = fopen("number.txt","w+");
fp3 = fopen("tuntu.txt","w+");
fp4 = fopen("result1.txt","w+");
fp5 = fopen("number1.txt","w+");
fp6 = fopen("tuntu1.txt","w+");
fp7 = fopen("result2.txt","w+");
fp8 = fopen("number2.txt","w+");
fp9 = fopen("tuntu2.txt","w+");
for(i=0;i<maxand;i++)
{
if(tongji[i].times !=0)
{
LAMBDAnum ++ ;
result = (float)tongji[i].tongguo / tongji[i].times;
result1 = (float)tongji[i].tongguo1 / tongji[i].times;
result2 = (float)tongji[i].tongguo2 / tongji[i].times;
printf("When LAMBDA = %4d, 总通过量为:%5.3f ; LAMBDA1通过量为: %7.3f .\n",i,result,result1);
printf(" LAMBDA2通过量为: %7.3f .\n",result2);
fprintf(fp1,"%d %f \n",i,result);
fprintf(fp4,"%d %f \n",i,result1);
fprintf(fp7,"%d %f \n",i,result2);
fprintf(fp2,"%d ",i);
fprintf(fp5,"%d ",i);
fprintf(fp8,"%d ",i);
fprintf(fp3,"%f ",result);
fprintf(fp6,"%f ",result1);
fprintf(fp9,"%f ",result2);
}
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
fclose(fp5);
fclose(fp6);
fclose(fp7);
fclose(fp8);
fclose(fp9);
total = 0;
fp1 = fopen("max.txt","w+");
for(i=0;i<LAMBDAnum;i++)
{
LAMBDAAll = 0;
total = 0;
fp3 = fopen("number.txt","r");
fp2 = fopen("gaosi1.txt","r");
fscanf(fp3,"%d ",&maxandtemp);
for(j=0;j<cycle;j++)
{
LAMBDAAll += maxandtemp;
fscanf(fp2,"%d ",&channel);
if(LAMBDAAll <= channel)
{
total = total + LAMBDAAll * B1;
LAMBDAAll = 0;
}
else
{
LAMBDAAll = LAMBDAAll - channel;
total = total + channel * B1;
}
}
fclose(fp2);
fclose(fp3);
fprintf(fp1,"%d %f \n",maxandtemp,(total/cycle));
}
fclose(fp1);
}
void DelayTime2()
{
FILE *fp1,*fp2,*fp3;
double TotalDelayTime = 0.0;
double LAMBDA1TotalDelayTime = 0;
double LAMBDA2TotalDelayTime = 0;
unsigned int TotalLAMBDA = 0;
unsigned int TotalLAMBDA1 = 0;
unsigned int TotalLAMBDA2 = 0;
unsigned int SuccessTotalLAMBDA1 = 0;
unsigned int SuccessTotalLAMBDA2 = 0;
unsigned int TransmitSuccess = 0;
unsigned int TotalChannel = 0,TotalChannel1 = 0,TotalChannel2 = 0;
struct Sdata *pHead,*pTail,*pLAMBDA1,*pLAMBDA2,*ptemp,*pDelete;
int i;
int channel;
int channelRemain =0;
int LAMBDA1= 0 ,LAMBDA2 = 0;
int Readtemp;
double temp;
double AverageDelay;
int OldFlag = 0;
fp1 = fopen("data1.txt","r");
fp2 = fopen("data2.txt","r");
fp3 = fopen("gaosi1.txt","r");
for(i=0;i<cycle;i++)
{
// fscanf(fp3,"%d ",&channel);
ptemp = (struct Sdata *)malloc(sizeof(struct Sdata));
fscanf(fp1,"%d ",&Readtemp);
ptemp->LAMBDA1 = Readtemp;
LAMBDA1 = Readtemp;
TotalLAMBDA1 += Readtemp;
ptemp->delay1 = 0.5;
fscanf(fp2,"%d ",&Readtemp);
ptemp->LAMBDA2 = Readtemp;
LAMBDA2 = Readtemp;
TotalLAMBDA2 += Readtemp;
ptemp->delay2 = 0.5;
ptemp->next = NULL;
TotalLAMBDA = TotalLAMBDA + ptemp->LAMBDA1 + ptemp->LAMBDA2;
if(i == 0)
{
pHead = ptemp;
pTail = ptemp;
pDelete = ptemp;
pLAMBDA1 = ptemp;
pLAMBDA2 = ptemp;
}
else
{
pTail->next = ptemp;
pTail = ptemp;
}
// LAMBDA1 process
channelRemain = channel1;
while(pLAMBDA1 != pTail)
{
if(pLAMBDA1->LAMBDA1 <= channelRemain)
{
channelRemain = channelRemain - pLAMBDA1->LAMBDA1;
TotalDelayTime += pLAMBDA1->LAMBDA1 * pLAMBDA1->delay1;
LAMBDA1TotalDelayTime += pLAMBDA1->LAMBDA1 * pLAMBDA1->delay1;
TransmitSuccess += pLAMBDA1->LAMBDA1;
SuccessTotalLAMBDA1 += pLAMBDA1->LAMBDA1;
pLAMBDA1->LAMBDA1 = 0;
pLAMBDA1 = pLAMBDA1->next;
}
else
{
TotalDelayTime += channelRemain * pLAMBDA1->delay1;
LAMBDA1TotalDelayTime += channelRemain * pLAMBDA1->delay1;
pLAMBDA1->LAMBDA1 = pLAMBDA1->LAMBDA1 - channelRemain;
TransmitSuccess += channelRemain;
SuccessTotalLAMBDA1 += channelRemain;
pLAMBDA1->delay1 = pLAMBDA1->delay1 + 1;
channelRemain = 0;
}
if(channelRemain == 0)
{
break ;
}
}
// LAMBDA2 process
channelRemain = channel2;
while(pLAMBDA2 != pTail)
{
if(pLAMBDA2->LAMBDA2 <= channelRemain)
{
channelRemain = channelRemain - pLAMBDA2->LAMBDA2;
TotalDelayTime += pLAMBDA2->LAMBDA2 * pLAMBDA2->delay2;
LAMBDA2TotalDelayTime += pLAMBDA2->LAMBDA2 * pLAMBDA2->delay2;
TransmitSuccess += pLAMBDA2->LAMBDA2;
SuccessTotalLAMBDA2 += pLAMBDA2->LAMBDA2;
pLAMBDA2->LAMBDA2 = 0;
pLAMBDA2 = pLAMBDA2->next;
}
else
{
TotalDelayTime += channelRemain * pLAMBDA2->delay2;
LAMBDA2TotalDelayTime += channelRemain * pLAMBDA2->delay2;
pLAMBDA2->LAMBDA2 = pLAMBDA2->LAMBDA2 - channelRemain;
TransmitSuccess += channelRemain;
SuccessTotalLAMBDA2 += channelRemain;
pLAMBDA2->delay2 = pLAMBDA2->delay2 + 1;
channelRemain = 0;
}
if(channelRemain == 0)
{
break;
}
}
while (pHead != pTail)
{
if((pHead->LAMBDA1 == 0) && (pHead->LAMBDA2 == 0))
{
pDelete = pHead;
pHead = pHead->next;
free(pDelete);
}
else
{
break;
}
}
fscanf(fp3,"%d ",&channel);
if(channel % 2 == 0)
{
channel1 = channel / 2;
channel2 = channel / 2;
}
else
{
if(OldFlag == 1)
{
channel1 = channel / 2;
channel2 = channel / 2 + 1;
}
else
{
channel1 = channel / 2 + 1;
channel2 = channel / 2;
}
OldFlag = (OldFlag + 1) % 2;
}
TotalChannel += channel;
TotalChannel1 += channel1;
TotalChannel2 += channel2;
// Display
if(i%100 == 0)
{
temp = 100*i/((float)cycle);
system("cls");
printf("The 4 part finish %4.2f %% \n",temp);
}
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
system("cls");
TotalLAMBDA = TotalLAMBDA - LAMBDA1 - LAMBDA2;
AverageDelay = TotalDelayTime / TotalLAMBDA;
printf("Total channel number is %d \n",TotalChannel);
printf("Need to be transmit is %d .\n",TotalLAMBDA);
printf("Suceessful transmit %d . \n",TransmitSuccess);
printf("remain %d can't be transmit!\n",TotalLAMBDA - TransmitSuccess);
printf("Suceess transmit ratio is %4.2f %%\n",100*(float)TransmitSuccess/TotalLAMBDA);
printf("Channel utilize ratio is %4.2f %%\n",100*(float)TransmitSuccess/TotalChannel);
printf("TotalDelayTime = %4.2f.\n",TotalDelayTime);
printf("The Average delay time is %4.2f slot!\n",AverageDelay);
printf("Success transmit average delay time is %4.2f slot.\n",(float)TotalDelayTime/TransmitSuccess);
printf("\nLAMBDA1 Total Delay Time is %4.2f .\n",LAMBDA1TotalDelayTime);
printf("Total LAMBDA1 is %d \n",TotalLAMBDA1);
printf("LAMBDA1 Average delay time is %4.2f slot!\n",(float)LAMBDA1TotalDelayTime/SuccessTotalLAMBDA1);
printf("User1 success transmit ratio is %4.2f %%\n",100*(float)SuccessTotalLAMBDA1/(TotalLAMBDA1 - LAMBDA1));
printf("\nLAMBDA2 Total Delay Time id %4.2f .\n",LAMBDA2TotalDelayTime);
printf("Total LAMBDA2 is %d \n",TotalLAMBDA2);
if(SuccessTotalLAMBDA2 != 0)
{
printf("LAMBDA2 Average delay time is %4.2f slot!\n",(float)LAMBDA2TotalDelayTime/SuccessTotalLAMBDA2);
}
else
{
printf("User2 not data to be transmit\n");
}
printf("User2 success transmit ratio is %4.2f %%\n",100*(float)SuccessTotalLAMBDA2/(TotalLAMBDA2 - LAMBDA2));
fp1 = fopen("AveDelay.txt","w");
fprintf(fp1,"%f ",AverageDelay);
fclose(fp1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -