00001 00002 // PROYECTO FIN DE CARRERA // 00003 // TÍTULO: Implementación de un Simulador de Redes de Acceso Pasivas en Omnet // 00004 // // 00005 // AUTOR: Jose Maria Robledo Saez // 00006 // TUTOR: Noemi Merayo Alvarez // 00007 // INGENIERÍA TÉCNICA DE TELECOMUNICACIONES, SISTEMAS DE TELECOMUNICACIÓN // 00008 // UNIVERSIDAD DE VALLADOLID // 00010 00011 00016 /***********************************************************/ 00017 // 00018 // File: analysis.h 00019 // Aim: Declaration of the required classes for 00020 // simulation analysis 00021 // Authors: Ignacio de Miguel Jimenez 00022 // David Rodriguez Alfayate 00023 // Institution: University of Valladolid (Spain) 00024 // E-mail: ignacio.miguel@tel.uva.es 00025 // Version: 1.1 00026 // 21-Nov-00 00027 // Translation to English: 2-Dec-10 00028 /***********************************************************/ 00029 00030 #ifndef __ANALYSIS_H 00031 #define __ANALYSIS_H 00032 00033 #include <cstring> 00034 #include <algorithm> 00035 #include <cctype> 00036 #include <climits> 00037 #include <cstdio> 00038 #include <cstdlib> 00039 #include <memory> 00040 #include <sys/types.h> 00041 #include <typeinfo> 00042 00043 00044 #ifndef __MATH_H 00045 #include <math.h> 00046 #endif 00047 00048 #ifndef __STDLIB_H 00049 #include <stdlib.h> 00050 #endif 00051 00052 #ifndef __IOSTREAM_H 00053 #include <iostream> 00054 #endif 00055 00056 #ifndef __FSTREAM_H 00057 #include <fstream> 00058 #endif 00059 00060 #define NUM_BATCHES 400 00061 #define EVEN 1 00062 #define ODD 0 00063 00064 #define HALF 2 00065 00066 // By decreasing THRESHOLD and GAMMA more 00067 // strict requirements are set in order to 00068 // declare that the estimation of the parameter 00069 // has converged. 00070 // Hence, by decreasing these values, simulations 00071 // run longer but provide more accurate estimates of 00072 // the averages and a smaller confidence interval 00073 #define THRESHOLD 0.4 00074 #define GAMMA 0.075 00075 00076 #define t_STUDENT 1.960 00077 00078 using namespace std; 00079 00095 class Analysis 00096 { 00097 long double averages[2][NUM_BATCHES]; // It stores the averages with the result 00098 // of the analysis. 00099 long double rohat; // Correlation. 00100 int position_batch[2]; // Posicion of the batch where we are 00101 int size_batch[2]; // Size of the batch 00102 int batch[2]; // Current batch 00103 long samples[2]; // Total samples per batch 00104 int iter; // Number of iteration 00105 int converge; // Converge or not. 00106 long double total_average; // Average of all batches. 00107 long double numerator_sy2; // Numerator used in calculation of conf. interval 00108 long Max_samples[2]; // Maximum number of samples in even and odd iterations 00109 public: 00110 // IMPORTANT FUNCTIONS FOR THE USER OF THE CLASS 00111 Analysis(); 00112 bool analyze(const long double &elem); // Add a sample of the parameter to analyze to the list. 00113 int converged() {return converge;} // Returns 1 if the analysis of the parameter converged, 0 otherwise. 00114 long double average() {return total_average; } // Returns the average of the parameter 00115 long double half_confidence_interval() { 00116 // Returns half confidence interval 00117 // Thus, the result should be expressed as: 00118 // average() +- half_confidence_interval() 00119 return t_STUDENT*sqrt(numerator_sy2/(NUM_BATCHES*(NUM_BATCHES-1))); 00120 } 00121 int number_iterations() { return iter; } // Returns the number of iterations 00122 void result(); // Prints the result of the analysis 00123 00124 // OTHER FUNCTIONS 00125 long double value_rohat() {return rohat;} // Returns self-correlation 00126 protected: 00127 void calculate_averages(int); // Calculates the averages of the batches 00128 int calculate_rohat(int,int x=1); // Calculates the correlation 00129 long double calculate_ro(int,int,int); // Calculates a first estimate of the correlation 00130 void average_from_to(int,int,int); // Calculates the average of all averages 00131 // from 'from' to 'to' 00132 int check_gamma(); // Checks whether the threshold has been exceeded 00133 00134 friend istream & operator>> (istream & ent, Analysis & anls); 00135 friend ostream & operator<< (ostream & sal, Analysis anls); 00136 00137 }; 00138 00139 #endif 00140