homeMovGen-rel1.0.cc File Reference

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <string.h>
#include <fstream>
#include <istream>
#include <iostream>
#include <cstdlib>
#include <ios>
#include "socialNet.h"
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_multifit_nlin.h>

Defines

#define RAND_INT(l, h)   (((double)(random() * ((double)(h)-(l)+1.0))) + (l))

Functions

double getRandomDouble ()
void setSeed (unsigned int init)
double generateRandomDouble (double min, double max)
int generateRandomInteger (int min, int max)
void header ()
void usage ()
void generateXMLHeader (FILE *outputFileXML, double sideLength_WholeAreaX, double sideLength_WholeAreaY, double transmissionRange, int numberOfNodes)
void generateXMLSetNodePosition (FILE *outputFileXML, int node, double x, double y, double sideLength_WholeAreaX, double sideLength_WholeAreaY)
void generateXMLSetNewGoal (FILE *outputFileXML, int node, double time, double newGoalX, double newGoalY, double velocity, double sideLength_WholeAreaX, double sideLength_WholeAreaY)
int main (int argc, char *argv[])

Define Documentation

#define RAND_INT ( l,
 )     (((double)(random() * ((double)(h)-(l)+1.0))) + (l))

Function Documentation

double generateRandomDouble ( double  min,
double  max 
)

00104                                                      {
00105         //double number=getRandomDouble() * (max-min+1.0) + min;
00106         double number=getRandomDouble()*(max-min)+min;  
00107         
00108         //double number=min+((max-min)*getRandomDouble()/RAND_MAX);
00109         return number;
00110 }

int generateRandomInteger ( int  min,
int  max 
)

00113                                             {
00114         
00115         int number=(int)floor(generateRandomDouble((double)min,(double)max)+1);
00116         //printf("%s %d\n","The random generated integer number is",number);
00117 
00118         return number;
00119 }

void generateXMLHeader ( FILE *  outputFileXML,
double  sideLength_WholeAreaX,
double  sideLength_WholeAreaY,
double  transmissionRange,
int  numberOfNodes 
)

00167                                                                                                                                                      {
00168         
00169         fprintf(outputFileXML,"<?xml version=\"1.0\"?>\n");
00170         fprintf(outputFileXML,"<simulation xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
00171         fprintf(outputFileXML,"xsi:noNamespaceSchemaLocation=\"http://www.i-u.de/schools/hellbrueck/ansim/xml/simulation.xsd\">\n");
00172         fprintf(outputFileXML,"\t<parameter>\n");
00173         fprintf(outputFileXML,"\t\t<area_shape>rectangle</area_shape>\n");
00174         fprintf(outputFileXML,"\t\t<xsize>%f</xsize>\n",sideLength_WholeAreaX);
00175         fprintf(outputFileXML,"\t\t<ysize>%f</ysize>\n",sideLength_WholeAreaY);
00176         fprintf(outputFileXML,"\t\t<extension_factor>1</extension_factor>\n");
00177         fprintf(outputFileXML,"\t\t<numberOfNodes>%d</numberOfNodes>\n",numberOfNodes);
00178         fprintf(outputFileXML,"\t\t<range>%f</range>\n",transmissionRange);
00179         fprintf(outputFileXML,"\t\t<mobility_model>socialFoundedMM</mobility_model>\n");
00180         fprintf(outputFileXML,"\t</parameter>\n");
00181                         
00182 }

void generateXMLSetNewGoal ( FILE *  outputFileXML,
int  node,
double  time,
double  newGoalX,
double  newGoalY,
double  velocity,
double  sideLength_WholeAreaX,
double  sideLength_WholeAreaY 
)

00198                                                                                                                                                                                       {
00199         fprintf(outputFileXML,"\t\t<position_change>\n");
00200         fprintf(outputFileXML,"\t\t\t<node_id>%d</node_id>\n",node);
00201         fprintf(outputFileXML,"\t\t\t<start_time>%f</start_time>\n",time);
00202         fprintf(outputFileXML,"\t\t\t<destination>\n");
00203         fprintf(outputFileXML,"\t\t\t\t<xpos>%f</xpos>\n",newGoalX-sideLength_WholeAreaX/2.0);
00204         fprintf(outputFileXML,"\t\t\t\t<ypos>%f</ypos>\n",newGoalY-sideLength_WholeAreaY/2.0);
00205         fprintf(outputFileXML,"\t\t\t</destination>\n");
00206         fprintf(outputFileXML,"\t\t\t<velocity>%f</velocity>\n",velocity);
00207         fprintf(outputFileXML,"\t\t</position_change>\n");
00208 }

void generateXMLSetNodePosition ( FILE *  outputFileXML,
int  node,
double  x,
double  y,
double  sideLength_WholeAreaX,
double  sideLength_WholeAreaY 
)

00186                                                                                                                                               {
00187         fprintf(outputFileXML,"\t\t<node>\n");
00188         fprintf(outputFileXML,"\t\t\t<node_id>%d</node_id>\n",node);
00189         fprintf(outputFileXML,"\t\t\t<position>\n");
00190         fprintf(outputFileXML,"\t\t\t\t<xpos>%f</xpos>\n",x-sideLength_WholeAreaX/2.0);
00191         fprintf(outputFileXML,"\t\t\t\t<ypos>%f</ypos>\n",y-sideLength_WholeAreaY/2.0);
00192         fprintf(outputFileXML,"\t\t\t</position>\n");
00193         fprintf(outputFileXML,"\t\t</node>\n");
00194 }

double getRandomDouble (  ) 

00078                           {
00079 
00080 /* input parameters*/
00081 
00082 /* static int a = 1588635695, m = 4294967291U, q = 2, r = 1117695901; */
00083 
00084 static unsigned int a = 1223106847, m = 4294967291U, q = 3, r = 625646750;
00085 
00086 /* static unsigned int a = 279470273, m = 4294967291U, q = 15, r = 102913196;*/
00087 /* static unsigned int a = 1583458089, m = 2147483647, q = 1, r = 564025558; */
00088 /* static unsigned int a = 784588716, m = 2147483647, q = 2, r = 578306215;  */
00089 /* static unsigned int a = 16807, m = 2147483647, q = 127773, r = 2836;      */
00090 /* static unsigned int a = 950706376, m = 2147483647, q = 2, r = 246070895;  */
00091 
00092    SEED = a*(SEED % q) - r*(SEED / q);
00093    return ((double)SEED / (double)m);
00094 }

void header (  ) 

00123               {
00124     printf("%s","\nMobility Patterns Generator for OMNET++ simulator\n");
00125     printf("%s","Home Cell Community Based Mobility Model\n");
00126     printf("%s","Based on the Community Based Mobility Model of Mirco Musolesi\n");
00127     printf("%s","Version 1.2 January 2012\n");
00128     printf("%s","Copyright (C) Nikolaos Vastardis University of Essex\n");
00129     printf("%s","              nvasta@essex.ac.uk\n");
00130 }

int main ( int  argc,
char *  argv[] 
)

00211                                   {
00212 
00213         //----------------------------
00214         //Definitions of the constants
00215         //----------------------------
00216 
00217         //number of hosts
00218         int numHosts=100;
00219 
00220         //connection threshold
00221         double connectionThreshold=0.1;
00222 
00223         //length of the sides of the area
00224         double sideLength_WholeAreaX=2000.0;
00225         double sideLength_WholeAreaY=2000.0;
00226 
00227         //radius of the transmission area
00228         double radius=200.0;
00229 
00230         //number of rows
00231         int numberOfRows=20;
00232 
00233         //number of columns
00234         int numberOfColumns=20;
00235         
00236         //simulationTime
00237         double totalSimulationTime=1000.0;
00238 
00239         //refreshTime
00240         double stepInterval=1.0;
00241 
00242         //low bound speed of the host
00243         double minHostSpeed=1.0;
00244         double maxHostSpeed=10.00;
00245 
00246         //reconfiguration interval
00247         //it defines the interval between two reconfigurations
00248         double reconfigurationInterval=10000.0;
00249 
00250         //rewiring probability
00251         double rewiringProb=0.1;
00252         
00253         //numberOfGroups
00254         int numberOfGroups=10;
00255 
00256         //simulation time
00257         double simTime=0.0;
00258         
00259         //number of travellers
00260         int numberOfTravellers=0;
00261 
00262         //speed of the travellers
00263         double travellerSpeed=20.0;
00264     
00265         //verbose on/off
00266         bool verbose=false;
00267         
00268         //generateXML on/off
00269     bool generateXML=false;
00270     string xmlFile="socMov.xml";
00271         
00272         //girvan Newman clustering algorithm on off
00273         bool girvanNewmanOn=true;
00274         
00275         //colocation traces on/off
00276         bool colocationTracesOn=false;
00277         
00278         //communities traces on/off
00279         bool communitiesTracesOn=false;
00280         
00281         //deterministic on/off
00282         bool deterministicOn=true;
00283         
00284         //drift
00285         float drift;
00286         
00287         //debug variables
00288         bool firstTime=true;
00289         double timeFirstReconfiguration;
00290         
00291         //adjacency matric input
00292         bool read_adjacency=false;
00293         string inputFile;
00294 
00295         //adjacency matric output
00296         bool output_adjacency=false;
00297 
00298         //double pause time MAX
00299         int pauseMAX=0;
00300                                                         
00301         //***********************/
00302         // Retrieving input values
00303         // **********************/
00304 
00305         char ch;
00306         int inputSeed;  
00307                 
00308         while ((ch = getopt (argc, argv, "hx:n:s:S:p:l:d:X:Y:c:C:R:G:r:T:t:w:v:g:a:d:A:b:i:P:o:"))!=EOF)
00309                 
00310                  switch(ch) {
00311                          case 'h':
00312                                                 //shows helps
00313                                                 header();
00314                                                 usage();
00315                                                 exit(1);
00316                          case 'x':
00317                         //generate XML file using ANSim format
00318                         generateXML=true;
00319                         //If there is file name following
00320                         if(optarg[0]!='-') {
00321                             xmlFile.assign(optarg);
00322                             xmlFile.append(".xml");
00323                         }
00324                         else
00325                             --optind;
00326                         break;
00327                          case 'n':
00328                                                 //sets the number of hosts
00329                                                 numHosts=atoi(optarg);
00330                                                 break;
00331                          case 's':
00332                                                 //sets lower bound of the speed of the hosts
00333                                                 minHostSpeed=(double)atof(optarg);
00334                                                 break;
00335                          case 'S':                                                                               
00336                                                 //sets upper bound of the speed of the hosts
00337                                                 maxHostSpeed=(double)atof(optarg);
00338                                                 break;
00339                          case 'p':
00340                                                 //sets the connection threshold
00341                                                 connectionThreshold=(double)atof(optarg);
00342                                                 break;
00343                          case 'X':
00344                                                 //sets the side length of the whole area (x coordinates)
00345                                                 sideLength_WholeAreaX=(double)atof(optarg);
00346                                                 break;
00347                          case 'Y':
00348                                                 //sets the side length of the whole area (y coordinates)
00349                                                 sideLength_WholeAreaY=(double)atof(optarg);
00350                                                 break;
00351                          case 'R':
00352                                                 //sets the number of rows
00353                                                 numberOfRows=atoi(optarg);
00354                                                 break;
00355                          case 'C':
00356                                                 //sets the number of columns
00357                                     numberOfColumns=atoi(optarg);
00358                                                 break;  
00359                          case 'T':
00360                                                 //sets the transmission range (radius)
00361                                                 radius=(double)atof(optarg);                    
00362                                                 break;
00363                          case 't':
00364                                                 //sets total simulation time
00365                                                 totalSimulationTime=(double)atof(optarg);
00366                                                 break;
00367                          case 'r':
00368                                                 //sets the reconfiguration interval
00369                                                 reconfigurationInterval=(double)atof(optarg);
00370                                                 break;  
00371                          case 'w':      
00372                                                 //sets the rewiring probability
00373                                                 rewiringProb=(double)atof(optarg);
00374                                                 break;
00375                          case 'G':   
00376                                                 //sets the number of groups of the social network
00377                                                 numberOfGroups=atoi(optarg);
00378                                                 break;
00379                          case 'g':
00380                                                 //sets the seed of the random number generator
00381                                                 inputSeed=atoi(optarg);
00382                                                 setSeed(inputSeed);
00383                                                 break;
00384                          case 'c':      
00385                                                 //sets the number of carriers/travellers
00386                                                 numberOfTravellers=atoi(optarg);
00387                                                 break;
00388                          case 'v':  
00389                                                 //sets the speed of the travellers
00390                                                 travellerSpeed=(double)atof(optarg);
00391                                                 break;
00392                          case 'a': 
00393                                                 //sets the Girvan/Newman algorithm on/off
00394                                                 if (strcmp(optarg,"on")==0)
00395                                                         girvanNewmanOn=true;
00396                                                 else
00397                                                         girvanNewmanOn=false;
00398                                                 break;  
00399                          case 'A':  
00400                                                 //sets colocation traces on/off
00401                                                 if (strcmp(optarg,"on")==0)
00402                                                         colocationTracesOn=true;
00403                                                 else
00404                                                         colocationTracesOn=false;
00405                                                 break;
00406                          case 'b': 
00407                                                 //sets communities on/off
00408                                                 if (strcmp(optarg,"on")==0)
00409                                                         communitiesTracesOn=true;
00410                                                 else
00411                                                         communitiesTracesOn=false;
00412                                                 break;
00413                      case 'd':
00414                                                 //sets deterministic on/off
00415                                                 if (strcmp(optarg,"on")==0)
00416                                                         deterministicOn=true;
00417                                                 else
00418                                                         deterministicOn=false;
00419                                                 break;
00420                          case 'i':              
00421                                                 //sets adjecency input on/off
00422                                                 read_adjacency=true;
00423                                                 inputFile.assign(optarg);
00424                                                 break;
00425                          case 'o':
00426                                                 //output the adjacency matrix in the given text file
00427                                                 if (strcmp(optarg,"on")==0)
00428                                                         output_adjacency=true;
00429                                                 break;
00430                          case 'P':
00431                                                 pauseMAX=atoi(optarg);
00432                                                 break;
00433              case '?':
00434                                             //Invalid option
00435                                 cerr << "Invalid option will be discarted!" << endl;
00436                                 break;
00437                          case ':':   
00438                         //fprintf(stderr,"Option -%c requires an operand\n", optopt);
00439                                                 usage();
00440                         exit(1);                        
00441                          default: 
00442                                                 break;
00443                 }
00444         int commute=0;
00445         int setgoal=0;
00446         bool isConnected[numHosts][numHosts];
00447 
00448         struct hostsItem{
00449                 double currentX;
00450                 double currentY;
00451                 double relativeX;
00452                 double relativeY;
00453                 double goalRelativeX;
00454                 double goalRelativeY;
00455                 double goalCurrentX;
00456                 double goalCurrentY;
00457                 int cellIdX;
00458                 int cellIdY;
00459                 int initialCellIdX;
00460                 int initialCellIdY;
00461                 double speed;
00462                 double absSpeed;
00463                 double af;
00464                 bool isATraveller;
00465                 int **numberOfFriends;
00466                 double pausetime;
00467         };
00468 
00469         hostsItem hosts[numHosts];
00470 
00471         struct cellsItem{
00472                 double minX;
00473                 double minY;
00474                 int numberOfHosts;
00475         };
00476         
00477         cellsItem cells[numberOfRows][numberOfColumns];
00478 
00479         double sideLengthX;
00480         double sideLengthY;
00481 
00482         //cell attractivity
00483         float CA[numberOfRows][numberOfColumns];
00484 
00485         //Variables used for the generation of the mobility scenario using the results of complex networks theory and in particular the Girvan-Newman algorithm
00486 
00487         //interaction->adjacency threshold
00488         double threshold=connectionThreshold;
00489 
00490         int numberOfMembers[numHosts];
00491         int optNumberOfMembers[numHosts];
00492         int **adjacency;
00493         int **tempadjacency;
00494         double **interaction;
00495         int **groups;
00496         int **optGroups;
00497         
00498         // **********************************/
00499         //           Sanity Checks
00500         // **********************************/
00501         // Chech the number of hosts
00502         if(numHosts<numberOfGroups){
00503                 cerr << "ERROR: The number of Groups was set higher than the number of Hosts! Exiting..." << endl;
00504                 exit(-1);
00505         }
00506         // **********************************/
00507 
00508         //output streamle.c_str(),"wt"))==NULL)
00509     fprintf(stderr,"Cannot open %s\n",xmlFile.c_str());
00510         std::ofstream out1; 
00511 
00512         //input fileName
00513         char resultsFileName[]="results.txt";   
00514         
00515         //double last values registered
00516         double lastValues[numHosts][numHosts];
00517         
00518         //array [hostId,communitiesId]
00519         int communities[numHosts][2];
00520         
00521         //probability of moving to the cell [c][r]
00522         float a[numberOfRows][numberOfColumns];
00523         
00524         struct probRange {
00525                 float min;
00526                 float max;
00527         };
00528         
00529         probRange p[numberOfRows][numberOfColumns];
00530         
00531         //probability space distribution in the range [0..1]
00532 
00533         // **********************************/
00534         // Initialisation of the output files   
00535         // **********************************/
00536 
00537         //Creation of the output file XML
00538         FILE* outputFileXML;
00539         generateXML=true;
00540         if (generateXML==true)
00541         if ((outputFileXML=fopen(xmlFile.c_str(),"wt"))==NULL)
00542             fprintf(stderr,"Cannot open %s\n",xmlFile.c_str());
00543         
00544         
00545         //Creation of the colocation statistics files
00546         FILE* outputColocFiles[numHosts];
00547         if (colocationTracesOn==true)
00548                 for (int i=0;i<numHosts;i++) {
00549                         static char fileName[10];
00550                         static char prefix[]=".idat";
00551                         sprintf(fileName,"%d%s",i,prefix);
00552             if ((outputColocFiles[i]=fopen(fileName,"wt"))==NULL)
00553                                 fprintf(stderr,"Cannot open %s\n",fileName);
00554                 }//end for
00555         
00556         //Creation of the communities statistics files
00557         FILE* outputCommunitiesFile;
00558         FILE* outputAdjacency;
00559 
00560         //Erasing file output adjacency file
00561         system("echo > adjacency.idat");
00562                 
00563         // ***************************/
00564         // Initialisation of the model
00565         //****************************/
00566         sideLengthX=sideLength_WholeAreaX/((double)numberOfRows);
00567         sideLengthY=sideLength_WholeAreaY/((double)numberOfColumns);
00568                 
00569         for (int i=0;i<numberOfRows;i++)
00570                 for (int j=0;j<numberOfColumns;j++) {
00571                         cells[i][j].minX=((double)i)*sideLengthX;
00572                         cells[i][j].minY=((double)j)*sideLengthY;       
00573                         cells[i][j].numberOfHosts=0;
00574                 }       
00575 
00576         //setup of the links
00577         for (int i=0;i<numHosts;i++) {
00578 
00579                 for (int l=0;l<numHosts;l++) {
00580                         isConnected[i][l]=false;
00581                         lastValues[i][l]=0.0;
00582                         //nodeModule1->setIsInReach(l,false);
00583                 }
00584         }
00585         
00586         //initialization of the travellers
00587         for (int i=0; i<numberOfTravellers; i++) {
00588                 
00589                 hosts[i].isATraveller=true;
00590                 //definition of the initial speeds of the travellers    
00591                 hosts[i].speed=travellerSpeed;
00592                 
00593         }
00594         
00595         for (int i=numberOfTravellers; i<numHosts; i++) {
00596         
00597                 hosts[i].isATraveller=false;
00598                 hosts[i].speed=generateRandomDouble(minHostSpeed,maxHostSpeed);
00599         
00600         }
00601 
00602         double numberOfReconfigurations=0.0;
00603         double nextReconfigurationTime=0.0;
00604         
00605         
00606         int initialNumberOfGroups=numberOfGroups;
00607         //Update of the positions
00608 
00609         adjacency=initialise_int_array(numHosts);
00610         interaction=initialise_double_array(numHosts);
00611         groups=initialise_int_array(numHosts);
00612         optGroups=initialise_int_array(numHosts);
00613         int optNumberOfGroups=0;
00614         double node_betw[numHosts];
00615         double** betw=initialise_double_array(numHosts);
00616 
00617         //Initialize the number of friends for each host
00618         for (int k=0;k<numHosts;k++) {
00619                 hosts[k].numberOfFriends=initialise_int_square_array(numberOfColumns, numberOfRows);
00620         }
00621 
00622         for (simTime=0.0; simTime<totalSimulationTime;simTime=simTime+stepInterval) {
00623 
00624                 //reconfiguration mechanism
00625                 if (simTime==nextReconfigurationTime) {
00626                         for (int i=0;i<numberOfRows;i++) {
00627                                 for (int j=0;j<numberOfColumns;j++) {
00628         
00629                                         cells[i][j].numberOfHosts=0;
00630 
00631                                         //Initialize the number of friend in each square for every host
00632                                         for (int k=0;k<numHosts;k++)
00633                                                 hosts[k].numberOfFriends[i][j]=0;
00634                                 }       
00635                         }
00636 
00637                         //start correction
00638                         adjacency=initialise_int_array(numHosts);
00639                         tempadjacency=initialise_int_array(numHosts);
00640                 interaction=initialise_double_array(numHosts);
00641                         
00642                         //print_double_array(interaction,numHosts);
00643 
00644                 groups=initialise_int_array(numHosts);
00645                 optGroups=initialise_int_array(numHosts);
00646                 optNumberOfGroups=0;
00647                         //end correction
00648                         
00649                         numberOfReconfigurations=numberOfReconfigurations+1.0;
00650                         nextReconfigurationTime=reconfigurationInterval*numberOfReconfigurations;
00651 
00652                         bool splitted=true;
00653                         double previousModth=0.0;
00654                         double modth=0.0;
00655                         double optModth=0.0;
00656                         if (girvanNewmanOn==true) {     
00657 
00658                                 if(read_adjacency==false) {
00659                                         initialise_weight_array_ingroups(interaction,numHosts,initialNumberOfGroups,rewiringProb,threshold,generateRandomDouble(0,inputSeed));
00660                                         generate_adjacency(interaction,adjacency,threshold,numHosts);
00661                                 }
00662                                 else {
00663                                         if(!readAdjacency(inputFile, interaction,adjacency,numHosts,threshold))
00664                                                 exit(-1);
00665                                 }
00666                                 
00667                                 //Creating a temporal copy of the adjacency matrix
00668                                 for (int i=0;i<numHosts; i++) {
00669                                         for (int j=0;j<numHosts; j++) {
00670                                                 tempadjacency[i][j]=adjacency[i][j];
00671                                         }
00672                                 }
00673                                 
00674                                 //clustering using the Girvan-Newman algorithm
00675                                 do {
00676                                         //Initialize numberOfMembers matrix
00677                                         for (int i=0;i<numHosts; i++)
00678                                                 numberOfMembers[i]=0;
00679 
00680                                         for (int i=0;i<numHosts; i++) {
00681                                                 for (int j=0;j<numHosts;j++) {
00682                                                         betw[i][j]=0;
00683                                                 }
00684                                         }
00685                                         //Calculating the edge betweenness of the current graph
00686                                         calculate_edge_betweenness(betw,tempadjacency,numHosts);
00687 
00688                                         //Find the initial number of Groups
00689                                         numberOfGroups=getGroups(tempadjacency, groups ,numberOfMembers,numHosts);
00690 
00691                                         //Save the previous modularity for the comparison
00692                                         previousModth=modth;
00693 
00694                                         //Split the network according to the modularity
00695                                         modth=splitNetwork_edge_Threshold(adjacency, tempadjacency, betw, numHosts, modth);
00696 
00697                                         //Check for the optimum solution
00698                                         if(optModth<modth || optNumberOfGroups==0) {
00699                                                 optModth=modth;
00700 
00701                                                 //Reinitialize numberOfMembers matrix
00702                                                 for (int i=0;i<numHosts; i++)
00703                                                         numberOfMembers[i]=0;
00704 
00705                                                 //Find the number of Groups after the split
00706                                                 optNumberOfGroups=getGroups(tempadjacency, groups ,numberOfMembers,numHosts);
00707 
00708                                                 //Copy groups matrix
00709                                                 for(int m=0;m<numHosts;m++) {
00710                                                         optNumberOfMembers[m]=numberOfMembers[m];
00711                                                         for(int n=0;n<numHosts;n++)
00712                                                                 if (m<optNumberOfGroups && n<optNumberOfMembers[m]){
00713                                                                         optGroups[m][n]=groups[m][n];
00714                                                                 }
00715                                                 }
00716                                         }
00717 
00718                                         //Print results is asked
00719                                         if (verbose==true && modth!=-1) {
00720                                                 //Reinitialize numberOfMembers matrix
00721                                                 for (int i=0;i<numHosts; i++)
00722                                                         numberOfMembers[i]=0;
00723 
00724                                                 //Find the number of Groups after the split
00725                                                 numberOfGroups=getGroups(tempadjacency, groups ,numberOfMembers,numHosts);
00726                                                 cout<<"\nModth is equal to "<<modth<<endl;
00727                                                 printGroups(numberOfGroups, groups, numberOfMembers, numHosts);
00728                                         }
00729                                 }
00730                                 while ( (previousModth<=2*modth) && (modth>-1) );
00731                                 
00732                                 //Printing results
00733                                 cout<<endl<<"---------Communities Detected---------"<<endl;
00734                                 cout << "Optimal Modularity: " << optModth << endl;
00735                                 cout << "Optimal number of groups: " << optNumberOfGroups << endl;
00736                                 printGroups(optNumberOfGroups, optGroups, optNumberOfMembers, numHosts);
00737                                 cout<<"--------------------------------------"<<endl;
00738                                 
00739                                 //Copy results in the used variables
00740                                 //Find the number of Groups after the split
00741                                 numberOfGroups=optNumberOfGroups;
00742 
00743                                 //Copy groups matrix
00744                                 for(int m=0;m<numHosts;m++) {
00745                                         numberOfMembers[m]=optNumberOfMembers[m];
00746                                         for(int n=0;n<numHosts;n++)
00747                                                 if (m<optNumberOfGroups && n<optNumberOfMembers[m]){
00748                                                         groups[m][n]=optGroups[m][n];
00749                                                 }
00750                                 }
00751 
00752                         }//end if (girvanNewmanOn==true)
00753                         else if(girvanNewmanOn==false) {
00754                                 //communities based on the initial number of caves in the Caveman model         
00755                                 //i.e., w=0
00756                                 if(read_adjacency==true) {
00757                                         cout << endl << "!!!!!!!!!Adjacency input file given but Girvan Newman algorithm is turned off!!!!!!!!!" << endl;
00758                                         cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Creating random network...!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl << endl;
00759                                         sleep(2);
00760                                 }
00761 
00762                                 initialise_weight_array_ingroups(interaction,numHosts,initialNumberOfGroups,0,threshold,inputSeed);
00763                                 generate_adjacency(interaction,adjacency,threshold,numHosts);
00764 
00765                                 for (int i=0;i<numHosts; i++)
00766                                         numberOfMembers[i]=0;
00767                                 numberOfGroups=getGroups(adjacency, groups ,numberOfMembers,numHosts);
00768                                 if (verbose==true)
00769                                         printGroups(numberOfGroups, groups, numberOfMembers, numHosts);
00770                                 
00771                                 initialise_weight_array_ingroups(interaction,numHosts,initialNumberOfGroups,rewiringProb,threshold,inputSeed);
00772                                 generate_adjacency(interaction,adjacency,threshold,numHosts);
00773                                 //print_double_array(interaction, numHosts);
00774                                 
00775                         }//end else
00776                         
00777                         //Calculate node betweenness
00778                         calculate_node_betweenness(node_betw, adjacency, numHosts);
00779                         calculate_edge_betweenness(betw,adjacency,numHosts);
00780 
00781                         //Choose initial cells for the hosts, randomly for each community
00782                         int pointer=0; 
00783                         for (int i=0;i<numberOfGroups;i++) {
00784 
00785                                 int cellIdX=generateRandomInteger(0,numberOfRows);
00786                                 int cellIdY=generateRandomInteger(0,numberOfColumns);
00787 
00788                                 //Check this cell hasn't been used before
00789                                 for (int k=0;k<pointer;k++) {
00790                                         if(hosts[communities[k][0]].cellIdX==cellIdX && hosts[communities[k][0]].cellIdY==cellIdY) {
00791                                                 cellIdX=generateRandomInteger(0,numberOfRows);
00792                                                 cellIdY=generateRandomInteger(0,numberOfColumns);
00793                                                 k=0;
00794                                         }
00795                                 }
00796 
00797                                 for (int j=0;j<numberOfMembers[i];j++) {
00798                                         int hostId=groups[i][j];
00799                                         hosts[hostId-1].cellIdX=cellIdX;
00800                                         hosts[hostId-1].cellIdY=cellIdY;
00801                                         hosts[hostId-1].initialCellIdX=cellIdX;
00802                                         hosts[hostId-1].initialCellIdY=cellIdY;
00803 
00804                                         communities[pointer][0]=hostId;
00805                                         communities[pointer][1]=i+1;
00806                                         pointer++;
00807                                         
00808                                         //increment the number of the hosts in that cell
00809                                         cells[cellIdX-1][cellIdY-1].numberOfHosts+=1;
00810                                 }
00811                         }
00812 
00813                         //Output the adjacency file
00814                         if (output_adjacency==true) {
00815                                 //Opening and writing into file
00816                                 if ((outputAdjacency=fopen("adjacency.idat","a+"))==NULL)
00817                                         fprintf(stderr,"Cannot open adjacency.idat\n");
00818 
00819                                 for (int i=0;i<numHosts;i++) {
00820                                         for (int j=0;j<numHosts;j++) {
00821                                                 fprintf(outputAdjacency, "%d ", adjacency[i][j]);
00822                                         }//end for (int j=0
00823                                         fprintf(outputAdjacency,"\n");
00824                                 }// end for (int i=0
00825                                 fprintf(outputAdjacency,"\n");
00826                                 fclose(outputAdjacency);
00827 
00828                         }//end communitiesTracesOn
00829 
00830                         //Set initial number of friends in each square for every host and initialize pause time to -1 (invalid)
00831                         for (int i=0;i<numHosts;i++) {
00832                                 //Also initialize pause time
00833                                 hosts[i].pausetime=-1;
00834 
00835                                 for (int j=0;j<numHosts;j++) {
00836                                         //If the two nodes are friends
00837                                         if(adjacency[i][j]==1 && i!=j) {
00838                                                 //Increase the number of friends in the specific square of the grid
00839                                                 hosts[i].numberOfFriends[hosts[j].cellIdX-1][hosts[j].cellIdY-1]++;
00840                                         }
00841                                 }
00842                         }
00843 
00844                         if (communitiesTracesOn==true) {
00845                                 if ((outputCommunitiesFile=fopen("communities.idat","wt"))==NULL)
00846                                         fprintf(stderr,"Cannot open communities.idat\n");
00847                                 
00848                                 int temp1=0;
00849                                 int temp2=0;
00850                                 for (int i=0;i<numHosts;i++) {
00851                                         for (int j=0;j<numHosts-1;j++) {
00852                                                 
00853                                                 if (communities[j][0]>communities[j+1][0]) {
00854                                                         temp1=communities[j+1][0];
00855                                                         temp2=communities[j+1][1];
00856                                                         
00857                                                         communities[j+1][0]=communities[j][0];
00858                                                         communities[j+1][1]=communities[j][1];
00859                                                         
00860                                                         communities[j][0]=temp1;
00861                                                         communities[j][1]=temp2;
00862                                                 }
00863                                         }//end for (int j=0
00864                                 }// end for (int i=0
00865                                 
00866                                 for (int i=0;i<numHosts;i++) {
00867                                         fprintf(outputCommunitiesFile, "%d%s", communities[i][0]," ");
00868                                         fprintf(outputCommunitiesFile, "%d%s", communities[i][1],"\n");
00869                         
00870                                 }
00871 
00872                                 fclose(outputCommunitiesFile);                  
00873                         
00874                         }//end communitiesTracesOn
00875 
00876                         if (firstTime==true) {
00877                                 //definition of the initial position of the hosts
00878                                 for (int k=0;k<numHosts;k++) {                  
00879                                         hosts[k].currentX=cells[hosts[k].cellIdX-1][hosts[k].cellIdY-1].minX+generateRandomDouble(0.0,sideLengthX);     
00880                                         hosts[k].currentY=cells[hosts[k].cellIdX-1][hosts[k].cellIdY-1].minY+generateRandomDouble(0.0,sideLengthY);
00881                                 }
00882                                         
00883                                 timeFirstReconfiguration=simTime;
00884                                 firstTime=false;
00885         
00886                                 // ************************
00887                                 // Generation of the traces
00888                                 // ************************
00889         
00890                                 printf("%s","#Mobility Patterns Generator for OMNET++ simulator\n");
00891                                 printf("%s","#Based on the Enhanced Home Community Based Mobility Model\n");
00892                                 printf("%s","#Copyright (C) Nikolaos Vastardis, University of Essex\n");
00893                                 printf("%s","#              nvasta@essex.ac.uk\n");
00894                                 printf("%s","#Version 1.0 May 2011\n");
00895 
00896                                 printf("%s","set god_ [God instance]\n");
00897         
00898                                 //Generating initial positions of the hosts
00899                                 for (int i=0;i<numHosts;i++) {
00900                                         
00901                                         printf("%s%d%s%f%s","$node_(",i,") set X_ ",hosts[i].currentX,"\n");    
00902                                         printf("%s%d%s%f%s","$node_(",i,") set Y_ ",hosts[i].currentY,"\n");    
00903                                         printf("%s%d%s%f%s","$node_(",i,") set Z_ ",0.0,"\n");
00904                                                           
00905                                 }
00906         
00907                                 //Generating initial positions of the hosts - XML code  
00908                                 if (generateXML==true) {
00909                 
00910                                         generateXMLHeader(outputFileXML, sideLength_WholeAreaX, sideLength_WholeAreaY, radius, numHosts);
00911                                         fprintf(outputFileXML,"\t<node_settings>\n");
00912                 
00913                                         for (int i=0;i<numHosts;i++) {
00914                                                 generateXMLSetNodePosition(outputFileXML, i, hosts[i].currentX, hosts[i].currentY,sideLength_WholeAreaX,sideLength_WholeAreaY);
00915                                         }
00916         
00917                                         fprintf(outputFileXML,"\t</node_settings>\n");
00918                                         fprintf(outputFileXML,"\t<mobility>\n");
00919         
00920                                 }//end generation XML code
00921                         }//end if (firstTime==true)
00922                         
00923                         //definition of the initial goals
00924                         for (int k=0;k<numHosts;k++) {
00925                                 hosts[k].goalCurrentX=cells[hosts[k].cellIdX-1][hosts[k].cellIdY-1].minX+generateRandomDouble(0.0,sideLengthX);
00926                                 hosts[k].goalCurrentY=cells[hosts[k].cellIdX-1][hosts[k].cellIdY-1].minY+generateRandomDouble(0.0,sideLengthY);                         
00927                         }       
00928                 
00929                 
00930                         //generation of the traces - setting of the goals
00931                         for (int i=0;i<numHosts;i++) {
00932                                 
00933                                 hosts[i].absSpeed=hosts[i].speed;
00934 
00935                                 //printf("%s %f %s%d%s %f %f %f%s","$ns_ at",simTime,"\"$node_(",i,") setdest",hosts[i].goalCurrentX,hosts[i].goalCurrentY,(hosts[i].absSpeed)/stepInterval,"\"\n");
00936                         
00937                          if (generateXML==true) 
00938                                         generateXMLSetNewGoal(outputFileXML,i,simTime,hosts[i].goalCurrentX,hosts[i].goalCurrentY,hosts[i].absSpeed/stepInterval,sideLength_WholeAreaX,sideLength_WholeAreaY);
00939                         } //end for (int i=0;i<numHosts;i++)
00940                 }//end reconfiguration mechanism
00941                 
00942                 // !!!!!!!!!!!!!!!!!!                                     !!!!!!!!!!!!!!!!!!  
00943                 // !!!!!!!!!!!!!!!!!! No specific speed for x and y axis  !!!!!!!!!!!!!!!!!!
00944                 // !!!!!!!!!!!!!!!!!!                                     !!!!!!!!!!!!!!!!!!
00945                 
00946                 
00947                 for (int i=0;i<numHosts;i++) {
00948 
00949                                 if((hosts[i].currentX>hosts[i].goalCurrentX+hosts[i].speed)||
00950                                    (hosts[i].currentX<hosts[i].goalCurrentX-hosts[i].speed)||
00951                                    (hosts[i].currentY>hosts[i].goalCurrentY+hosts[i].speed)||
00952                                    (hosts[i].currentY<hosts[i].goalCurrentY-hosts[i].speed)) {
00953                                                 //move towards the goal                                 
00954                                                 if (hosts[i].currentX<(hosts[i].goalCurrentX-hosts[i].speed))
00955                                                         hosts[i].currentX=hosts[i].currentX+hosts[i].speed;
00956                                                 if (hosts[i].currentX>(hosts[i].goalCurrentX+hosts[i].speed))
00957                                                         hosts[i].currentX=(hosts[i].currentX)-hosts[i].speed;
00958                                                 if (hosts[i].currentY<(hosts[i].goalCurrentY-hosts[i].speed))
00959                                                         hosts[i].currentY=(hosts[i].currentY)+hosts[i].speed;
00960                                                 if (hosts[i].currentY>(hosts[i].goalCurrentY+hosts[i].speed))
00961                                                         hosts[i].currentY=(hosts[i].currentY)-hosts[i].speed; 
00962                                 }
00963                                 //If node just finished a movement in his home square, pause for some seconds
00964                                 else if(pauseMAX>0 && hosts[i].pausetime==-1 /*&& hosts[i].cellIdX==hosts[i].initialCellIdX && hosts[i].cellIdY==hosts[i].initialCellIdY*/) {
00965                                         hosts[i].pausetime=simTime+generateRandomInteger(0,pauseMAX);
00966                                         hosts[i].absSpeed=0;
00967 
00968                                         //Print the info for the pausing node
00969                                         //printf("%s %f %s%d%s %f %f %f%s","$ns_ at",simTime,"\"$node_(",i,") setdest",hosts[i].goalCurrentX,hosts[i].goalCurrentY,(hosts[i].absSpeed)/stepInterval,"\"\n");
00970                                         if (generateXML==true)
00971                                                 generateXMLSetNewGoal(outputFileXML,i,simTime,hosts[i].goalCurrentX,hosts[i].goalCurrentY,hosts[i].absSpeed/stepInterval,sideLength_WholeAreaX,sideLength_WholeAreaY);
00972                                 }
00973                                 else if(hosts[i].pausetime<=simTime){
00974                                         hosts[i].pausetime=-1;
00975                                         int selectedGoalCellX=0;
00976                                         int selectedGoalCellY=0;        
00977                                         int previousGoalCellX=hosts[i].cellIdX;
00978                                         int previousGoalCellY=hosts[i].cellIdY;
00979                                         
00980                                         if (deterministicOn==true) {
00981 
00982                                                 //Algorithm of the selection of the new cell
00983                                                 for (int c=0;c<numberOfRows;c++)
00984                                                         for (int r=0;r<numberOfColumns;r++)
00985                                                                 CA[c][r]=0;
00986 
00987                                                 //find current node's community
00988                                                 int comId=-1;
00989                                                 for(int c=0;c<numHosts;c++){
00990                                                         if(communities[c][0]==i+1)
00991                                                                 comId=communities[c][1];
00992                                                 }
00993 
00994                                                 //Add interaction of each node to the present while the initial cell exerts attraction with all the initial nodes
00995                                                 for (int n=0;n<numHosts;n++) {
00996                                                         //For all nodes but the present one
00997                                                         if (n!=i) {
00998                                                                 //Check the communities of all nodes
00999                                                                 for(int c=0;c<numHosts;c++) {
01000                                                                         if(communities[c][0]-1==n) {
01001                                                                                 //If the checked node belongs to the same community as the currently choosing target add their
01002                                                                                 //interaction to the initial square of the current node
01003                                                                                 if (communities[c][1]==comId)
01004                                                                                         CA[hosts[n].initialCellIdX-1][hosts[n].initialCellIdY-1]+=interaction[i][n];
01005                                                                                 //Else add it to the square it currently resides
01006                                                                                 else
01007                                                                                         CA[hosts[n].cellIdX-1][hosts[n].cellIdY-1]+=interaction[i][n];
01008                                                                         }
01009                                                                 }
01010                                                         }
01011                                                 }
01012 
01013                                                 for (int c=0;c<numberOfRows;c++) {
01014                                                         for (int r=0;r<numberOfColumns;r++) {
01015                                                                 if (cells[c][r].numberOfHosts!=0) {
01016                                                                         CA[c][r]=CA[c][r]/(double)(cells[c][r].numberOfHosts);
01017                                                                 }
01018                                                                 else
01019                                                                         CA[c][r]=0;
01020                                                         }
01021                                                 }
01022 
01023                                                 int selectedGoalCellX2=0;
01024                                                 int selectedGoalCellY2=0;
01025                                                 
01026                                                 double CAMax1=0;
01027                                                 double CAMax2=0;
01028                                         
01029                                                 for (int c=0;c<numberOfRows;c++)
01030                                                         for (int r=0;r<numberOfColumns;r++)
01031                                                                 if (CA[c][r]>CAMax1) {
01032                                                                 
01033                                                                         //set the second best
01034                                                                         selectedGoalCellX2=selectedGoalCellX;
01035                                                                         selectedGoalCellY2=selectedGoalCellY;
01036                                                                         CAMax2=CAMax1;
01037                                                                 
01038                                                                         selectedGoalCellX=c+1;
01039                                                                         selectedGoalCellY=r+1;
01040                                                                 
01041                                                                         CAMax1=CA[c][r];
01042 
01043                                                                 }
01044                                                                 else if (CA[c][r]>CAMax2) {
01045                                                                         selectedGoalCellX2=c+1;
01046                                                                         selectedGoalCellY2=r+1;
01047                                                                         CAMax2=CA[c][r];
01048                                                                 }
01049 
01050                                                 setgoal++;
01051 
01052                                                 if ((previousGoalCellX!=selectedGoalCellX)||(previousGoalCellY!=selectedGoalCellY)) {
01053                                                         cout << "Host "<< i+1 << " is moving from cell " << previousGoalCellX << "-" << previousGoalCellY;
01054                                                         cout << " to cell " << selectedGoalCellX << "-" << selectedGoalCellY << endl;
01055                                                 }
01056 
01057                                                 if ((previousGoalCellX==selectedGoalCellX)&&(previousGoalCellY==selectedGoalCellY)) {
01058                                                         if (hosts[i].isATraveller==true) {
01059                                                                 if (selectedGoalCellX!=0) 
01060                                                                 {
01061                                                                         selectedGoalCellX=selectedGoalCellX2;
01062                                                                         selectedGoalCellY=selectedGoalCellY2;
01063                                                                 }
01064                                                         }
01065                                                 }
01066 
01067                                         }//end deterministic
01068                                         else {//probabilistic
01069 
01070                                                 //Algorithm of the selection of the new cell
01071                                                 for (int c=0;c<numberOfRows;c++)
01072                                                         for (int r=0;r<numberOfColumns;r++)
01073                                                                 CA[c][r]=0.0;
01074                                                 
01075                                                 //find current node's community
01076                                                 int comId=-1;
01077                                                 for(int c=0;c<numHosts;c++){
01078                                                         if(communities[c][0]==i+1)
01079                                                                 comId=communities[c][1];
01080                                                 }
01081 
01082                                                 //Add interaction of each node to the present while the initial cell exerts attraction with all the initial nodes
01083                                                 for (int n=0;n<numHosts;n++) {
01084                                                         //For all nodes but the present one
01085                                                         if (n!=i) {
01086                                                                 //Check the communities of all nodes
01087                                                                 for(int c=0;c<numHosts;c++) {
01088                                                                         if(communities[c][0]-1==n) {
01089                                                                                 //If the checked node belongs to the same community as the currently choosing target add their
01090                                                                                 //interaction to the initial square of the current node
01091                                                                                 if (communities[c][1]==comId)
01092                                                                                         CA[hosts[n].initialCellIdX-1][hosts[n].initialCellIdY-1]+=interaction[i][n];
01093                                                                                 //Else add it to the square it currently resides
01094                                                                                 else
01095                                                                                         CA[hosts[n].cellIdX-1][hosts[n].cellIdY-1]+=interaction[i][n];
01096                                                                         }
01097                                                                 }
01098                                                         }
01099                                                 }
01100 
01101                                                 for (int c=0;c<numberOfRows;c++) {
01102                                                         for (int r=0;r<numberOfColumns;r++) {
01103                                                                 if (cells[c][r].numberOfHosts!=0) {
01104                                                                         CA[c][r]=CA[c][r]/(double)(cells[c][r].numberOfHosts);
01105                                                                 }
01106                                                                 else
01107                                                                         CA[c][r]=0;
01108                                                         }
01109                                                 }
01110 
01111                                                 //Denonmiantor for the normalization of the values
01112                                                 float denNorm=0.00;
01113                                                 
01114                                                 //used for simulations
01115                                                 //drift=0.01;
01116                                                 
01117                                                 drift=0;
01118                                                 
01119                                                 for (int c=0;c<numberOfRows;c++) {
01120                                                         for (int r=0;r<numberOfColumns;r++) {
01121                                                                 denNorm=denNorm+CA[c][r]+drift;
01122                                                                 //printf ("%f ",CA[c][r]);
01123                                                         }
01124                                                         //cout << endl;
01125                                                 }
01126                                                 
01127                                                 for (int c=0;c<numberOfRows;c++) {
01128                                                         for (int r=0;r<numberOfColumns;r++) {
01129                                                                 if (CA[c][r]==0)
01130                                                                         a[c][r]=drift/denNorm;
01131                                                                 else
01132                                                                         a[c][r]=(CA[c][r]+drift)/(+denNorm);
01133                                                         }
01134                                                 }
01135                                                 
01136                                                 float current=0.0;
01137                                                 for (int c=0;c<numberOfRows;c++) {
01138                                                         for (int r=0;r<numberOfColumns;r++) {
01139                                                                 p[c][r].min=current;
01140                                                                 
01141                                                                 p[c][r].max=p[c][r].min+a[c][r];
01142                                                                 current=p[c][r].max;
01143                                                         }
01144                                                 }
01145                                                         
01146                                                 //float infiniteDice= (float) random() / (float) 0x7fffffff;;
01147                                                 float infiniteDice = (float) generateRandomDouble(0.0,1.0);
01148                                                 //printf ("%f %s",infiniteDice,"\n");
01149                                                 for (int c=0;c<numberOfRows;c++) {
01150                                                         for (int r=0;r<numberOfColumns;r++) {
01151                                                                 if ((infiniteDice>p[c][r].min)&&(infiniteDice<=p[c][r].max)) {
01152                                                                         selectedGoalCellX=c+1;
01153                                                                         selectedGoalCellY=r+1;
01154                                                                         setgoal++;
01155                                                                 }
01156                                                         }
01157                                                 }
01158                                         }//end probabilistic
01159 
01160                                         //Since the goal square changed change the number of friends for this node's friends
01161                                         if ((previousGoalCellX!=selectedGoalCellX)||(previousGoalCellY!=selectedGoalCellY)) {
01162                                                 for (int n=0;n<numHosts;n++) {
01163                                                         //If the two nodes are friends
01164                                                         if(adjacency[i][n]==1 && i!=n) {
01165                                                                 //Increase the number of friends in the specific square of the grid
01166                                                                 hosts[n].numberOfFriends[previousGoalCellX-1][previousGoalCellY-1]-=1;
01167                                                                 hosts[n].numberOfFriends[selectedGoalCellX-1][selectedGoalCellY-1]+=1;
01168                                                         }
01169                                                 }
01170                                                 commute++;
01171                                         }
01172 
01173                                         //Re-definition of the number of hosts in each cell
01174                                         cells[previousGoalCellX-1][previousGoalCellY-1].numberOfHosts-=1;
01175                                         cells[selectedGoalCellX-1][selectedGoalCellY-1].numberOfHosts+=1;               
01176 
01177 
01178                                         double newGoalRelativeX=generateRandomDouble(0,sideLengthX);
01179                                         double newGoalRelativeY=generateRandomDouble(0,sideLengthY);                                            
01180                                         
01181                                         //refresh of the information
01182                                         hosts[i].cellIdX=selectedGoalCellX;
01183                                         hosts[i].cellIdY=selectedGoalCellY;
01184                                                 
01185                                         hosts[i].goalCurrentX=cells[selectedGoalCellX-1][selectedGoalCellY-1].minX+newGoalRelativeX;
01186                                         hosts[i].goalCurrentY=cells[selectedGoalCellX-1][selectedGoalCellY-1].minY+newGoalRelativeY;
01187                                         hosts[i].speed=generateRandomDouble(minHostSpeed,maxHostSpeed);                                         
01188                                         hosts[i].absSpeed=hosts[i].speed;
01189                                         
01190                                         //printf("%s %f %s%d%s %f %f %f%s","$ns_ at",simTime,"\"$node_(",i,") setdest",hosts[i].goalCurrentX,hosts[i].goalCurrentY,(hosts[i].absSpeed)/stepInterval,"\"\n");
01191 
01192                                         if (generateXML==true)
01193                                                 generateXMLSetNewGoal(outputFileXML,i,simTime,hosts[i].goalCurrentX,hosts[i].goalCurrentY,hosts[i].absSpeed/stepInterval,sideLength_WholeAreaX,sideLength_WholeAreaY);
01194  
01195                                 }
01196                 }// end for (int i=0;i<numHosts;i++) {
01197 
01198                 for (int i=0;i<numHosts;i++) {
01199                         //update connectivity
01200                         for (int j=0;j<numHosts;j++) {
01201                                         //I am connected with me so the following condition must hold...:)
01202                                         if (i!=j) {
01203 
01204                                                 //calculation of the current distance
01205                                                 double currentDistance=sqrt((hosts[i].currentX-hosts[j].currentX)*(hosts[i].currentX-hosts[j].currentX)+(hosts[i].currentY-hosts[j].currentY)*(hosts[i].currentY-hosts[j].currentY));
01206                                         
01207                                                 //if currentDistance<=radius then the hosts are connected
01208                                                 if (currentDistance<radius) {
01209                                                         //if the hosts has been previously disconnected, then they must be connected
01210                                                         if (isConnected[i][j]==false) {
01211 
01212                                                                 isConnected[i][j]=true;
01213 
01214                                                                 lastValues[i][j]=simTime;
01215                                                         
01216                                                         }
01217                                                 }
01218                                                 //else they are disconnected
01219                                                 else {
01220                                                         if (isConnected[i][j]==true) {
01221                                                                         if (simTime!=0) {
01222                                                                                 //if the hosts has been previously connected, then they must be disconnected
01223                                                                                 if (colocationTracesOn)
01224                                                                                         fprintf(outputColocFiles[i],"%d %ld %ld\n",j+1,(long)lastValues[i][j],(long)simTime);
01225                                                                                 isConnected[i][j]=false;
01226                                                                         }
01227                                                                 }
01228                                                 }//end else
01229 
01230                                         }//end if (i!=j)
01231 
01232                                 }
01233 
01234                 }
01235                                 
01236         }
01237 
01238         //Print the colocation traces for the nodes who were connected when simulation finished
01239         for (int i=0;i<numHosts;i++) {
01240                 //update connectivity
01241                 for (int j=0;j<numHosts;j++) {
01242                         //I am connected with me so the following condition must hold...:)
01243                         if (i!=j) {
01244                                         if (isConnected[i][j]==true) {
01245                                                 if (simTime!=0) {
01246                                                                 //if the hosts has been previously connected, then they must be disconnected
01247                                                                 if (colocationTracesOn)
01248                                                                         fprintf(outputColocFiles[i],"%d %ld %ld\n",j+1,(long)lastValues[i][j],(long)simTime);
01249                                                                 isConnected[i][j]=false;
01250                                                         }
01251                                         }
01252 
01253                         }//end if (i!=j)
01254 
01255                 }
01256         }
01257 
01258         //generation of the XML file - generation of the last lines
01259         if (generateXML==true)  {       
01260                 fprintf(outputFileXML,"\t</mobility>\n");       
01261                 fprintf(outputFileXML,"\t<statistics>\n");
01262                 fprintf(outputFileXML,"\t\t<stoptime>%f</stoptime>\n",simTime);
01263                 fprintf(outputFileXML,"\t</statistics>\n");
01264                 fprintf(outputFileXML,"</simulation>\n");
01265         }
01266         
01267         if(setgoal!=0)
01268                 cout << "Percentage of commute nodes: "<< (double)commute/(double)setgoal << endl;
01269         else
01270                 cout << "Percentage of commute nodes: 0" << endl;
01271         cout << "Random Seed: " << inputSeed << endl;
01272 
01273         // close output file and outputFileXML
01274         if (generateXML==true) 
01275                 fclose (outputFileXML);
01276 
01277         
01278 }

void setSeed ( unsigned int  init  ) 

00098                                    {
00099         if (init != 0.0) SEED = init;
00100 }

void usage (  ) 

00134              {
00135         printf("%s","Usage: movGen [-options] \n");
00136         printf("%s","Input parameters:\n");
00137         printf("%s","-h                           shows help\n");
00138         printf("%s","-x <output_XML_file>         generates XML\n");
00139     printf("%s","-n <numberOfHosts>           sets the number of hosts\n");
00140         printf("%s","-t <totalSimulationTime>     sets the total simulation time\n");
00141         printf("%s","-r <reconfigurationInterval> sets the reconfiguration interval\n");
00142         printf("%s","-s <lowerBoundSpeedHost>     sets lower bound of the speed of the hosts (in m/s)\n");
00143         printf("%s","-S <upperBoundSpeedHost>     sets upper bound of the speed of the hosts (in m/s)\n");
00144         printf("%s","-p <connectionThreshold>     sets the connection threshold\n");
00145         printf("%s","-X <sideLengthXcoordinates>  sets the side length of the the simulation area - x coordinates\n");
00146         printf("%s","-Y <sideLengthYcoordinates>  sets the side length of the the simulation area - y coordinates\n");
00147         printf("%s","-R <numberOfRows>            sets the number of rows\n");
00148         printf("%s","-C <numberOfColumns>         sets the number of columns\n");
00149         printf("%s","-T <transmissionRange>       sets the transmission range (in m)\n");
00150         printf("%s","-w <rewiring probability>    sets the rewiring probability\n");
00151         printf("%s","-G <numberOfGroups>          sets the initial number of groups for the Caveman model\n");
00152         printf("%s","-g <seedRNG>                 sets the seed of the Random Number Generator\n");
00153         printf("%s","-c <numberOfTravellers>      sets the number of travellers\n");
00154         printf("%s","-v <travellersSpeed>         sets the speed of the travellers\n");
00155         printf("%s","-a <on/off>                  sets the Girvan-Newman algorithm on/off\n");
00156         printf("%s","-d <on/off>                  sets the deterministic selection of the nodes on/off. If true the selection is deterministic, if false is probabilistic\n");
00157         printf("%s","-i <on/off>                  sets the the name of the input adjacency file\n");
00158         printf("%s","-o <on/off>                  sets the output adjacency file generation on/off\n");
00159         printf("%s","-P <on/off>                  sets the maximum pause time durationmake"
00160                         "\n");
00161         printf("%s","-A <on/off>                  sets the colocation traces on/off\n");
00162         printf("%s","-b <on/off>                  sets the communities traces on/off\n");
00163 }

Generated on Mon Aug 13 18:29:03 2012 for ECMM by  doxygen 1.6.3