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

📄 sim_shr.h

📁 无限传感器网络的模拟环境
💻 H
📖 第 1 页 / 共 3 页
字号:
	nodes[i].pm.failureStats( 0.0);		// source & dest don't go down    }  }  else			// failures are transient  {    for( i = 0; i < NumNodes; i++)    {      nodes[i].pm.BeginTime = 0.0;      nodes[i].pm.FinishTime = StopTime();      if( nodes[i].SrcOrDst == false)	nodes[i].pm.failureStats( 5 * Interval + (double) i/NumNodes * ActiveCycle,				  ActiveCycle, ActivePercent);      else	nodes[i].pm.failureStats( 0.0);		// source & dest don't go down    }  }#ifdef	USE_CONFIG_FILE/*** Check the execution time of all of the events in the configuration file.** If an event is scheduled after the end of traffic generation or** after the end of the simulation (StopTime), inform the user*/  bool		status;  int		node;  double	time, finishTime = StopTime() * FinishTimeRatio;  SimEvent	event;  for( status = firstEvent( time, node, event); status == true;       status = nextEvent( time, node, event))  {    if( time > StopTime())    {      printf( "FYI: Event '%s' for node %d is after end of simulation "	      "(%.0f > %.0f)\n", eventToString( event), node, time,StopTime());      continue;    }    if( time > finishTime)    {      printf( "FYI: Event '%s' for node %d is after last packet generation "	      "(%.0f > %.0f)\n", eventToString( event), node, time,finishTime);      continue;    }/*** This is a major kludge, but it's unavoidable with the current state of** compcxx. See my comments after the definition of RoutingSim.** Since it is not possible to pass pointers (or references) to a component,** this method must reexamine the event list looking for when nodes come back** up. When an event is found, schedule that event on the component's timer.*/    if( event == NodeUp)      nodes[ node].net.scheduleHELLO( time);  }#endif	// USE_CONFIG_FILE  return;}/************************************************************************ * @<h2>Running the Simulation</h2>@ * To run the simulation, first we need to create a * simulation object from the simulation component class.  * Several default simulation parameters must be determined.  * @StopTime@ denotes the ending time of the simulation. * @Seed@ is the initial seed of the random number generator used * by the simulation. * * Use the make file to compile and link the program. *  * To run the simulation, simply type in: * * sim_shr <flags>	(This is not complete.) * mwl ************************************************************************/int main(  int		argc,  char		*argv[]){  RoutingSim	sim;  int		seed;  bool		doDecrement, proceed = true;  const char	*UnsupportedOption = "***** Unsupported option %s *****\n";  seed = (int) time( 0);  for( argv++; argc > 1; argc--, argv++)  {    if( *argv[0] != '-')    {      printf( UnsupportedOption, *argv);      proceed = false;      continue;    }    doDecrement = true;    switch( (*argv)[1])    {      case 'A':		// The sum of a node's mean up time and down time	sim.ActiveCycle = atof( argv[1]);	if( sim.ActiveCycle < 0.0)	{	  printf( "***** Warning: Nodes have ActiveCycle < 0.0 *****\n");	  proceed = false;	}	break;      case 'a':		// percent active, cycles node between idle and off, see power.h	sim.ActivePercent = atof( argv[1]);	if( sim.ActivePercent > 1.0)	{	  printf( "***** Warning: Nodes active more than 100%% of the time *****\n");	  proceed = false;	}	if( sim.ActivePercent <= 0.0)	{	  printf( "***** Warning: Nodes never active *****\n");	  proceed = false;	}	break;      case 'b':		// backoff type      {	char	*str = new char[ strlen(argv[1])+1], *p1, *p2;	for( p1 = argv[1], p2 = str; *p1 != 0; p1++, p2++)	  *p2 = tolower( *p1);	*p2 = 0;	if( strcmp( "ssr", str) == 0)	  sim.BackOff = SHRBackOff_SSR;	else if( strcmp( "shr", str) == 0)	  sim.BackOff = SHRBackOff_SHR;	else if( strcmp( "incorrect", str) == 0)	  sim.BackOff = SHRBackOff_Incorrect;	else	{	  printf( UnsupportedOption, argv[1]);	  proceed = false;	}	delete [] str;	break;      }#ifdef	USE_CONFIG_FILE      case 'c':		// enable reading of configuration file (if that makes sense)	configStatus = true;	configFile = argv[1];	doDecrement = true;	break;#endif	// USE_CONFIG_FILE      case 'C':		// continuous vs. slotting	switch( *argv[1])	{	  case 't':	  case 'T':	    sim.ContinuousBackOff = true;	    break;	  case 'f':	  case 'F':	    sim.ContinuousBackOff = false;	    break;	  default:	    printf( UnsupportedOption, argv[1]);	    proceed = false;	    break;	}	break;      case 'd':		// at end of simulation, dump status of nodes	dumpStatus = true;	dumpFile = argv[1];	doDecrement = true;	break;      case 'e':		// simulation end time	sim.StopTime( atof( argv[1]));	break;      case 'i':		// interval	sim.Interval = atof( argv[1]);	break;      case 'l':		// lambda (aka ForwardDelay)	sim.ForwardDelay = atof( argv[1]);	break;#ifndef	USE_CONFIG_FILE      case 'n':		// number of nodes	numNodes = sim.NumNodes = atoi( argv[1]);	break;#endif	// USE_CONFIG_FILE      case 'p':		// antenna transmission power in watts	sim.TXPower = atof( argv[1]);	break;      case 'r':		// random number seed	seed = atoi( argv[1]);	break;      case 'R':		// # packets in route repair	sim.RouteRepair = atoi( argv[1]);	if( sim.RouteRepair < 0)	{	  printf( "***** Route repair must be >= 0\n");	  proceed = false;	}	break;      case 's':		// number of sources	sim.NumSourceNodes = atoi( argv[1]);	break;      case 'S':		// traffic pattern: 	switch( *argv[1])	{	  case 't':	// many sources to single destination	  case 'T':	    sim.OneSink = true;	    break;	  case 'f':	// many (source, destination) pairs (parallel streams)	  case 'F':	    sim.OneSink = false;	    break;	  default:	    printf( UnsupportedOption, argv[1]);	    proceed = false;	    break;	}	break;      case 't':		// transition timer	sim.TransitionTime = atof( argv[1]);	break;      case 'u':		// unidirectional traffic	switch( *argv[1])	{	  case 't':	// all traffic from sources to destination(s)	  case 'T':	    sim.UnidirectionalTraffic = true;	    break;	  case 'f':	// traffic in both directions	  case 'F':	    sim.UnidirectionalTraffic = false;	    break;	  default:	    printf( UnsupportedOption, argv[1]);	    proceed = false;	    break;	}	break;      case 'v':		// enable visualizer	Visualizer::instantiate( argv[1]);	break;      case 'w':		// slot width	sim.SlotWidth = atof( argv[1]);	break;      case 'x':		// x (and y) dimension	sim.MaxX = sim.MaxY = atof( argv[1]);	break;      case 'z':		// clear stats counters	sim.ClearStatsTime( atof( argv[ 1]));	break;      default:	doDecrement = false;	proceed = false;	printf( UnsupportedOption, *argv);	break;    }    if( doDecrement == true)    {      argv++;      argc--;    }  }  if( proceed == false)    return 1;#ifdef	USE_CONFIG_FILE  if( configFile == NULL)  {    printf( "***** A configuration file is required\n");    assert( 0);  }  parseConfigInfo( configFile);  numNodes = sim.NumNodes = getNumNodes();#endif	// USE_CONFIG_FILE  if( sim.NumSourceNodes == 0)    sim.NumSourceNodes = sim.NumNodes / 10;  if( sim.NumSourceNodes <= 0)  {    printf( "***** Warning: no source nodes\n");    return 1;  }  if( sim.NumSourceNodes * (sim.UnidirectionalTraffic == true ? 1 : 2) >= sim.NumNodes)  {    printf( "***** Warning: more source nodes than actual nodes\n");    return 1;  }  sim.Seed = seed;/*** Display parameters that define the simulation.*/  printf( "SSR/SHR:\t\t");#ifdef	SHR_ACK  printf( "SHR_ACK defined\n");#else	//SHR_ACK  printf( "SHR_ACK not defined\n");#endif	//SHR_ACK  printf( "Channel model:\t\t%s\n", ChannelModel);#ifdef	USE_CONFIG_FILE  if( configStatus == true)    printf( "Configuration file:\t%s\n", configFile);  else    printf( "Configuration file not used\n");#endif	// USE_CONFIG_FILE  printf( "Random number seed:\t%d\nStopTime:\t\t%.0f\n"	  "Clear Stats Time:\t%.0f\nNumber of Nodes:\t%d\n"	  "Active Cycle:\t\t%5.2f\n"	  "Percent Active:\t\t%5.2f\nTerrain:\t\t%.0f by %.0f\n"	  "Number of Sources:\t%d\nPacket Size:\t\t%d\n"	  "Interval:\t\t%f\nAntenna Power:\t\t%f\nSingle sink:\t\t%s\n"	  "Unidirectional Traffic:\t%s\nLambda:\t\t\t%f\nRoute Repair:\t\t",	  seed,	  sim.StopTime(), sim.ClearStatsTime(), sim.NumNodes, sim.ActiveCycle,	  sim.ActivePercent * 100.0, sim.MaxX, sim.MaxY, sim.NumSourceNodes,	  sim.PacketSize, sim.Interval, sim.TXPower,	  sim.OneSink == true ? "True" : "False",	  sim.UnidirectionalTraffic == true ? "True" : "False", sim.ForwardDelay);  if( sim.RouteRepair == 0)    printf( "none");  else    printf( "%d packet%c", sim.RouteRepair, sim.RouteRepair == 1 ? ' ' : 's');  printf( "\nBackoff Type:\t\t");  switch( sim.BackOff)  {    case SHRBackOff_SSR:      printf( "SSR formula\n");      break;    case SHRBackOff_SHR:      printf( "SHR formula\n");      break;    case SHRBackOff_Incorrect:      printf( "formula as published (incorrect)\n");      break;    default:      printf( "unknown\n");      break;  }  printf( "Continuous:\t\t");  if( sim.ContinuousBackOff == false)    printf( "false\nSlot Width:\t\t%f\nTransition Time:\t%f\n",	    sim.SlotWidth, sim.TransitionTime);  else    printf( "true\n");  sim.Setup();#ifdef	USE_CONFIG_FILE  dumpConnections( sim.MaxX, sim.MaxY);#endif	// USE_CONFIG_FILE  sim.Run();  return 0;}void addToNeighborMatrix(  int		src,  int		dest){  if( dumpStatus == true)    neighborMatrix[ src * numNodes + dest] = true;  return;}

⌨️ 快捷键说明

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