#include <Vivaldi.h>
Public Member Functions | |
| virtual void | initVivaldi (NeighborCache *neighborCache) |
| void | processCoordinates (simtime_t rtt, const std::vector< double > &xj, double errrorj) |
| Prox | getCoordinateBasedProx (const NodeCoordsInfo &info) |
| const std::vector< double > & | getOwnCoordinates () const |
| double | getOwnError () const |
Protected Member Functions | |
| virtual void | finishVivaldi () |
| virtual void | updateDisplay () |
Protected Attributes | |
| bool | useSVivaldi |
| bool | showVivaldiPosition |
| GlobalStatistics * | globalStatistics |
| NeighborCache * | neighborCache |
Private Attributes | |
| double | errorC |
| double | coordC |
| bool | enableHeightVector |
| double | lossC |
| double | effectiveSample |
| uint32_t | dimension |
| std::vector< double > | xi |
| double | errori |
| double | loss |
| double | lossResetLimit |
Definition at line 39 of file Vivaldi.h.
| void Vivaldi::finishVivaldi | ( | ) | [protected, virtual] |
Definition at line 164 of file Vivaldi.cc.
00165 { 00166 globalStatistics->addStdDev("Vivaldi: Errori(ei)",errori); 00167 }
| Prox Vivaldi::getCoordinateBasedProx | ( | const NodeCoordsInfo & | info | ) |
Definition at line 126 of file Vivaldi.cc.
Referenced by NeighborCache::getCoordinateBasedProx().
00127 { 00128 double dist = 0.0, accuracy = 0.0; 00129 uint32_t size = info.coordinates.size(); 00130 if(enableHeightVector) size -= 1; 00131 00132 for (uint32_t i = 0; i < size; i++) { 00133 dist += pow(xi[i] - info.coordinates[i], 2); 00134 } 00135 dist = sqrt(dist); 00136 00137 accuracy = 1 - ((info.coordErr + errori) / 2); 00138 if (info.coordErr >= 1.0 || errori >= 1.0) accuracy = 0.0; 00139 if (accuracy < 0) accuracy = 0.0; 00140 if (accuracy > 1) accuracy = 1; 00141 00142 if (enableHeightVector) return Prox(dist + 00143 xi[size] + 00144 info.coordinates[size], 00145 info.coordErr); 00146 return Prox(dist, accuracy); 00147 }
| const std::vector<double>& Vivaldi::getOwnCoordinates | ( | ) | const [inline] |
Definition at line 74 of file Vivaldi.h.
Referenced by BaseRpc::sendRpcResponse().
00074 { return xi; };
| double Vivaldi::getOwnError | ( | ) | const [inline] |
Definition at line 75 of file Vivaldi.h.
Referenced by BaseRpc::sendRpcResponse().
00075 { return errori; };
| void Vivaldi::initVivaldi | ( | NeighborCache * | neighborCache | ) | [virtual] |
Definition at line 32 of file Vivaldi.cc.
Referenced by NeighborCache::initializeApp().
00033 { 00034 this->neighborCache = neighborCache; 00035 00036 useSVivaldi = neighborCache->par("useSVivaldi"); 00037 errorC = neighborCache->par("vivaldiErrorConst"); 00038 coordC = neighborCache->par("vivaldiCoordConst"); 00039 dimension = neighborCache->par("vivaldiDimConst"); 00040 enableHeightVector = neighborCache->par("vivaldiEnableHeightVector"); 00041 lossC = neighborCache->par("vivaldiLossConst"); 00042 effectiveSample = neighborCache->par("vivaldiEffectiveSample"); 00043 showVivaldiPosition = neighborCache->par("showVivaldiPosition"); 00044 lossResetLimit = neighborCache->par("lossResetLimit"); 00045 00046 if(enableHeightVector) dimension += 1; 00047 00048 // init variables 00049 xi.resize(dimension); 00050 errori = 1.0; 00051 loss = 0; 00052 00053 for (uint32_t i = 0; i < dimension; i++) { 00054 xi[i] = uniform(-.2, .2); //TODO 00055 } 00056 if(enableHeightVector) xi[dimension - 1] = 0; 00057 00058 WATCH(errori); 00059 WATCH_VECTOR(xi); 00060 WATCH(loss); 00061 00062 globalStatistics = GlobalStatisticsAccess().get(); 00063 };
| void Vivaldi::processCoordinates | ( | simtime_t | rtt, | |
| const std::vector< double > & | xj, | |||
| double | errrorj | |||
| ) |
Definition at line 65 of file Vivaldi.cc.
Referenced by NeighborCache::updateNode().
00068 { 00069 //assert(rtt > 0.0); 00070 if (rtt <= 0.0) return; 00071 00072 // init variables 00073 double dist = 0, sum = 0, delta = 0; 00074 double weight = (((errori + errorj) == 0) ? 00075 0 : (errori / (errori + errorj))); 00076 00077 uint32_t size = dimension; 00078 if(enableHeightVector) size -= 1; 00079 00080 // calculate distance 00081 if (rtt != 0) { 00082 for (uint32_t i = 0; i < size; i++) { 00083 dist += pow(xi[i] - xj[i], 2); 00084 } 00085 dist = sqrt(dist); 00086 } 00087 if (enableHeightVector) dist += xi[size] + xj[size]; 00088 00089 // choose Vivaldi version 00090 if (useSVivaldi) { 00091 // get avg absolute prediction error 00092 sum = neighborCache->getAvgAbsPredictionError(xi, effectiveSample); 00093 00094 // update weighted moving average of local error 00095 errori = (sum * errorC) + errori * (1 - errorC); 00096 00097 // calculate loss factor 00098 loss = lossC + (1 - lossC) * loss; 00099 if(fabs(dist-SIMTIME_DBL(rtt)) > lossResetLimit) loss = 0.0; 00100 delta = coordC * weight * (1 - loss); 00101 } else { 00102 double relErr = 0; 00103 if (rtt != 0) { 00104 //eSample computes the relative error for this sample 00105 relErr = fabs(dist - rtt) / rtt; 00106 } 00107 // update weighted moving average of local error 00108 errori = (relErr * errorC * weight) + errori * (1 - errorC * weight); 00109 // estimates the delta factor 00110 delta = coordC * weight; 00111 } 00112 00113 // update local coordinates 00114 if (dist > 0) { 00115 for (uint32_t i = 0; i < size; i++) { 00116 xi[i] += (delta * (SIMTIME_DBL(rtt) - dist)) * ((xi[i] - xj[i]) / dist); 00117 } 00118 if(enableHeightVector) { 00119 xi[size] += (delta * (SIMTIME_DBL(rtt) - dist)); 00120 if(xi[size] < 0) xi[size] = 0.0; 00121 } 00122 } 00123 updateDisplay(); 00124 }
| void Vivaldi::updateDisplay | ( | ) | [protected, virtual] |
Definition at line 150 of file Vivaldi.cc.
Referenced by processCoordinates().
00151 { 00152 char buf[60]; 00153 sprintf(buf, "xi[0]: %f xi[1]: %f ", xi[0], xi[1]); 00154 neighborCache->getDisplayString().setTagArg("t", 0, buf); 00155 00156 // show nodes at estimated position TODO 00157 if (showVivaldiPosition) { 00158 for (uint32_t i = 0; i < dimension; i++) 00159 neighborCache->getParentModule() 00160 ->getDisplayString().setTagArg("p", i, xi[i] * 1000); 00161 } 00162 }
double Vivaldi::coordC [private] |
uint32_t Vivaldi::dimension [private] |
Definition at line 48 of file Vivaldi.h.
Referenced by initVivaldi(), processCoordinates(), and updateDisplay().
double Vivaldi::effectiveSample [private] |
bool Vivaldi::enableHeightVector [private] |
Definition at line 45 of file Vivaldi.h.
Referenced by getCoordinateBasedProx(), initVivaldi(), and processCoordinates().
double Vivaldi::errorC [private] |
double Vivaldi::errori [private] |
Definition at line 52 of file Vivaldi.h.
Referenced by finishVivaldi(), getCoordinateBasedProx(), getOwnError(), initVivaldi(), and processCoordinates().
GlobalStatistics* Vivaldi::globalStatistics [protected] |
double Vivaldi::loss [private] |
double Vivaldi::lossC [private] |
double Vivaldi::lossResetLimit [private] |
NeighborCache* Vivaldi::neighborCache [protected] |
bool Vivaldi::showVivaldiPosition [protected] |
bool Vivaldi::useSVivaldi [protected] |
std::vector<double> Vivaldi::xi [private] |
Definition at line 51 of file Vivaldi.h.
Referenced by getCoordinateBasedProx(), getOwnCoordinates(), initVivaldi(), processCoordinates(), and updateDisplay().
1.5.8