OverSim
Vivaldi Class Reference

#include <Vivaldi.h>

Inheritance diagram for Vivaldi:
AbstractNcs SVivaldi

Public Member Functions

virtual ~Vivaldi ()
virtual void init (NeighborCache *neighborCache)
void processCoordinates (const simtime_t &rtt, const AbstractNcsNodeInfo &nodeInfo)
Prox getCoordinateBasedProx (const AbstractNcsNodeInfo &info) const
virtual AbstractNcsNodeInfogetUnvalidNcsInfo () const
virtual AbstractNcsNodeInfocreateNcsInfo (const std::vector< double > &coords) const
const VivaldiCoordsInfogetOwnNcsInfo () const
const std::vector< double > & getOwnCoordinates () const
double getOwnError () const
double getOwnHeightVector () const
- Public Member Functions inherited from AbstractNcs
virtual ~AbstractNcs ()
virtual bool isReady ()
virtual void handleTimerEvent (cMessage *msg)
virtual bool handleRpcCall (BaseCallMessage *msg)

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

VivaldiCoordsInfoownCoords
double errorC
double coordC
bool showPosition
GlobalStatisticsglobalStatistics
NeighborCacheneighborCache

Private Attributes

bool enableHeightVector
uint32_t dimension

Detailed Description

Definition at line 39 of file Vivaldi.h.

Constructor & Destructor Documentation

virtual Vivaldi::~Vivaldi ( )
inlinevirtual

Definition at line 66 of file Vivaldi.h.

{ delete ownCoords; };

Member Function Documentation

double Vivaldi::calcDelta ( const simtime_t &  rtt,
double  dist,
double  weight 
)
protectedvirtual

Reimplemented in SVivaldi.

Definition at line 123 of file Vivaldi.cc.

Referenced by processCoordinates().

{
// estimates the delta factor
return coordC * weight;
}
double Vivaldi::calcError ( const simtime_t &  rtt,
double  dist,
double  weight 
)
protectedvirtual

Reimplemented in SVivaldi.

Definition at line 110 of file Vivaldi.cc.

Referenced by processCoordinates().

{
double relErr = 0;
if (rtt != 0) {
//eSample computes the relative error for this sample
relErr = fabs(dist - rtt) / rtt;
}
// update weighted moving average of local error
return (relErr * errorC * weight) +
ownCoords->getError() * (1 - errorC * weight);
}
AbstractNcsNodeInfo * Vivaldi::createNcsInfo ( const std::vector< double > &  coords) const
virtual

Implements AbstractNcs.

Definition at line 136 of file Vivaldi.cc.

{
assert(coords.size() > 1);
uint8_t i;
for (i = 0; i < coords.size() - (enableHeightVector ? 2 : 1); ++i) {
info->setCoords(i, coords[i]);
}
info->setError(coords[i++]);
info->setHeightVector(coords[i]);
}
return info;
}
void Vivaldi::finishVivaldi ( )
protectedvirtual

Definition at line 171 of file Vivaldi.cc.

{
globalStatistics->addStdDev("Vivaldi: Errori(ei)", ownCoords->getError());
}
Prox Vivaldi::getCoordinateBasedProx ( const AbstractNcsNodeInfo info) const
virtual

Implements AbstractNcs.

Definition at line 130 of file Vivaldi.cc.

{
return ownCoords->getDistance(abstractInfo);
}
const std::vector<double>& Vivaldi::getOwnCoordinates ( ) const
inline

Definition at line 78 of file Vivaldi.h.

{ return ownCoords->getCoords(); };
double Vivaldi::getOwnError ( ) const
inline

Definition at line 79 of file Vivaldi.h.

Referenced by DiscoveryMode::sendNewRequest(), and DiscoveryMode::stop().

{ return ownCoords->getError(); };
double Vivaldi::getOwnHeightVector ( ) const
inline

Definition at line 80 of file Vivaldi.h.

{ return ownCoords->getHeightVector(); };
const VivaldiCoordsInfo& Vivaldi::getOwnNcsInfo ( ) const
inlinevirtual

Implements AbstractNcs.

Definition at line 77 of file Vivaldi.h.

{ return *ownCoords; };
virtual AbstractNcsNodeInfo* Vivaldi::getUnvalidNcsInfo ( ) const
inlinevirtual

Implements AbstractNcs.

Definition at line 74 of file Vivaldi.h.

void Vivaldi::init ( NeighborCache neighborCache)
virtual

Implements AbstractNcs.

Reimplemented in SVivaldi.

Definition at line 32 of file Vivaldi.cc.

{
this->neighborCache = neighborCache;
errorC = neighborCache->par("vivaldiErrorConst");
coordC = neighborCache->par("vivaldiCoordConst");
dimension = neighborCache->par("vivaldiDimConst");
enableHeightVector = neighborCache->par("vivaldiEnableHeightVector");
showPosition = neighborCache->par("vivaldiShowPosition");
// init variables
for (uint32_t i = 0; i < dimension; i++) {
//ownCoords->setCoords(i, uniform(-.2, .2));
ownCoords->setCoords(i, uniform(-200, 200));
}
WATCH(*ownCoords);
};
void Vivaldi::processCoordinates ( const simtime_t &  rtt,
const AbstractNcsNodeInfo nodeInfo 
)
virtual

Reimplemented from AbstractNcs.

Definition at line 57 of file Vivaldi.cc.

{
if (rtt <= 0.0) {
std::cout << "Vivaldi::processCoordinates() called with rtt = "
<< rtt << std::endl;
return;
}
//double dblrtt = SIMTIME_DBL(rtt);// * 1000; // s -> ms
if (!dynamic_cast<const VivaldiCoordsInfo*>(&nodeInfo)) {
throw cRuntimeError("Vivaldi coords needed!");
}
const VivaldiCoordsInfo& info =
*(static_cast<const VivaldiCoordsInfo*>(&nodeInfo));
// calculate weight
double weight = (((ownCoords->getError() + info.getError()) == 0) ? 0 :
(ownCoords->getError() / (ownCoords->getError() + info.getError())));
// calculate distance
double dist = ownCoords->getDistance(info).proximity;
// ... own error
ownCoords->setError(calcError(rtt, dist, weight));
// delta
double delta = calcDelta(rtt, dist, weight);
// update local coordinates
if (dist > 0) {
for (uint8_t i = 0; i < dimension; i++) {
// old calculation based on s not ms
//ownCoords->setCoords(i, ownCoords->getCoords(i) +
// (delta * (SIMTIME_DBL(rtt) - dist)) *
// ((ownCoords->getCoords(i) - info.getCoords(i)) /
// dist));
ownCoords->setCoords(i, ((ownCoords->getCoords(i) / 1000) +
(delta * (SIMTIME_DBL(rtt) - dist)) *
((ownCoords->getCoords(i) - info.getCoords(i)) /
(dist * 1000))) * 1000);
}
(delta * (SIMTIME_DBL(rtt) - dist)));
}
}
}
void Vivaldi::updateDisplay ( )
protectedvirtual

Definition at line 155 of file Vivaldi.cc.

Referenced by processCoordinates().

{
char buf[60];
sprintf(buf, "xi[0]: %f xi[1]: %f ", ownCoords->getCoords(0),
neighborCache->getDisplayString().setTagArg("t", 0, buf);
// show nodes at estimated position TODO
if (showPosition) {
for (uint32_t i = 0; i < dimension; i++)
neighborCache->getParentModule()
->getDisplayString().setTagArg("p", i,
ownCoords->getCoords(i)/* * 1000*/);
}
}

Member Data Documentation

double Vivaldi::coordC
protected

Definition at line 50 of file Vivaldi.h.

Referenced by SVivaldi::calcDelta(), 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 SVivaldi::calcError(), calcError(), and init().

GlobalStatistics* Vivaldi::globalStatistics
protected

Definition at line 62 of file Vivaldi.h.

Referenced by finishVivaldi(), and init().

NeighborCache* Vivaldi::neighborCache
protected

Definition at line 63 of file Vivaldi.h.

Referenced by SVivaldi::calcError(), init(), and updateDisplay().

bool Vivaldi::showPosition
protected

Definition at line 52 of file Vivaldi.h.

Referenced by init(), and updateDisplay().


The documentation for this class was generated from the following files: