#include <Vivaldi.h>
Public Member Functions | |
virtual | ~Vivaldi () |
virtual bool | isAdapting () |
virtual void | init (NeighborCache *neighborCache) |
void | processCoordinates (const simtime_t &rtt, const AbstractNcsNodeInfo &nodeInfo) |
Prox | getCoordinateBasedProx (const AbstractNcsNodeInfo &info) const |
virtual AbstractNcsNodeInfo * | getUnvalidNcsInfo () const |
virtual AbstractNcsNodeInfo * | createNcsInfo (const std::vector< double > &coords) const |
const VivaldiCoordsInfo & | getOwnNcsInfo () const |
const std::vector< double > & | getOwnCoordinates () const |
double | getOwnError () const |
double | getOwnHeightVector () const |
Protected Member Functions | |
virtual void | finishVivaldi () |
virtual void | updateDisplay () |
virtual double | calcError (const simtime_t &rtt, double dist, double weight) |
virtual double | calcDelta (const simtime_t &rtt, double dist, double weight) |
Protected Attributes | |
VivaldiCoordsInfo * | ownCoords |
double | errorC |
double | coordC |
bool | showVivaldiPosition |
GlobalStatistics * | globalStatistics |
NeighborCache * | neighborCache |
Private Attributes | |
bool | enableHeightVector |
uint32_t | dimension |
Definition at line 39 of file Vivaldi.h.
virtual Vivaldi::~Vivaldi | ( | ) | [inline, virtual] |
double Vivaldi::calcDelta | ( | const simtime_t & | rtt, | |
double | dist, | |||
double | weight | |||
) | [protected, virtual] |
Reimplemented in SVivaldi.
Definition at line 115 of file Vivaldi.cc.
Referenced by processCoordinates().
00116 { 00117 // estimates the delta factor 00118 return coordC * weight; 00119 }
double Vivaldi::calcError | ( | const simtime_t & | rtt, | |
double | dist, | |||
double | weight | |||
) | [protected, virtual] |
Reimplemented in SVivaldi.
Definition at line 102 of file Vivaldi.cc.
Referenced by processCoordinates().
00103 { 00104 double relErr = 0; 00105 if (rtt != 0) { 00106 //eSample computes the relative error for this sample 00107 relErr = fabs(dist - rtt) / rtt; 00108 } 00109 // update weighted moving average of local error 00110 return (relErr * errorC * weight) + 00111 ownCoords->getError() * (1 - errorC * weight); 00112 }
AbstractNcsNodeInfo * Vivaldi::createNcsInfo | ( | const std::vector< double > & | coords | ) | const [virtual] |
Implements AbstractNcs.
Definition at line 128 of file Vivaldi.cc.
00129 { 00130 assert(coords.size() > 1); 00131 VivaldiCoordsInfo* info = new VivaldiCoordsInfo(); 00132 00133 uint8_t i; 00134 for (i = 0; i < coords.size() - (enableHeightVector ? 2 : 1); ++i) { 00135 info->setCoords(i, coords[i]); 00136 } 00137 info->setError(coords[i++]); 00138 00139 if (enableHeightVector) { 00140 info->setHeightVector(coords[i]); 00141 } 00142 00143 return info; 00144 }
void Vivaldi::finishVivaldi | ( | ) | [protected, virtual] |
Definition at line 163 of file Vivaldi.cc.
00164 { 00165 globalStatistics->addStdDev("Vivaldi: Errori(ei)", ownCoords->getError()); 00166 }
Prox Vivaldi::getCoordinateBasedProx | ( | const AbstractNcsNodeInfo & | info | ) | const [virtual] |
Implements AbstractNcs.
Definition at line 122 of file Vivaldi.cc.
00123 { 00124 return ownCoords->getDistance(abstractInfo); 00125 }
const std::vector<double>& Vivaldi::getOwnCoordinates | ( | ) | const [inline] |
double Vivaldi::getOwnError | ( | ) | const [inline] |
double Vivaldi::getOwnHeightVector | ( | ) | const [inline] |
Definition at line 82 of file Vivaldi.h.
00082 { return ownCoords->getHeightVector(); };
const VivaldiCoordsInfo& Vivaldi::getOwnNcsInfo | ( | ) | const [inline, virtual] |
virtual AbstractNcsNodeInfo* Vivaldi::getUnvalidNcsInfo | ( | ) | const [inline, virtual] |
Implements AbstractNcs.
Definition at line 76 of file Vivaldi.h.
00076 { return new VivaldiCoordsInfo(enableHeightVector); };
void Vivaldi::init | ( | NeighborCache * | neighborCache | ) | [virtual] |
Implements AbstractNcs.
Reimplemented in SVivaldi.
Definition at line 32 of file Vivaldi.cc.
00033 { 00034 this->neighborCache = neighborCache; 00035 00036 errorC = neighborCache->par("vivaldiErrorConst"); 00037 coordC = neighborCache->par("vivaldiCoordConst"); 00038 dimension = neighborCache->par("vivaldiDimConst"); 00039 enableHeightVector = neighborCache->par("vivaldiEnableHeightVector"); 00040 showVivaldiPosition = neighborCache->par("showVivaldiPosition"); 00041 00042 // init variables 00043 VivaldiCoordsInfo::setDimension(dimension); 00044 ownCoords = new VivaldiCoordsInfo(); 00045 00046 for (uint32_t i = 0; i < dimension; i++) { 00047 ownCoords->setCoords(i, uniform(-.2, .2)); 00048 } 00049 if (enableHeightVector) ownCoords->setHeightVector(0.0); 00050 00051 WATCH(*ownCoords); 00052 00053 globalStatistics = GlobalStatisticsAccess().get(); 00054 };
virtual bool Vivaldi::isAdapting | ( | ) | [inline, virtual] |
void Vivaldi::processCoordinates | ( | const simtime_t & | rtt, | |
const AbstractNcsNodeInfo & | nodeInfo | |||
) | [virtual] |
Reimplemented from AbstractNcs.
Definition at line 56 of file Vivaldi.cc.
00058 { 00059 if (rtt <= 0.0) { 00060 std::cout << "Vivaldi::processCoordinates() called with rtt = " 00061 << rtt << std::endl; 00062 return; 00063 } 00064 00065 if (!dynamic_cast<const VivaldiCoordsInfo*>(&nodeInfo)) { 00066 throw cRuntimeError("Vivaldi coords needed!"); 00067 } 00068 const VivaldiCoordsInfo& info = 00069 *(static_cast<const VivaldiCoordsInfo*>(&nodeInfo)); 00070 00071 // calculate weight 00072 double weight = (((ownCoords->getError() + info.getError()) == 0) ? 0 : 00073 (ownCoords->getError() / (ownCoords->getError() + info.getError()))); 00074 00075 // calculate distance 00076 double dist = ownCoords->getDistance(info).proximity; 00077 00078 // ... own error 00079 ownCoords->setError(calcError(rtt, dist, weight)); 00080 00081 // delta 00082 double delta = calcDelta(rtt, dist, weight); 00083 00084 // update local coordinates 00085 if (dist > 0) { 00086 for (uint8_t i = 0; i < dimension; i++) { 00087 ownCoords->setCoords(i, ownCoords->getCoords(i) + 00088 (delta * (SIMTIME_DBL(rtt) - dist)) * 00089 ((ownCoords->getCoords(i) - info.getCoords(i)) / 00090 dist)); 00091 } 00092 if(enableHeightVector) { 00093 ownCoords->setHeightVector(ownCoords->getHeightVector() + 00094 (delta * (SIMTIME_DBL(rtt) - dist))); 00095 } 00096 } 00097 00098 updateDisplay(); 00099 }
void Vivaldi::updateDisplay | ( | ) | [protected, virtual] |
Definition at line 147 of file Vivaldi.cc.
Referenced by processCoordinates().
00148 { 00149 char buf[60]; 00150 sprintf(buf, "xi[0]: %f xi[1]: %f ", ownCoords->getCoords(0), 00151 ownCoords->getCoords(1)); 00152 neighborCache->getDisplayString().setTagArg("t", 0, buf); 00153 00154 // show nodes at estimated position TODO 00155 if (showVivaldiPosition) { 00156 for (uint32_t i = 0; i < dimension; i++) 00157 neighborCache->getParentModule() 00158 ->getDisplayString().setTagArg("p", i, 00159 ownCoords->getCoords(i) * 1000); 00160 } 00161 }
double Vivaldi::coordC [protected] |
Definition at line 50 of file Vivaldi.h.
Referenced by calcDelta(), SVivaldi::calcDelta(), and init().
uint32_t Vivaldi::dimension [private] |
Definition at line 44 of file Vivaldi.h.
Referenced by init(), processCoordinates(), and updateDisplay().
bool Vivaldi::enableHeightVector [private] |
Definition at line 43 of file Vivaldi.h.
Referenced by createNcsInfo(), getUnvalidNcsInfo(), init(), and processCoordinates().
double Vivaldi::errorC [protected] |
Definition at line 49 of file Vivaldi.h.
Referenced by calcError(), SVivaldi::calcError(), and init().
GlobalStatistics* Vivaldi::globalStatistics [protected] |
Definition at line 63 of file Vivaldi.h.
Referenced by finishVivaldi(), and init().
NeighborCache* Vivaldi::neighborCache [protected] |
Definition at line 64 of file Vivaldi.h.
Referenced by SVivaldi::calcError(), and updateDisplay().
VivaldiCoordsInfo* Vivaldi::ownCoords [protected] |
Definition at line 47 of file Vivaldi.h.
Referenced by calcError(), SVivaldi::calcError(), finishVivaldi(), getCoordinateBasedProx(), getOwnCoordinates(), getOwnError(), getOwnHeightVector(), getOwnNcsInfo(), init(), processCoordinates(), updateDisplay(), and ~Vivaldi().
bool Vivaldi::showVivaldiPosition [protected] |
Definition at line 53 of file Vivaldi.h.
Referenced by init(), and updateDisplay().