ranvar.h

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) Xerox Corporation 1997. All rights reserved.
00004  *  
00005  * This program is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU General Public License as published by the
00007  * Free Software Foundation; either version 2 of the License, or (at your
00008  * option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  * Linking this file statically or dynamically with other modules is making
00020  * a combined work based on this file.  Thus, the terms and conditions of
00021  * the GNU General Public License cover the whole combination.
00022  *
00023  * In addition, as a special exception, the copyright holders of this file
00024  * give you permission to combine this file with free software programs or
00025  * libraries that are released under the GNU LGPL and with code included in
00026  * the standard release of ns-2 under the Apache 2.0 license or under
00027  * otherwise-compatible licenses with advertising requirements (or modified
00028  * versions of such code, with unchanged license).  You may copy and
00029  * distribute such a system following the terms of the GNU GPL for this
00030  * file and the licenses of the other code concerned, provided that you
00031  * include the source code of that other code when and as the GNU GPL
00032  * requires distribution of source code.
00033  *
00034  * Note that people who make modified versions of this file are not
00035  * obligated to grant this special exception for their modified versions;
00036  * it is their choice whether to do so.  The GNU General Public License
00037  * gives permission to release a modified version without this exception;
00038  * this exception also makes it possible to release a modified version
00039  * which carries forward this exception.
00040  *
00041  * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tools/ranvar.h,v 1.16 2005/08/26 05:05:31 tomh Exp $ (Xerox)
00042  */
00043 
00044 #ifndef ns_ranvar_h
00045 #define ns_ranvar_h
00046 
00047 /* XXX still need to clean up dependencies among parameters such that
00048  * when one parameter is changed, other parameters are recomputed as
00049  * appropriate.
00050  */
00051 
00052 #include "random.h"
00053 #include "rng.h"
00054 
00055 class RandomVariable : public TclObject {
00056  public:
00057     virtual double value() = 0;
00058     virtual double avg() = 0;
00059     int command(int argc, const char*const* argv);
00060     RandomVariable();
00061     // This is added by Debojyoti Dutta 12th Oct 2000
00062     int seed(char *);
00063  protected:
00064     RNG* rng_;
00065 };
00066 
00067 class UniformRandomVariable : public RandomVariable {
00068  public:
00069     virtual double value();
00070     virtual inline double avg() { return (max_-min_)/2; };
00071     UniformRandomVariable();
00072     UniformRandomVariable(double, double);
00073     double* minp()  { return &min_; };
00074     double* maxp()  { return &max_; };
00075     double min()    { return min_; };
00076     double max()    { return max_; };
00077     void setmin(double d)   { min_ = d; };
00078     void setmax(double d)   { max_ = d; };
00079  private:
00080     double min_;
00081     double max_;
00082 };
00083 
00084 class ExponentialRandomVariable : public RandomVariable {
00085  public:
00086     virtual double value();
00087     ExponentialRandomVariable();
00088     ExponentialRandomVariable(double);
00089     double* avgp() { return &avg_; };
00090     virtual inline double avg() { return avg_; };
00091     void setavg(double d) { avg_ = d; };
00092  private:
00093     double avg_;
00094 };
00095 
00096 class ParetoRandomVariable : public RandomVariable {
00097  public:
00098     virtual double value();
00099     ParetoRandomVariable();
00100     ParetoRandomVariable(double, double);
00101     double* avgp() { return &avg_; };
00102     double* shapep() { return &shape_; };
00103     virtual inline double avg() { return avg_; };
00104     double shape()  { return shape_; };
00105     void setavg(double d)   { avg_ = d; };
00106     void setshape(double d) { shape_ = d; };
00107  private:
00108     double avg_;
00109     double shape_;
00110     double scale_;
00111 };
00112 
00113 class ParetoIIRandomVariable : public RandomVariable {
00114  public:
00115         virtual double value();
00116         ParetoIIRandomVariable();
00117         ParetoIIRandomVariable(double, double);
00118         double* avgp() { return &avg_; };
00119         double* shapep() { return &shape_; };
00120         virtual inline double avg()   { return avg_; };
00121         double shape()   { return shape_; };
00122         void setavg(double d)  { avg_ = d; };
00123         void setshape(double d)  { shape_ = d; };
00124  private:
00125         double avg_;
00126         double shape_;
00127         double scale_;
00128 };
00129 
00130 class NormalRandomVariable : public RandomVariable {
00131  public:
00132         virtual double value();
00133         NormalRandomVariable();
00134         inline double* avgp() { return &avg_; };
00135         inline double* stdp() { return &std_; };
00136         virtual inline double avg()     { return avg_; };
00137         inline double std()     { return std_; };
00138         inline void setavg(double d)    { avg_ = d; };
00139         inline void setstd(double d)    { std_ = d; };
00140  private:
00141         double avg_;
00142         double std_;
00143 };
00144 
00145 class LogNormalRandomVariable : public RandomVariable {
00146 public:
00147         virtual double value();
00148         LogNormalRandomVariable();
00149         inline double* avgp() { return &avg_; };
00150         inline double* stdp() { return &std_; };
00151         virtual inline double avg()     { return avg_; };
00152         inline double std()     { return std_; };
00153         inline void setavg(double d)    { avg_ = d; };
00154         inline void setstd(double d)    { std_ = d; };
00155 private:
00156         double avg_;
00157         double std_;
00158 };
00159 
00160 class ConstantRandomVariable : public RandomVariable {
00161  public:
00162     virtual double value();
00163     virtual double avg(){ return val_;}
00164     ConstantRandomVariable();
00165     ConstantRandomVariable(double);
00166     double* valp() { return &val_; };
00167     double val() { return val_; };
00168     void setval(double d) { val_ = d; };
00169  private:
00170     double val_;
00171 };
00172 
00173 class HyperExponentialRandomVariable : public RandomVariable {
00174  public:
00175     virtual double value();
00176     HyperExponentialRandomVariable();
00177     HyperExponentialRandomVariable(double, double);
00178     double* avgp()  { return &avg_; };
00179     double* covp()  { return &cov_; };
00180     virtual double avg()    { return avg_; };
00181     double cov()    { return cov_; };
00182     void setavg(double d)   { avg_ = d; };
00183     void setcov(double d)   { cov_ = d; };
00184  private:
00185     double avg_;
00186     double cov_;
00187     double alpha_;
00188 };
00189 
00190 
00191 #define INTER_DISCRETE 0    // no interpolation (discrete)
00192 #define INTER_CONTINUOUS 1  // linear interpolation
00193 #define INTER_INTEGRAL 2    // linear interpolation and round up
00194 
00195 struct CDFentry {
00196     double cdf_;
00197     double val_;
00198 };
00199 
00200 class EmpiricalRandomVariable : public RandomVariable {
00201 public:
00202     virtual double value();
00203     virtual double interpolate(double u, double x1, double y1, double x2, double y2);
00204     virtual double avg(){ return value(); } // junk
00205     EmpiricalRandomVariable();
00206     double& minCDF() { return minCDF_; }
00207     double& maxCDF() { return maxCDF_; }
00208     int loadCDF(const char* filename);
00209 
00210 protected:
00211     int command(int argc, const char*const* argv);
00212     int lookup(double u);
00213 
00214     double minCDF_;     // min value of the CDF (default to 0)
00215     double maxCDF_;     // max value of the CDF (default to 1)
00216     int interpolation_; // how to interpolate data (INTER_DISCRETE...)
00217     int numEntry_;      // number of entries in the CDF table
00218     int maxEntry_;      // size of the CDF table (mem allocation)
00219     CDFentry* table_;   // CDF table of (val_, cdf_)
00220 };
00221 
00222 #endif
00223 
00224 
00225 
00226 

Generated on Tue Mar 6 16:47:49 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6