📄 gf.cpp
字号:
#include "stdafx.h"
#include "Network.h"
//implement the GF functions
/* global variables */
extern NODE_TYPE nodeT[4000];
extern NETWORK_TYPE net;
int bestNeighbor(int from,int dest);
void BuildGF(int root){
int i;
for( i = 0 ; i < net.NUM_NODES;i++){
int next = bestNeighbor(i,root);
if(next != INVALID_ID)
SetNextHop(i, root, next);
else
assert(false);
}
}
int bestNeighbor(int from,int dest) //gfX
{
int i;
bool found = false;
double test = MAXCOST;
int find;
double currenttest;
assert(from < net.NUM_NODES && dest < net.NUM_NODES);
if(from == dest) return from;
for (i=0;i<nodeT[from].neighbornum;i++)
{
if ((unidirectional(from, nodeT[from].neighbor[i])==true))
continue;
if(adistance(nodeT[from].neighbor[i],dest) > adistance(from,dest)) continue;
currenttest = adistance(nodeT[from].neighbor[i],dest);
if (currenttest <test)
{ test = currenttest;
find = nodeT[from].neighbor[i];
found = true;
}
}
if (found == false){
printf("node %d can not do greedy forward\n",from);
find = INVALID_ID;
assert(false);
}
// printf("%d->%d\n",from,find);
return find;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -