• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/tools/ranvar.h

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: /cvsroot/nsnam/ns-2/tools/ranvar.h,v 1.18 2008/02/01 21:39:43 tom_henderson 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 ErlangRandomVariable : public RandomVariable {
00097  public:
00098         virtual double value();
00099         ErlangRandomVariable();
00100         ErlangRandomVariable(double, int);
00101         virtual inline double avg() { return k_/lambda_; };
00102  private:
00103         double lambda_;
00104         int    k_;
00105 };
00106 
00107 
00108 class GammaRandomVariable : public RandomVariable {
00109  public:
00110         virtual double value();
00111         GammaRandomVariable();
00112         GammaRandomVariable(double, double);
00113         virtual inline double avg() { return alpha_*beta_; };
00114  private:
00115         double alpha_;
00116         double beta_;
00117 };
00118 
00119 
00120 class ParetoRandomVariable : public RandomVariable {
00121  public:
00122         virtual double value();
00123         ParetoRandomVariable();
00124         ParetoRandomVariable(double, double);
00125         double* avgp() { return &avg_; };
00126         double* shapep() { return &shape_; };
00127         virtual inline double avg()     { return avg_; };
00128         double shape()  { return shape_; };
00129         void setavg(double d)   { avg_ = d; };
00130         void setshape(double d) { shape_ = d; };
00131  private:
00132         double avg_;
00133         double shape_;
00134         double scale_;
00135 };
00136 
00137 class ParetoIIRandomVariable : public RandomVariable {
00138  public:
00139         virtual double value();
00140         ParetoIIRandomVariable();
00141         ParetoIIRandomVariable(double, double);
00142         double* avgp() { return &avg_; };
00143         double* shapep() { return &shape_; };
00144         virtual inline double avg()   { return avg_; };
00145         double shape()   { return shape_; };
00146         void setavg(double d)  { avg_ = d; };
00147         void setshape(double d)  { shape_ = d; };
00148  private:
00149         double avg_;
00150         double shape_;
00151         double scale_;
00152 };
00153 
00154 class NormalRandomVariable : public RandomVariable {
00155  public:
00156         virtual double value();
00157         NormalRandomVariable();
00158         inline double* avgp() { return &avg_; };
00159         inline double* stdp() { return &std_; };
00160         virtual inline double avg()     { return avg_; };
00161         inline double std()     { return std_; };
00162         inline void setavg(double d)    { avg_ = d; };
00163         inline void setstd(double d)    { std_ = d; };
00164  private:
00165         double avg_;
00166         double std_;
00167 };
00168 
00169 class LogNormalRandomVariable : public RandomVariable {
00170 public:
00171         virtual double value();
00172         LogNormalRandomVariable();
00173         inline double* avgp() { return &avg_; };
00174         inline double* stdp() { return &std_; };
00175         virtual inline double avg()     { return avg_; };
00176         inline double std()     { return std_; };
00177         inline void setavg(double d)    { avg_ = d; };
00178         inline void setstd(double d)    { std_ = d; };
00179 private:
00180         double avg_;
00181         double std_;
00182 };
00183 
00184 class ConstantRandomVariable : public RandomVariable {
00185  public:
00186         virtual double value();
00187         virtual double avg(){ return val_;}
00188         ConstantRandomVariable();
00189         ConstantRandomVariable(double);
00190         double* valp() { return &val_; };
00191         double val() { return val_; };
00192         void setval(double d) { val_ = d; };
00193  private:
00194         double val_;
00195 };
00196 
00197 class HyperExponentialRandomVariable : public RandomVariable {
00198  public:
00199         virtual double value();
00200         HyperExponentialRandomVariable();
00201         HyperExponentialRandomVariable(double, double);
00202         double* avgp()  { return &avg_; };
00203         double* covp()  { return &cov_; };
00204         virtual double avg()    { return avg_; };
00205         double cov()    { return cov_; };
00206         void setavg(double d)   { avg_ = d; };
00207         void setcov(double d)   { cov_ = d; };
00208  private:
00209         double avg_;
00210         double cov_;
00211         double alpha_;
00212 };
00213 
00214 class WeibullRandomVariable : public RandomVariable {
00215 public:
00216         virtual double value();
00217         virtual double avg();
00218         WeibullRandomVariable();
00219         WeibullRandomVariable(double shape, double scale);
00220         WeibullRandomVariable(double shape, double scale, RNG* rng);
00221         double* shapep() { return &shape_; };
00222         double* scalep() { return &scale_; };
00223         double shape()   { return shape_; };
00224         double scale()   { return scale_; };
00225         void setshape(double d)  { shape_ = d; };       
00226         void setscale(double d)  { scale_ = d; };
00227 private:
00228         double shape_;
00229         double scale_;
00230 };
00231 
00232 
00233 #define INTER_DISCRETE 0        // no interpolation (discrete)
00234 #define INTER_CONTINUOUS 1      // linear interpolation
00235 #define INTER_INTEGRAL 2        // linear interpolation and round up
00236 
00237 struct CDFentry {
00238         double cdf_;
00239         double val_;
00240 };
00241 
00242 class EmpiricalRandomVariable : public RandomVariable {
00243 public:
00244         virtual double value();
00245         virtual double interpolate(double u, double x1, double y1, double x2, double y2);
00246         virtual double avg(){ return value(); } // junk
00247         EmpiricalRandomVariable();
00248         double& minCDF() { return minCDF_; }
00249         double& maxCDF() { return maxCDF_; }
00250         int loadCDF(const char* filename);
00251 
00252 protected:
00253         int command(int argc, const char*const* argv);
00254         int lookup(double u);
00255 
00256         double minCDF_;         // min value of the CDF (default to 0)
00257         double maxCDF_;         // max value of the CDF (default to 1)
00258         int interpolation_;     // how to interpolate data (INTER_DISCRETE...)
00259         int numEntry_;          // number of entries in the CDF table
00260         int maxEntry_;          // size of the CDF table (mem allocation)
00261         CDFentry* table_;       // CDF table of (val_, cdf_)
00262 };
00263 
00264 #endif
00265 
00266 
00267 
00268 

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