Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

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  * License is granted to copy, to use, and to make and to use derivative
00006  * works for research and evaluation purposes, provided that Xerox is
00007  * acknowledged in all documentation pertaining to any such copy or derivative
00008  * work. Xerox grants no other licenses expressed or implied. The Xerox trade
00009  * name should not be used in any advertising without its written permission.
00010  *  
00011  * XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
00012  * MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE
00013  * FOR ANY PARTICULAR PURPOSE.  The software is provided "as is" without
00014  * express or implied warranty of any kind.
00015  *  
00016  * These notices must be retained in any copies of any part of this software.
00017  *
00018  * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tools/ranvar.h,v 1.15 2002/03/19 07:10:16 ddutta Exp $ (Xerox)
00019  */
00020 
00021 #ifndef ns_ranvar_h
00022 #define ns_ranvar_h
00023 
00024 /* XXX still need to clean up dependencies among parameters such that
00025  * when one parameter is changed, other parameters are recomputed as
00026  * appropriate.
00027  */
00028 
00029 #include "random.h"
00030 #include "rng.h"
00031 
00032 class RandomVariable : public TclObject {
00033  public:
00034         virtual double value() = 0;
00035         virtual double avg() = 0;
00036         int command(int argc, const char*const* argv);
00037         RandomVariable();
00038         // This is added by Debojyoti Dutta 12th Oct 2000
00039         int seed(char *);
00040  protected:
00041         RNG* rng_;
00042 };
00043 
00044 class UniformRandomVariable : public RandomVariable {
00045  public:
00046         virtual double value();
00047         virtual inline double avg() { return (max_-min_)/2; };
00048         UniformRandomVariable();
00049         UniformRandomVariable(double, double);
00050         double* minp()  { return &min_; };
00051         double* maxp()  { return &max_; };
00052         double min()    { return min_; };
00053         double max()    { return max_; };
00054         void setmin(double d)   { min_ = d; };
00055         void setmax(double d)   { max_ = d; };
00056  private:
00057         double min_;
00058         double max_;
00059 };
00060 
00061 class ExponentialRandomVariable : public RandomVariable {
00062  public:
00063         virtual double value();
00064         ExponentialRandomVariable();
00065         ExponentialRandomVariable(double);
00066         double* avgp() { return &avg_; };
00067         virtual inline double avg() { return avg_; };
00068         void setavg(double d) { avg_ = d; };
00069  private:
00070         double avg_;
00071 };
00072 
00073 class ParetoRandomVariable : public RandomVariable {
00074  public:
00075         virtual double value();
00076         ParetoRandomVariable();
00077         ParetoRandomVariable(double, double);
00078         double* avgp() { return &avg_; };
00079         double* shapep() { return &shape_; };
00080         virtual inline double avg()     { return avg_; };
00081         double shape()  { return shape_; };
00082         void setavg(double d)   { avg_ = d; };
00083         void setshape(double d) { shape_ = d; };
00084  private:
00085         double avg_;
00086         double shape_;
00087         double scale_;
00088 };
00089 
00090 class ParetoIIRandomVariable : public RandomVariable {
00091  public:
00092         virtual double value();
00093         ParetoIIRandomVariable();
00094         ParetoIIRandomVariable(double, double);
00095         double* avgp() { return &avg_; };
00096         double* shapep() { return &shape_; };
00097         virtual inline double avg()   { return avg_; };
00098         double shape()   { return shape_; };
00099         void setavg(double d)  { avg_ = d; };
00100         void setshape(double d)  { shape_ = d; };
00101  private:
00102         double avg_;
00103         double shape_;
00104         double scale_;
00105 };
00106 
00107 class NormalRandomVariable : public RandomVariable {
00108  public:
00109         virtual double value();
00110         NormalRandomVariable();
00111         inline double* avgp() { return &avg_; };
00112         inline double* stdp() { return &std_; };
00113         virtual inline double avg()     { return avg_; };
00114         inline double std()     { return std_; };
00115         inline void setavg(double d)    { avg_ = d; };
00116         inline void setstd(double d)    { std_ = d; };
00117  private:
00118         double avg_;
00119         double std_;
00120 };
00121 
00122 class LogNormalRandomVariable : public RandomVariable {
00123 public:
00124         virtual double value();
00125         LogNormalRandomVariable();
00126         inline double* avgp() { return &avg_; };
00127         inline double* stdp() { return &std_; };
00128         virtual inline double avg()     { return avg_; };
00129         inline double std()     { return std_; };
00130         inline void setavg(double d)    { avg_ = d; };
00131         inline void setstd(double d)    { std_ = d; };
00132 private:
00133         double avg_;
00134         double std_;
00135 };
00136 
00137 class ConstantRandomVariable : public RandomVariable {
00138  public:
00139         virtual double value();
00140         virtual double avg(){ return val_;}
00141         ConstantRandomVariable();
00142         ConstantRandomVariable(double);
00143         double* valp() { return &val_; };
00144         double val() { return val_; };
00145         void setval(double d) { val_ = d; };
00146  private:
00147         double val_;
00148 };
00149 
00150 class HyperExponentialRandomVariable : public RandomVariable {
00151  public:
00152         virtual double value();
00153         HyperExponentialRandomVariable();
00154         HyperExponentialRandomVariable(double, double);
00155         double* avgp()  { return &avg_; };
00156         double* covp()  { return &cov_; };
00157         virtual double avg()    { return avg_; };
00158         double cov()    { return cov_; };
00159         void setavg(double d)   { avg_ = d; };
00160         void setcov(double d)   { cov_ = d; };
00161  private:
00162         double avg_;
00163         double cov_;
00164         double alpha_;
00165 };
00166 
00167 
00168 #define INTER_DISCRETE 0        // no interpolation (discrete)
00169 #define INTER_CONTINUOUS 1      // linear interpolation
00170 #define INTER_INTEGRAL 2        // linear interpolation and round up
00171 
00172 struct CDFentry {
00173         double cdf_;
00174         double val_;
00175 };
00176 
00177 class EmpiricalRandomVariable : public RandomVariable {
00178 public:
00179         virtual double value();
00180         virtual double interpolate(double u, double x1, double y1, double x2, double y2);
00181         virtual double avg(){ return value(); } // junk
00182         EmpiricalRandomVariable();
00183         double& minCDF() { return minCDF_; }
00184         double& maxCDF() { return maxCDF_; }
00185         int loadCDF(const char* filename);
00186 
00187 protected:
00188         int command(int argc, const char*const* argv);
00189         int lookup(double u);
00190 
00191         double minCDF_;         // min value of the CDF (default to 0)
00192         double maxCDF_;         // max value of the CDF (default to 1)
00193         int interpolation_;     // how to interpolate data (INTER_DISCRETE...)
00194         int numEntry_;          // number of entries in the CDF table
00195         int maxEntry_;          // size of the CDF table (mem allocation)
00196         CDFentry* table_;       // CDF table of (val_, cdf_)
00197 };
00198 
00199 #endif
00200 
00201 
00202 
00203 

Generated on Tue Apr 20 12:14:28 2004 for NS2.26SourcesOriginal by doxygen 1.3.3