CoordCalcFunction Class Reference

Auxiliary class for coord calculation. More...

#include <Nps.h>

List of all members.

Public Member Functions

 CoordCalcFunction (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 ( std::vector< LandmarkDataEntry myLandmarks  )  [inline]

Definition at line 71 of file Nps.h.

00071 { landmarks = myLandmarks; };


Member Function Documentation

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

Definition at line 680 of file Nps.cc.

Referenced by f().

00682 {
00683     double sum_of_squares = 0.0;
00684     for (int i = 0; i < nodeCoordinates.size(); i++) {
00685         sum_of_squares += pow(landmark.coordinates[i] - nodeCoordinates[i], 2);
00686     }
00687     double result = sqrt(sum_of_squares);
00688     return result;
00689 }

double CoordCalcFunction::f ( const Vec_DP initCoordinates  )  const

Definition at line 660 of file Nps.cc.

Referenced by Simplex::high(), Simplex::low(), and simplex_min().

00661 {
00662     double sum = 0;
00663     double rel_diff = 0;
00664 
00665     for (uint i = 0; i < landmarks.size(); i++) {
00666         // Distance = RTT in ms / 2
00667         double diff = SIMTIME_DBL(landmarks[i].rtt) / 2 * 1000 -
00668             endnodeDistance(initCoordinates, landmarks[i]);
00669 
00670         if (SIMTIME_DBL(landmarks[i].rtt) != 0) {
00671             rel_diff = diff / (SIMTIME_DBL(landmarks[i].rtt) / 2 * 1000);
00672         } else {
00673             opp_error("[CBR] RTT == 0. Node is landmark? This shouldn't happen.");
00674         }
00675         sum += rel_diff * rel_diff;
00676     }
00677     return sum;
00678 }

double CoordCalcFunction::simplex_min ( CoordCalcFunction functionObject,
Vec_DP init 
) [static]

Definition at line 589 of file Nps.cc.

Referenced by Nps::computeOwnCoordinates().

00591 {
00592     double accf = 0.0000001;
00593     double accx = 0.0000001;
00594     uint32_t nmax = 30001;
00595     uint8_t dim = init.size();
00596     Simplex spx(dim);
00597 
00598     int ihi;    // Index of highest point at start of each iteration
00599     Vec_DP phi(dim);   // Highest point at start of each iteration.
00600     double vhi;    // Function value at highest point at start of each iteration.
00601     double vre;    // Function value at reflected point.
00602     double vlo, diff;  // for checking convergence.
00603     uint32_t count;
00604 
00605     // Initialize Simplex
00606     Vec_DP tmp(dim);
00607     spx.functionObject = functionObject;
00608     spx[0] = init;
00609     for (uint8_t i = 0; i < dim; i++) {
00610         tmp[i] = 1;
00611         spx[i+1] = init + tmp;
00612         tmp[i] = 0;
00613     }
00614 
00615     Vec_DP debugCoords(dim);
00616 
00617     for (count = 1; count <= nmax; count++) {
00618         /*
00619         if ((count % 10000) == 0) {
00620             std::cout << "running loop #" << count << " of " << nmax << endl;
00621             std::cout << "diff: " << diff << std::endl;
00622             std::cout << "vhi: " << vhi << std::endl;
00623             std::cout << "vlo: " << vlo << std::endl;
00624             debugCoords = spx[spx.low()];
00625             std::cout << "Coords: " << debugCoords << std::endl;
00626         }
00627         */
00628         ihi = spx.high(&vhi);
00629         phi = spx[ihi];
00630         spx.reflect();
00631         vre = functionObject->f(spx[ihi]);
00632         if (vre < functionObject->f(spx[spx.low()])) {
00633             spx[ihi] = phi;  // Undo reflection.
00634             spx.reflect_exp();
00635             vre = functionObject->f(spx[ihi]);
00636             if (vre > functionObject->f(spx[spx.low()])) {
00637                 spx[ihi] = phi;
00638                 spx.reflect();
00639             }
00640         } else if (vre >= vhi) { // Equal sign important!
00641             spx[ihi] = phi;  // Undo reflection.
00642             spx.contract();
00643             if (functionObject->f(spx[ihi]) > vhi) {
00644                 spx[ihi] = phi; // Undo contraction.
00645                 spx.reduce();
00646             } // else contraction ok.
00647         } // else reflection ok
00648 
00649         spx.high(&vhi);
00650         spx.low(&vlo);
00651         diff = vhi - vlo;
00652         if (diff < accf)
00653             if (spx.size() < accx)
00654                 break;
00655     }
00656     init = spx[spx.low()];
00657     return vlo;
00658 }


Member Data Documentation

Definition at line 65 of file Nps.h.

Referenced by CoordCalcFunction(), and f().


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

Generated on Tue Sep 8 17:26:57 2009 for OverSim by  doxygen 1.5.8