movGen-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 
)

00100                                                      {
00101         //double number=getRandomDouble() * (max-min+1.0) + min;
00102         double number=getRandomDouble()*(max-min)+min;  
00103         
00104         //double number=min+((max-min)*getRandomDouble()/RAND_MAX);
00105         return number;
00106 }

int generateRandomInteger ( int  min,
int  max 
)

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

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

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

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

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

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

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

double getRandomDouble (  ) 

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

void header (  ) 

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

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

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

void setSeed ( unsigned int  init  ) 

00094                                    {
00095         if (init != 0.0) SEED = init;
00096 }

void usage (  ) 

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

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