• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/diffusion3/filters/gear/gear_tools.hh

00001 //
00002 // gear_tools.hh  : GEAR Tools Include File
00003 // authors        : Yan Yu and Fabio Silva
00004 //
00005 // Copyright (C) 2000-2002 by the University of Southern California
00006 // Copyright (C) 2000-2002 by the University of California
00007 // $Id: gear_tools.hh,v 1.2 2005/09/13 04:53:48 tomh Exp $
00008 //
00009 // This program is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License,
00011 // version 2, as published by the Free Software Foundation.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License along
00019 // with this program; if not, write to the Free Software Foundation, Inc.,
00020 // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00021 //
00022 // Linking this file statically or dynamically with other modules is making
00023 // a combined work based on this file.  Thus, the terms and conditions of
00024 // the GNU General Public License cover the whole combination.
00025 //
00026 // In addition, as a special exception, the copyright holders of this file
00027 // give you permission to combine this file with free software programs or
00028 // libraries that are released under the GNU LGPL and with code included in
00029 // the standard release of ns-2 under the Apache 2.0 license or under
00030 // otherwise-compatible licenses with advertising requirements (or modified
00031 // versions of such code, with unchanged license).  You may copy and
00032 // distribute such a system following the terms of the GNU GPL for this
00033 // file and the licenses of the other code concerned, provided that you
00034 // include the source code of that other code when and as the GNU GPL
00035 // requires distribution of source code.
00036 //
00037 // Note that people who make modified versions of this file are not
00038 // obligated to grant this special exception for their modified versions;
00039 // it is their choice whether to do so.  The GNU General Public License
00040 // gives permission to release a modified version without this exception;
00041 // this exception also makes it possible to release a modified version
00042 // which carries forward this exception.
00043 
00044 #ifndef _GEAR_TOOLS_HH_
00045 #define _GEAR_TOOLS_HH_
00046 
00047 #include <math.h>
00048 #include "diffapp.hh"
00049 
00050 #define FAIL                      -1
00051 #define INITIAL_HEURISTIC_VALUE   -1
00052 #define FORWARD_TABLE_SIZE        100
00053 #define LEARNED_COST_TABLE_SIZE   1000
00054 
00055 #define GEO_HEURISTIC_VALUE_UPDATE_THRESHOLD 2
00056 
00057 #define ABS(x)          ((x) >= 0 ? (x): -(x))
00058 
00059 class HeuristicValue {
00060 public:
00061   HeuristicValue(double dst_longitude, double dst_latitude,
00062                  double heuristic_value) : dst_longitude_(dst_longitude),
00063                                            dst_latitude_(dst_latitude),
00064                                            heuristic_value_(heuristic_value)
00065   {};
00066 
00067   double dst_longitude_;
00068   double dst_latitude_;
00069   double heuristic_value_;
00070 };
00071 
00072 class GeoLocation {
00073 public:
00074   void operator= (GeoLocation loc)
00075   {
00076     longitude_ = loc.longitude_;
00077     latitude_ = loc.latitude_;
00078   }
00079   void output()
00080   {
00081     DiffPrint(DEBUG_IMPORTANT, "(%f, %f)", longitude_, latitude_ );
00082   }
00083 
00084   double longitude_;
00085   double latitude_;
00086 };
00087 
00088 class HeuristicValueEntry {
00089 public:
00090   HeuristicValueEntry() {
00091     heuristic_value_ = INITIAL_HEURISTIC_VALUE;
00092   }
00093 
00094   GeoLocation dst_;
00095   double heuristic_value_;
00096 };
00097 
00098 class LearnedCostEntry {
00099 public:
00100   LearnedCostEntry() {
00101     learned_cost_value_ = INITIAL_HEURISTIC_VALUE;
00102   }
00103 
00104   int node_id_;
00105   GeoLocation dst_;
00106   double learned_cost_value_;
00107 };
00108 
00109 //local forwarding table at each node
00110 class HeuristicValueTable {
00111 public:
00112   HeuristicValueTable() {num_entries_ = 0; first_ = -1; last_ = -1;}
00113 
00114   HeuristicValueEntry table_[FORWARD_TABLE_SIZE];
00115 
00116   int retrieveEntry(GeoLocation  *dst);
00117   inline int numEntries() {return num_entries_;}
00118 
00119   void addEntry(GeoLocation dst, double heuristic_value);
00120   bool updateEntry(GeoLocation dst, double heuristic_value);
00121   //the return value of UpdateEntry is if there is significant change
00122   //compared to its old value, if there is(i.e., either the change
00123   //pass some threshold-GEO_H_VALUE_UPDATE_THRE or it is a new entry),
00124   //then return TRUE, o/w return FALSE;
00125   int next(int i) {return ((i+1) % FORWARD_TABLE_SIZE);}
00126   int last() {return last_;}
00127 
00128 private:
00129   int num_entries_;
00130   int first_;
00131   int last_;
00132 };
00133 
00134 // Local forwarding table
00135 class LearnedCostTable {
00136 public:
00137   LearnedCostTable() {num_entries_ = 0; first_ = -1; last_ = -1;}
00138 
00139   LearnedCostEntry table_[LEARNED_COST_TABLE_SIZE];
00140 
00141   int retrieveEntry(int neighbor_id, GeoLocation *dst);
00142   inline int numEntries() {return num_entries_;}
00143 
00144   void addEntry(int neighbor_id, GeoLocation dst, double learned_cost);
00145   void updateEntry(int neighbor_id, GeoLocation dst, double learned_cost);
00146   int next(int i) {return ((i+1) % LEARNED_COST_TABLE_SIZE);}
00147   int last() {return last_;}
00148 
00149 private:
00150   int num_entries_;
00151   int first_;
00152   int last_;
00153 };
00154 
00155 double Distance(double long1, double lat1, double long2, double lat2);
00156 bool IsSameLocation(GeoLocation src, GeoLocation dst);
00157 
00158 #endif // !_GEAR_TOOLS_HH_

Generated on Tue Aug 10 2010 16:16:06 for ns-2.33 by  doxygen 1.7.1