OverSim
CoordCalcFunction Class Reference

Auxiliary class for coord calculation. More...

#include <Nps.h>

Public Member Functions

 CoordCalcFunction (const std::vector< LandmarkDataEntry > myLandmarks)
double f (const Vec_DP &initCoordinates) const

Static Public Member Functions

static double simplex_min (CoordCalcFunction *functionObject, Vec_DP &init)

Private Member Functions

double endnodeDistance (const Vec_DP &nodeCoordinates, LandmarkDataEntry landmark) const

Private Attributes

std::vector< LandmarkDataEntrylandmarks

Detailed Description

Auxiliary class for coord calculation.

Definition at line 62 of file Nps.h.

Constructor & Destructor Documentation

CoordCalcFunction::CoordCalcFunction ( const std::vector< LandmarkDataEntry myLandmarks)
inline

Definition at line 71 of file Nps.h.

: landmarks(myLandmarks) { };

Member Function Documentation

double CoordCalcFunction::endnodeDistance ( const Vec_DP nodeCoordinates,
LandmarkDataEntry  landmark 
) const
private

Definition at line 711 of file Nps.cc.

Referenced by f().

{
double sum_of_squares = 0.0;
for (int i = 0; i < nodeCoordinates.size(); i++) {
sum_of_squares += pow(landmark.coordinates[i] - nodeCoordinates[i], 2);
}
double result = sqrt(sum_of_squares);
return result;
}
double CoordCalcFunction::f ( const Vec_DP initCoordinates) const

Definition at line 691 of file Nps.cc.

Referenced by simplex_min().

{
double sum = 0;
double rel_diff = 0;
for (uint i = 0; i < landmarks.size(); i++) {
// Distance = RTT in ms / 2
double diff = SIMTIME_DBL(landmarks[i].rtt) / 2 * 1000 -
endnodeDistance(initCoordinates, landmarks[i]);
if (SIMTIME_DBL(landmarks[i].rtt) != 0) {
rel_diff = diff / (SIMTIME_DBL(landmarks[i].rtt) / 2 * 1000);
} else {
opp_error("[CBR] RTT == 0. Node is landmark? This shouldn't happen.");
}
sum += rel_diff * rel_diff;
}
return sum;
}
double CoordCalcFunction::simplex_min ( CoordCalcFunction functionObject,
Vec_DP init 
)
static

Definition at line 620 of file Nps.cc.

Referenced by Nps::computeOwnCoordinates().

{
double accf = 0.0000001;
double accx = 0.0000001;
uint32_t nmax = 30001;
uint8_t dim = init.size();
Simplex spx(dim);
int ihi; // Index of highest point at start of each iteration
Vec_DP phi(dim); // Highest point at start of each iteration.
double vhi; // Function value at highest point at start of each iteration.
double vre; // Function value at reflected point.
double vlo, diff; // for checking convergence.
uint32_t count;
// Initialize Simplex
Vec_DP tmp(dim);
spx.functionObject = functionObject;
spx[0] = init;
for (uint8_t i = 0; i < dim; i++) {
tmp[i] = 1;
spx[i+1] = init + tmp;
tmp[i] = 0;
}
Vec_DP debugCoords(dim);
for (count = 1; count <= nmax; count++) {
/*
if ((count % 10000) == 0) {
std::cout << "running loop #" << count << " of " << nmax << endl;
std::cout << "diff: " << diff << std::endl;
std::cout << "vhi: " << vhi << std::endl;
std::cout << "vlo: " << vlo << std::endl;
debugCoords = spx[spx.low()];
std::cout << "Coords: " << debugCoords << std::endl;
}
*/
ihi = spx.high(&vhi);
phi = spx[ihi];
spx.reflect();
vre = functionObject->f(spx[ihi]);
if (vre < functionObject->f(spx[spx.low()])) {
spx[ihi] = phi; // Undo reflection.
spx.reflect_exp();
vre = functionObject->f(spx[ihi]);
if (vre > functionObject->f(spx[spx.low()])) {
spx[ihi] = phi;
spx.reflect();
}
} else if (vre >= vhi) { // Equal sign important!
spx[ihi] = phi; // Undo reflection.
spx.contract();
if (functionObject->f(spx[ihi]) > vhi) {
spx[ihi] = phi; // Undo contraction.
spx.reduce();
} // else contraction ok.
} // else reflection ok
spx.high(&vhi);
spx.low(&vlo);
diff = vhi - vlo;
if (diff < accf)
if (spx.size() < accx)
break;
}
init = spx[spx.low()];
return vlo;
}

Member Data Documentation

std::vector<LandmarkDataEntry> CoordCalcFunction::landmarks
private

Definition at line 65 of file Nps.h.

Referenced by f().


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