OverSim
SVivaldi.cc
Go to the documentation of this file.
1 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH)
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 
24 #include <cfloat>
25 
26 #include <NeighborCache.h>
27 
28 #include "SVivaldi.h"
29 
30 
31 void SVivaldi::init(NeighborCache* neighborCache)
32 {
33  Vivaldi::init(neighborCache);
34 
35  lossC = neighborCache->par("svivaldiLossConst");
36  lossResetLimit = neighborCache->par("svivaldiLossResetLimit");
37 
38  loss = 0;
39  WATCH(loss);
40 }
41 
42 
43 double SVivaldi::calcError(const simtime_t& rtt, double dist, double weight)
44 {
45  // get avg absolute prediction error
47 
48  // update weighted moving average of local error
49  return (sum * errorC) + ownCoords->getError() * (1 - errorC);
50 }
51 
52 
53 double SVivaldi::calcDelta(const simtime_t& rtt, double dist, double weight)
54 {
55  // calculate loss factor
56  loss = lossC + (1 - lossC) * loss;
57  if(fabs(dist - SIMTIME_DBL(rtt)) > lossResetLimit) loss = 0.0;
58 
59  return coordC * weight * (1 - loss);
60 }