Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

setdest.cc File Reference

#include <assert.h>
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <err.h>
#include "../../../tools/rng.h"
#include "setdest.h"

Include dependency graph for setdest.cc:

Include dependency graph

Go to the source code of this file.

Defines

#define SANITY_CHECKS
#define GOD_FORMAT   "$ns_ at %.12f \"$god_ set-dist %d %d %d\"\n"
#define GOD_FORMAT2   "$god_ set-dist %d %d %d\n"
#define NODE_FORMAT   "$ns_ at %.12f \"$node_(%d) setdest %.12f %.12f %.12f\"\n"
#define NODE_FORMAT2   "$node_(%d) setdest %.12f %.12f %.12f\n"
#define NODE_FORMAT3   "$node_(%d) set %c_ %.12f\n"
#define INFINITY   0x00ffffff
#define min(x, y)   ((x) < (y) ? (x) : (y))
#define max(x, y)   ((x) > (y) ? (x) : (y))
#define ROUND_ERROR   1e-9
#define M   2147483647L
#define INVERSE_M   ((double)4.656612875e-10)

Functions

void usage (char **)
void init (void)
double uniform (void)
void dumpall (void)
void ComputeW (void)
void floyd_warshall (void)
void show_diffs (void)
void show_routes (void)
void show_counters (void)
int main (int argc, char **argv)

Variables

int count = 0
const double RANGE = 250.0
double TIME = 0.0
double MAXTIME = 0.0
double MAXX = 0.0
double MAXY = 0.0
double MAXSPEED = 0.0
double PAUSE = 0.0
u_int32_t NODES = 0
u_int32_t RouteChangeCount = 0
u_int32_t LinkChangeCount = 0
u_int32_t DestUnreachableCount = 0
NodeNodeList = 0
u_int32_tD1 = 0
u_int32_tD2 = 0
char random_state [32]
RNGrng
char * optarg


Define Documentation

#define GOD_FORMAT   "$ns_ at %.12f \"$god_ set-dist %d %d %d\"\n"
 

Definition at line 27 of file setdest.cc.

#define GOD_FORMAT2   "$god_ set-dist %d %d %d\n"
 

Definition at line 28 of file setdest.cc.

#define INFINITY   0x00ffffff
 

Definition at line 34 of file setdest.cc.

#define INVERSE_M   ((double)4.656612875e-10)
 

Definition at line 82 of file setdest.cc.

#define M   2147483647L
 

Definition at line 81 of file setdest.cc.

#define max x,
 )     ((x) > (y) ? (x) : (y))
 

Definition at line 36 of file setdest.cc.

#define min x,
 )     ((x) < (y) ? (x) : (y))
 

Definition at line 35 of file setdest.cc.

#define NODE_FORMAT   "$ns_ at %.12f \"$node_(%d) setdest %.12f %.12f %.12f\"\n"
 

Definition at line 29 of file setdest.cc.

#define NODE_FORMAT2   "$node_(%d) setdest %.12f %.12f %.12f\n"
 

Definition at line 30 of file setdest.cc.

#define NODE_FORMAT3   "$node_(%d) set %c_ %.12f\n"
 

Definition at line 31 of file setdest.cc.

#define ROUND_ERROR   1e-9
 

Definition at line 37 of file setdest.cc.

#define SANITY_CHECKS
 

Definition at line 23 of file setdest.cc.


Function Documentation

void ComputeW void   ) 
 

void dumpall void   ) 
 

void floyd_warshall void   ) 
 

void init void   ) 
 

int main int  argc,
char **  argv
 

Definition at line 142 of file setdest.cc.

References dumpall(), floyd_warshall(), RNG::HEURISTIC_SEED_SOURCE, init(), MAXSPEED, MAXTIME, MAXX, MAXY, min, NodeList, NODES, optarg, PAUSE, random_state, rng, ROUND_ERROR, RNG::set_seed(), show_counters(), show_diffs(), show_routes(), TIME, Node::time_arrival, Node::time_transition, u_int32_t, uniform(), Node::Update(), Node::UpdateNeighbors(), and usage().

00143 {
00144         char ch;
00145 
00146         while ((ch = getopt(argc, argv, "n:p:s:t:x:y:i:o:")) != EOF) {       
00147 
00148                 switch (ch) { 
00149 
00150                 case 'n':
00151                         NODES = atoi(optarg);
00152                         break;
00153 
00154                 case 'p':
00155                         PAUSE = atof(optarg);
00156                         break;
00157 
00158                 case 's':
00159                         MAXSPEED = atof(optarg);
00160                         break;
00161 
00162                 case 't':
00163                         MAXTIME = atof(optarg);
00164                         break;
00165 
00166                 case 'x':
00167                         MAXX = atof(optarg);
00168                         break;
00169 
00170                 case 'y':
00171                         MAXY = atof(optarg);
00172                         break;
00173 
00174                 default:
00175                         usage(argv);
00176                         exit(1);
00177                 }
00178         }
00179 
00180         if(MAXX == 0.0 || MAXY == 0.0 || NODES == 0 || MAXTIME == 0.0) {
00181                 usage(argv);
00182                 exit(1);
00183         }
00184 
00185         fprintf(stdout, "#\n# nodes: %d, pause: %.2f, max speed: %.2f  max x = %.2f, max y: %.2f\n#\n",
00186                 NODES , PAUSE, MAXSPEED, MAXX, MAXY);
00187 
00188         // The more portable solution for random number generation
00189         rng = new RNG;
00190         rng->set_seed(RNG::HEURISTIC_SEED_SOURCE); 
00191 
00192         init();
00193 
00194         while(TIME <= MAXTIME) {
00195                 double nexttime = 0.0;
00196                 u_int32_t i;
00197 
00198                 for(i = 0; i < NODES; i++) {
00199                         NodeList[i].Update();
00200                 }
00201 
00202                 for(i = 0; i < NODES; i++) {
00203                         NodeList[i].UpdateNeighbors();
00204                 }
00205 
00206                 for(i = 0; i < NODES; i++) {
00207                         Node *n = &NodeList[i];
00208         
00209                         if(n->time_transition > 0.0) {
00210                                 if(nexttime == 0.0)
00211                                         nexttime = n->time_transition;
00212                                 else
00213                                         nexttime = min(nexttime, n->time_transition);
00214                         }
00215 
00216                         if(n->time_arrival > 0.0) {
00217                                 if(nexttime == 0.0)
00218                                         nexttime = n->time_arrival;
00219                                 else
00220                                         nexttime = min(nexttime, n->time_arrival);
00221                         }
00222                 }
00223 
00224                 floyd_warshall();
00225 
00226 #ifdef DEBUG
00227                 show_routes();
00228 #endif
00229 
00230                 show_diffs();
00231 
00232 #ifdef DEBUG
00233                 dumpall();
00234 #endif
00235 
00236                 assert(nexttime > TIME + ROUND_ERROR);
00237                 TIME = nexttime;
00238         }
00239 
00240         show_counters();
00241 
00242         int of;
00243         if ((of = open(".rand_state",O_WRONLY | O_TRUNC | O_CREAT, 0777)) < 0) {
00244           fprintf(stderr, "open rand state\n");
00245           exit(-1);
00246           }
00247         for (unsigned int i = 0; i < sizeof(random_state); i++)
00248           random_state[i] = 0xff & (int) (uniform() * 256);
00249         if (write(of,random_state, sizeof(random_state)) < 0) {
00250           fprintf(stderr, "writing rand state\n");
00251           exit(-1);
00252           }
00253         close(of);
00254 }

Here is the call graph for this function:

void show_counters void   ) 
 

void show_diffs void   ) 
 

void show_routes void   ) 
 

double uniform void   ) 
 

void usage char **   ) 
 


Variable Documentation

int count = 0 [static]
 

Definition at line 39 of file setdest.cc.

u_int32_t* D1 = 0
 

Definition at line 74 of file setdest.cc.

u_int32_t* D2 = 0
 

Definition at line 75 of file setdest.cc.

u_int32_t DestUnreachableCount = 0
 

Definition at line 71 of file setdest.cc.

u_int32_t LinkChangeCount = 0
 

Definition at line 70 of file setdest.cc.

double MAXSPEED = 0.0
 

Definition at line 66 of file setdest.cc.

double MAXTIME = 0.0
 

Definition at line 62 of file setdest.cc.

double MAXX = 0.0
 

Definition at line 64 of file setdest.cc.

double MAXY = 0.0
 

Definition at line 65 of file setdest.cc.

Node* NodeList = 0
 

Definition at line 73 of file setdest.cc.

u_int32_t NODES = 0
 

Definition at line 68 of file setdest.cc.

char* optarg
 

Definition at line 139 of file setdest.cc.

double PAUSE = 0.0
 

Definition at line 67 of file setdest.cc.

char random_state[32]
 

Definition at line 84 of file setdest.cc.

const double RANGE = 250.0
 

Definition at line 60 of file setdest.cc.

RNG* rng
 

Definition at line 85 of file setdest.cc.

u_int32_t RouteChangeCount = 0
 

Definition at line 69 of file setdest.cc.

double TIME = 0.0
 

Definition at line 61 of file setdest.cc.


Generated on Tue Apr 20 12:28:54 2004 for NS2.26SourcesOriginal by doxygen 1.3.3