📄 routingcost.cpp
字号:
#include "stdafx.h"
#include "Network.h"
/* global variables */
extern NODE_TYPE nodeT[4000];
extern NETWORK_TYPE net;
//this function is quite simple in that it intuitively gets the cost from end to end
void BuildCost(int dest)
{
int index;
int neighborindex;
for (index = 0; index < net.NUM_NODES; index++)
{
int currentnode;
double accumulatecost;
double accumulatedelay;
accumulatecost = 0;
accumulatedelay = 0;
currentnode = index;
while (currentnode!=dest)
{for (neighborindex = 0; neighborindex < MAX_NUM_NEIGHBORS; neighborindex ++)
if (nodeT[currentnode].rt.routingItem[neighborindex].DenstinationID==dest)
{accumulatecost+=linkCost(currentnode,nodeT[currentnode].rt.routingItem[neighborindex].NextHop, dest);
accumulatedelay+= linkDelay(currentnode, nodeT[currentnode].rt.routingItem[neighborindex].NextHop);
currentnode = nodeT[currentnode].rt.routingItem[neighborindex].NextHop;
break;}
}
for (neighborindex = 0; neighborindex < MAX_NUM_NEIGHBORS; neighborindex ++)
if (nodeT[index].rt.routingItem[neighborindex].DenstinationID==dest)
{ nodeT[index].rt.routingItem[neighborindex].Cost = accumulatecost;
nodeT[index].rt.routingItem[neighborindex].Delay = accumulatedelay;
break;}
}
}
void PrintCost(int dest)
{
int index;
double total ;
int neighborindex;
total = 0;
for (index = 0; index < net.NUM_NODES; index++)
{ for (neighborindex = 0; neighborindex < MAX_NUM_NEIGHBORS; neighborindex ++)
if (nodeT[index].rt.routingItem[neighborindex].DenstinationID==dest)
{ total+= nodeT[index].rt.routingItem[neighborindex].Cost ;
break;}
}
printf("The total is %f\n", total);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -