CDistribution Class Reference

A class representing a distribution that can be saved to file. More...

#include <Distribution.h>

Collaboration diagram for CDistribution:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 CDistribution ()
 CDistribution (double loc, double sc, double sh)
virtual ~CDistribution ()
 CDistribution (const CDistribution &dist)
void Serialize (CArchive &ar)
double GenKeepingCoV (double newLocation)
double Generate ()
void setShape (double sh)
void setScale (double sc)
void setLocation (double loc)
void setDistributionID (WORD id)
WORD getDistributionID () const
double getShape () const
double getScale () const
double getLocation () const
CDistributionoperator= (const CDistribution &dist)

Private Member Functions

double GenerateExponential ()
double GenerateLogNormal ()
double GenerateGamma ()
double GenerateGumbel ()
double GeneratePoisson ()
double GenerateGEV ()
double GenerateNormal ()
double BoxMuller ()

Private Attributes

const double PI
WORD m_DistributionID
double m_Location
double m_Scale
double m_Shape

Static Private Attributes

static MTRand m_RNG


Detailed Description

A class representing a distribution that can be saved to file.

Definition at line 18 of file Distribution.h.


Constructor & Destructor Documentation

CDistribution::CDistribution (  ) 

Definition at line 19 of file Distribution.cpp.

References DIST_NORMAL.

00019                             :PI(3.14159265359)
00020 {
00021         m_DistributionID = DIST_NORMAL;
00022         m_Location = 10.0;
00023         m_Scale = 2.0;
00024         m_Shape = 0.0;
00025 }

CDistribution::CDistribution ( double  loc,
double  sc,
double  sh 
)

Definition at line 27 of file Distribution.cpp.

References DIST_NORMAL, m_DistributionID, m_Location, m_Scale, and m_Shape.

00027                                                             :PI(3.14159265359)
00028 {
00029         m_DistributionID = DIST_NORMAL;
00030         m_Location = loc;
00031         m_Scale = sc;
00032         m_Shape = sh;
00033 }

CDistribution::~CDistribution (  )  [virtual]

Definition at line 35 of file Distribution.cpp.

00036 {
00037 
00038 }

CDistribution::CDistribution ( const CDistribution dist  ) 

Definition at line 40 of file Distribution.cpp.

References getDistributionID(), getLocation(), getScale(), getShape(), setDistributionID(), setLocation(), setScale(), and setShape().

00040                                                      :PI(3.14159265359)
00041 {
00042         this->setDistributionID( dist.getDistributionID() );
00043         this->setLocation( dist.getLocation() );
00044         this->setScale( dist.getScale() );
00045         this->setShape( dist.getShape() );
00046 }

Here is the call graph for this function:


Member Function Documentation

void CDistribution::Serialize ( CArchive &  ar  ) 

Definition at line 69 of file Distribution.cpp.

References m_DistributionID, m_Location, m_Scale, and m_Shape.

Referenced by CParameter::Serialize().

00070 {
00071         if (ar.IsStoring())
00072         {
00073                 ar      << m_DistributionID
00074                         << m_Location
00075                         << m_Scale
00076                         << m_Shape;
00077         }
00078         else
00079         {
00080                 ar      >> m_DistributionID
00081                         >> m_Location
00082                         >> m_Scale
00083                         >> m_Shape;
00084         }
00085 }

double CDistribution::GenKeepingCoV ( double  newLocation  ) 

Definition at line 269 of file Distribution.cpp.

References Generate(), m_Location, and m_Scale.

Referenced by CParameter::GenKeepingCoV().

00270 {
00271         const double zero = 0.0001;
00272         double val = m_Location;
00273         if( (m_Scale >  zero || m_Scale < -zero) && (m_Location >  zero || m_Location < -zero) )
00274         {
00275                 double CoV = m_Scale / m_Location;
00276                 double OldScale = m_Scale;
00277                 double OldLocation = m_Location;
00278                 
00279                 // set new params & generate new value
00280                 m_Scale = newLocation * CoV;
00281                 m_Location = newLocation;
00282                 val = Generate();
00283                 // restore old params
00284                 m_Scale = OldScale;
00285                 m_Location = OldLocation;
00286         }
00287         return val;
00288 }

Here is the call graph for this function:

double CDistribution::Generate (  ) 

Definition at line 141 of file Distribution.cpp.

References DIST_CONST, DIST_EXPONENTIAL, DIST_GAMMA, DIST_GEV, DIST_GUMBEL, DIST_LOGNORMAL, DIST_NORMAL, DIST_POISSON, GenerateExponential(), GenerateGamma(), GenerateGEV(), GenerateGumbel(), GenerateLogNormal(), GenerateNormal(), GeneratePoisson(), m_DistributionID, and m_Location.

Referenced by CParameter::Generate(), and GenKeepingCoV().

00142 {
00143         switch(m_DistributionID)
00144         {
00145                 case DIST_EXPONENTIAL:
00146                         return GenerateExponential();
00147                 case DIST_LOGNORMAL:
00148                         return GenerateLogNormal();
00149                 case DIST_GAMMA:
00150                         return GenerateGamma();
00151                 case DIST_GUMBEL:
00152                         return GenerateGumbel();
00153                 case DIST_POISSON:
00154                         return GeneratePoisson();
00155                 case DIST_GEV:
00156                         return GenerateGEV();
00157                 case DIST_NORMAL:
00158                         return GenerateNormal();
00159                 case DIST_CONST:
00160                         return m_Location;
00161                 default:
00162                         return m_Location;              // constant
00163         }
00164 }

Here is the call graph for this function:

void CDistribution::setShape ( double  sh  ) 

Definition at line 135 of file Distribution.cpp.

References m_Shape.

Referenced by CDistribution(), operator=(), and CTrafficConfigDlg::SetParamData().

00136 {
00137         m_Shape = sh;
00138 }

void CDistribution::setScale ( double  sc  ) 

Definition at line 130 of file Distribution.cpp.

References m_Scale.

Referenced by CDistribution(), operator=(), CParameter::SetDefaultParams(), and CTrafficConfigDlg::SetParamData().

00131 {
00132         m_Scale = sc;
00133 }

void CDistribution::setLocation ( double  loc  ) 

Definition at line 125 of file Distribution.cpp.

References m_Location.

Referenced by CDistribution(), operator=(), CParameter::SetDefaultParams(), and CTrafficConfigDlg::SetParamData().

00126 {
00127         m_Location = loc;
00128 }

void CDistribution::setDistributionID ( WORD  id  ) 

Definition at line 120 of file Distribution.cpp.

References m_DistributionID.

Referenced by CDistribution(), operator=(), CParameter::SetDefaultParams(), and CTrafficConfigDlg::SetParamData().

00121 {
00122         m_DistributionID = id;
00123 }

WORD CDistribution::getDistributionID (  )  const

Definition at line 100 of file Distribution.cpp.

References m_DistributionID.

Referenced by CDistribution(), CTrafficConfigDlg::LoadRow(), and operator=().

00101 {
00102         return m_DistributionID;
00103 }

double CDistribution::getShape (  )  const

Definition at line 115 of file Distribution.cpp.

References m_Shape.

Referenced by CDistribution(), CTrafficConfigDlg::LoadRow(), and operator=().

00116 {
00117         return m_Shape;
00118 }

double CDistribution::getScale (  )  const

Definition at line 110 of file Distribution.cpp.

References m_Scale.

Referenced by CDistribution(), CTrafficConfigDlg::LoadRow(), and operator=().

00111 {
00112         return m_Scale;
00113 }

double CDistribution::getLocation (  )  const

Definition at line 105 of file Distribution.cpp.

References m_Location.

Referenced by SpeedLimit::addVehicle(), CDistribution(), CTrafficConfigDlg::LoadRow(), and operator=().

00106 {
00107         return m_Location;
00108 }       

CDistribution & CDistribution::operator= ( const CDistribution dist  ) 

Definition at line 90 of file Distribution.cpp.

References getDistributionID(), getLocation(), getScale(), getShape(), setDistributionID(), setLocation(), setScale(), and setShape().

00091 {
00092         this->setDistributionID( dist.getDistributionID() );
00093         this->setLocation( dist.getLocation() );
00094         this->setScale( dist.getScale() );
00095         this->setShape( dist.getShape() );
00096 
00097         return *this;
00098 }

Here is the call graph for this function:

double CDistribution::GenerateExponential (  )  [private]

Definition at line 169 of file Distribution.cpp.

References m_RNG, and MTRand::rand().

Referenced by Generate().

00170 {
00171         double u01 = m_RNG.rand();
00172         double val = -log(u01);
00173         return val;
00174 }

Here is the call graph for this function:

double CDistribution::GenerateLogNormal (  )  [private]

Definition at line 176 of file Distribution.cpp.

References m_Location, m_RNG, m_Scale, PI, and MTRand::rand().

Referenced by Generate().

00177 {
00178         double x[2], u[2];
00179         u[0] = m_RNG.rand();
00180         u[1] = m_RNG.rand();
00181         x[0] = m_Location + m_Scale * sqrt(-2 * log(u[0])) * cos(2 * PI * u[1]);
00182         x[1] = m_Location + m_Scale * sqrt(-2 * log(u[0])) * sin(2 * PI * u[1]);
00183         double val = exp( x[ (int)(u[1] + 0.5) ] );
00184 
00185         return val;
00186 }

Here is the call graph for this function:

double CDistribution::GenerateGamma (  )  [private]

Definition at line 188 of file Distribution.cpp.

References m_Location, m_RNG, m_Scale, and MTRand::rand().

Referenced by Generate().

00189 {
00190         double u[2];
00191         u[0] = m_RNG.rand();
00192         u[1] = m_RNG.rand();
00193         u[2] = m_RNG.rand();
00194         double val = (1/m_Location) 
00195                                         * (-log(u[2])) 
00196                                         * pow( u[0], (1/m_Scale) ) 
00197                                         / pow( u[0], (1/m_Scale) 
00198                                         + pow( u[1], (1/(1 - m_Scale)) ) );
00199         
00200         return val;
00201 }

Here is the call graph for this function:

double CDistribution::GenerateGumbel (  )  [private]

Definition at line 203 of file Distribution.cpp.

References m_Location, m_RNG, m_Scale, and MTRand::rand().

Referenced by Generate().

00204 {
00205         double u01 = m_RNG.rand();
00206         double val = m_Location - (1 / m_Scale) * log(log(1 / u01));
00207 
00208         return val;
00209 }

Here is the call graph for this function:

double CDistribution::GeneratePoisson (  )  [private]

Definition at line 211 of file Distribution.cpp.

References m_Location, m_RNG, m_Scale, PI, and MTRand::rand().

Referenced by Generate().

00212 {
00213         double x[2], u[2];
00214         u[0] = m_RNG.rand();
00215         u[1] = m_RNG.rand();
00216 
00217         double m = m_Location - 0.5;
00218         double sigma = sqrt(m_Scale);
00219 
00220         x[0] = m + sigma * sqrt(-2 * log(u[0])) * cos(2 * PI * u[1]);
00221         x[1] = m + sigma * sqrt(-2 * log(u[0])) * sin(2 * PI * u[1]);
00222         double val = x[ (int)(u[1] + 0.5) ];
00223 
00224         return val;
00225 }

Here is the call graph for this function:

double CDistribution::GenerateGEV (  )  [private]

Definition at line 227 of file Distribution.cpp.

References m_Location, m_RNG, m_Scale, m_Shape, and MTRand::rand().

Referenced by Generate().

00228 {
00229         double u01 = m_RNG.rand();
00230         double val = m_Location + m_Scale * (1 - pow(-log(u01),m_Shape)) / m_Shape;
00231 
00232         return val;
00233 }

Here is the call graph for this function:

double CDistribution::GenerateNormal (  )  [private]

Definition at line 235 of file Distribution.cpp.

References BoxMuller(), m_Location, and m_Scale.

Referenced by Generate().

00236 {
00237         return m_Location + m_Scale * BoxMuller();
00238 }

Here is the call graph for this function:

double CDistribution::BoxMuller (  )  [private]

Definition at line 240 of file Distribution.cpp.

References m_RNG, and MTRand::rand().

Referenced by GenerateNormal().

00241 {
00242         // normal random variate generator
00243         
00244         double x1, x2, w, y1;
00245         static double y2;
00246         static int use_last = 0;
00247 
00248         if (use_last)                   // use value from previous call
00249         {
00250                 y1 = y2;
00251                 use_last = 0;
00252         }
00253         else
00254         {
00255                 do {
00256                         x1 = 2.0 * m_RNG.rand() - 1.0;
00257                         x2 = 2.0 * m_RNG.rand() - 1.0;
00258                         w = x1 * x1 + x2 * x2;
00259                 } while ( w >= 1.0 );
00260 
00261                 w = sqrt( (-2.0 * log( w ) ) / w );
00262                 y1 = x1 * w;
00263                 y2 = x2 * w;
00264                 use_last = 1;
00265         }
00266         return( y1 );
00267 }

Here is the call graph for this function:


Member Data Documentation

MTRand CDistribution::m_RNG [static, private]

const double CDistribution::PI [private]

Definition at line 67 of file Distribution.h.

Referenced by GenerateLogNormal(), and GeneratePoisson().

double CDistribution::m_Location [private]

double CDistribution::m_Scale [private]

double CDistribution::m_Shape [private]

Definition at line 72 of file Distribution.h.

Referenced by CDistribution(), GenerateGEV(), getShape(), Serialize(), and setShape().


The documentation for this class was generated from the following files:

Generated on Wed Aug 20 00:48:42 2008 for EvolveTraffic by  doxygen 1.5.6