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

📄 simulation.cpp

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


using namespace std;

void BuildNeighborHood();
void BuildRouting();
void NodeScheduling();
void Traffic();

extern NODE_TYPE nodeT[4000];
extern NETWORK_TYPE net;

int totaldirect, totalinter, totaldistant;


void startSimulation(){


 totaldirect = totalinter = totaldistant = 0;






	{
	
		//node init reads the network information and init nodes

		NodeInit();
		for(int i=0;i<100000000;i++) {};

		//organize the neighborhood information for the purpose of buidling neighborhood links, etc 

     	BuildNeighborHood();
 
		for(int i=0;i<100000;i++) {};
		//The first part of the simulation. This part will build the cost for comparison in terms of genreally routing protocols. Each routing protocol is represented as a case in the setting C.in
        //Pleae refer to the C.in file for the correpsonding simulation setting. The current implementation is quite naive in that all data collection is based on printed out information and post-processing 
		//using Perl scripts and excel plots
		//there is no specific implemenation in the file itself 

		//build routing structure with certain link cost, this should only change the next hop parameter in the fields. 


		BuildRouting();
      
	    //buildcost will form the cost for each node to send to the base sation, which is assumed to be node 0, which is placed at the center of the terrain 
        for(int i=0;i<10000000;i++) {};

		BuildCost(0);	

        //here is a place to put in some statistic collection code for the cost analsyis and printout 
		//these codes have been deleted duirng my earlier simulations 



		//buildclique forms cliques around the nodes 
		for(int i=0;i<100000000;i++) {};

        BuildClique(0);
		for(int i=0;i<100000000;i++) {};
 
	   //debugging
	   // for (int index=0;index<net.NUM_NODES;index++)
       // printf("%d:	%d	%f \n", index, nodeT[index].internum+nodeT[index].distantnum, linkquality2(index, nodeT[index].rt.routingItem[0].NextHop)*linkquality2(nodeT[index].rt.routingItem[0].NextHop, index));

		//calculates the cluster/clique cost. The paper uses cluster to refer to the cliques. 
		//read the paper to know how the code works 
        //there were earlier versions of clique implementaion, but they have been replaced by the current version 


		BuildClusterCost(0);
		for(int i=0;i<100000000;i++) {};



	 for (int index=0;index<net.NUM_NODES;index++)
			printf("%d	%f	%f	%f	%f\n", index, nodeT[index].rt.routingItem[0].Cost,nodeT[index].rt.routingItem[0].Delay,nodeT[index].rt.routingItem[0].CliqueCost,nodeT[index].rt.routingItem[0].CliqueDelay);

//   printf("%d %d %d\n", totaldirect, totalinter, totaldistant);
	}
	
	exit(0);
	
	
	/*following piece of code is leagcy implementation that is based on an earlier impelmentation strategy. 
	{  
		int TotalNumOfNodes = net.NUM_NODES;
		double costvalue[300];
		double delayvalue[300];

		double costvalue2[300];
		double delayvalue2[300];

        
	

		int index;
		int round;
		for (index=0;index<300;index++)
			 costvalue[index] = delayvalue[index] = costvalue2[index] = delayvalue2[index] = 0;
        
        for (round=0;round<100;round++)
		{		
		BuildCliqueCost(0);
		for (index=0;index<TotalNumOfNodes;index++){
		//printf("Node %d has cost %f delay %f VS cost %f delay %f\n", index,nodeT[index].rt.routingItem[0].Cost, nodeT[index].rt.routingItem[0].Delay, nodeT[index].destcost, nodeT[index].destdelay);
          costvalue[index]+=nodeT[index].destcost;
		  delayvalue[index]+=nodeT[index].destdelay;
		}

		BuildCliqueCost2(0);
		for (index=0;index<TotalNumOfNodes;index++){
		//printf("Node %d has cost %f delay %f VS cost %f delay %f\n", index,nodeT[index].rt.routingItem[0].Cost, nodeT[index].rt.routingItem[0].Delay, nodeT[index].destcost, nodeT[index].destdelay);
          costvalue2[index]+=nodeT[index].destcost;
		  delayvalue2[index]+=nodeT[index].destdelay;
		}

		}
     for (index=0;index<300;index++)
	 {costvalue[index] = costvalue[index]/100;
	   delayvalue[index] = delayvalue[index]/100;
       costvalue2[index] = costvalue2[index]/100;
	   delayvalue2[index] = delayvalue2[index]/100;
	 }
	 
	 
	
	}	

*/

}




⌨️ 快捷键说明

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