#include <Vivaldi.h>
Definition at line 37 of file Vivaldi.h.
Public Member Functions | |
| virtual void | initVivaldi (NeighborCache *neighborCache) |
| void | processCoordinates (simtime_t rtt, const std::vector< double > &xj, double errrorj) |
| 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 |
| double | lossC |
| double | effectiveSample |
| uint32_t | dimension |
| std::vector< double > | xi |
| double | errori |
| double | loss |
| void Vivaldi::finishVivaldi | ( | ) | [protected, virtual] |
Definition at line 126 of file Vivaldi.cc.
00127 { 00128 globalStatistics->addStdDev("Vivaldi: Errori(ei)",errori); 00129 }
| void Vivaldi::updateDisplay | ( | ) | [protected, virtual] |
Definition at line 112 of file Vivaldi.cc.
Referenced by processCoordinates().
00113 { 00114 char buf[60]; 00115 sprintf(buf, "xi[0]: %f xi[1]: %f ", xi[0], xi[1]); 00116 neighborCache->getDisplayString().setTagArg("t", 0, buf); 00117 00118 // show nodes at estimated position TODO 00119 if (showVivaldiPosition) { 00120 for (uint32_t i = 0; i < dimension; i++) 00121 neighborCache->getParentModule() 00122 ->getDisplayString().setTagArg("p", i, xi[i] * 1000); 00123 } 00124 }
| void Vivaldi::initVivaldi | ( | NeighborCache * | neighborCache | ) | [virtual] |
Definition at line 32 of file Vivaldi.cc.
Referenced by NeighborCache::initialize().
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 lossC = neighborCache->par("vivaldiLossConst"); 00041 effectiveSample = neighborCache->par("vivaldiEffectiveSample"); 00042 showVivaldiPosition = neighborCache->par("showVivaldiPosition"); 00043 00044 // init variables 00045 xi.resize(dimension); 00046 errori = 1.0; 00047 loss = 0; 00048 00049 for (uint32_t i = 0; i < dimension; i++) { 00050 xi[i] = uniform(-.2, .2); //TODO 00051 } 00052 00053 WATCH(errori); 00054 WATCH_VECTOR(xi); 00055 WATCH(loss); 00056 00057 globalStatistics = GlobalStatisticsAccess().get(); 00058 };
| void Vivaldi::processCoordinates | ( | simtime_t | rtt, | |
| const std::vector< double > & | xj, | |||
| double | errrorj | |||
| ) |
Definition at line 60 of file Vivaldi.cc.
Referenced by NeighborCache::updateNode().
00063 { 00064 //assert(rtt > 0.0); 00065 if (rtt <= 0.0) return; 00066 00067 // init variables 00068 double dist = 0, sum = 0, delta = 0; 00069 double weight = (((errori + errorj) == 0) ? 00070 0 : (errori / (errori + errorj))); 00071 00072 // calculate distance 00073 if (rtt != 0) { 00074 for (uint32_t i = 0; i < dimension; i++) { 00075 dist += pow(xi[i] - xj[i], 2); 00076 } 00077 dist = sqrt(dist); 00078 } 00079 00080 // choose Vivaldi version 00081 if (useSVivaldi) { 00082 // get avg absolute prediction error 00083 sum = neighborCache->getAvgAbsPredictionError(xi, effectiveSample); 00084 00085 // update weighted moving average of local error 00086 errori = (sum * errorC) + errori * (1 - errorC); 00087 00088 // calculate loss factor 00089 loss = lossC + (1 - lossC) * loss; 00090 delta = coordC * weight * (1 - loss); 00091 } else { 00092 double relErr = 0; 00093 if (rtt != 0) { 00094 //eSample computes the relative error for this sample 00095 relErr = fabs(dist - rtt) / rtt; 00096 } 00097 // update weighted moving average of local error 00098 errori = (relErr * errorC * weight) + errori * (1 - errorC * weight); 00099 // estimates the delta factor 00100 delta = coordC * weight; 00101 } 00102 00103 // update local coordinates 00104 if (dist > 0) { 00105 for (uint32_t i = 0; i < dimension; i++) { 00106 xi[i] += (delta * (SIMTIME_DBL(rtt) - dist)) * ((xi[i] - xj[i]) / dist); 00107 } 00108 } 00109 updateDisplay(); 00110 }
| const std::vector<double>& Vivaldi::getOwnCoordinates | ( | ) | const [inline] |
Definition at line 69 of file Vivaldi.h.
Referenced by NeighborCache::getNodePredictedRtt(), and BaseRpc::sendRpcResponse().
00069 { return xi; };
| double Vivaldi::getOwnError | ( | ) | const [inline] |
Definition at line 70 of file Vivaldi.h.
Referenced by BaseRpc::sendRpcResponse().
00070 { return errori; };
double Vivaldi::errorC [private] |
double Vivaldi::coordC [private] |
double Vivaldi::lossC [private] |
double Vivaldi::effectiveSample [private] |
uint32_t Vivaldi::dimension [private] |
Definition at line 45 of file Vivaldi.h.
Referenced by initVivaldi(), processCoordinates(), and updateDisplay().
std::vector<double> Vivaldi::xi [private] |
Definition at line 48 of file Vivaldi.h.
Referenced by getOwnCoordinates(), initVivaldi(), processCoordinates(), and updateDisplay().
double Vivaldi::errori [private] |
Definition at line 49 of file Vivaldi.h.
Referenced by finishVivaldi(), getOwnError(), initVivaldi(), and processCoordinates().
double Vivaldi::loss [private] |
bool Vivaldi::useSVivaldi [protected] |
bool Vivaldi::showVivaldiPosition [protected] |
GlobalStatistics* Vivaldi::globalStatistics [protected] |
NeighborCache* Vivaldi::neighborCache [protected] |
1.5.5