⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mh.cpp

📁 传感器网络的可靠路由算法
💻 CPP
字号:
#include "stdafx.h"
#include "Network.h"

/* global variables */
extern NODE_TYPE nodeT[4000];
extern NETWORK_TYPE net;

void BuildMH(int root){

int top,i;
queue <int> flood;


SetE2ECost(root, root, 0,root);
nodeT[root].floodsend =1;
flood.push(root);

while (!flood.empty()){

	top = flood.front();

	nodeT[top].inqueue = 0;
	flood.pop();

	for (i=0;i<nodeT[top].neighbornum;i++) 
	  { 
		  //get-rid of asymetric links
		if (unidirectional(top, nodeT[top].neighbor[i])==true){
			//printf("No connection between %d and  %d\n",top,nodeT[top].neighbor[i] );
			continue;
        }
		
		if (nodeT[nodeT[top].neighbor[i]].floodsend == 0){
			  
			 /* nodeT[top] send out control message and its neighbors receive it */
			 flood.push(nodeT[top].neighbor[i]);
			 nodeT[nodeT[top].neighbor[i]].inqueue = 1;
         					   
			 
			 SetNextHop(nodeT[top].neighbor[i], root, top);
			 nodeT[nodeT[top].neighbor[i]].floodsend =1;
		  }

	}
}
assert(flood.empty());

}


void BuildMH_A(int root){

int top,i;
queue <int> flood;


SetE2ECost(root, root, 0,root);
nodeT[root].floodsend =1;
flood.push(root);

while (!flood.empty()){

	top = flood.front();

	nodeT[top].inqueue = 0;
	flood.pop();

	for (i=0;i<nodeT[top].neighbornum;i++) 
	  { 
		  //get-rid of asymmetric links
		if (unidirectional(top, nodeT[top].neighbor[i])==true){
			//printf("No connection between %d and  %d\n",top,nodeT[top].neighbor[i] );
			continue;
        }
		
		if (nodeT[nodeT[top].neighbor[i]].floodsend == 0){
			  
			 /* nodeT[top] send out control message and its neighbors receive it */
			 flood.push(nodeT[top].neighbor[i]);
			 nodeT[nodeT[top].neighbor[i]].inqueue = 1;
         					   
			 double cost = GetE2ECost(top,root) + linkCost(nodeT[top].neighbor[i],top,root); 			 
			 SetE2ECost(nodeT[top].neighbor[i], root, cost,top);
			 nodeT[nodeT[top].neighbor[i]].floodsend =1;
		  }else{
			  
			  if(GetE2ECost(nodeT[top].neighbor[i],root) > GetE2ECost(top,root) + linkCost(nodeT[top].neighbor[i],top,root)){
         		 double cost = GetE2ECost(top,root)+ linkCost(nodeT[top].neighbor[i],top,root);         
				 SetE2ECost(nodeT[top].neighbor[i], root, cost,top);		 		 
			
				 if (nodeT[nodeT[top].neighbor[i]].inqueue==0){
					flood.push(nodeT[top].neighbor[i]);
					nodeT[nodeT[top].neighbor[i]].inqueue=1;
				 }   
			  }
		  }//else

	}
}
assert(flood.empty());

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -