Alex Bikfalvi
SimStream Documentation
ModelChannelPowerlaw.cpp
00001 #include "Headers.h" 00002 #include "ModelChannelPowerLaw.h" 00003 #include "Rand.h" 00004 00005 CModelChannelPowerLaw::CModelChannelPowerLaw( 00006 unsigned int numChannels, 00007 double durationMin, 00008 double durationMax, 00009 double alpha 00010 ) : CModelChannel(numChannels) 00011 { 00012 assert(durationMin < durationMax); 00013 00014 this->durationMin = durationMin; 00015 this->durationMax = durationMax; 00016 this->alpha = alpha; 00017 } 00018 00019 void CModelChannelPowerLaw::GenerateUptime( 00020 unsigned int& channel, 00021 __time& duration 00022 ) 00023 { 00024 channel = CRand::Generate(this->numChannels); 00025 assert(channel < this->numChannels); 00026 double rnd = CRand::Generate(); 00027 00028 duration = pow(rnd * (pow(this->durationMax,1-this->alpha) - pow(this->durationMin,1-this->alpha)) 00029 + pow(this->durationMin, 1-this->alpha), 1/(1-this->alpha)); 00030 } 00031 00032 void CModelChannelPowerLaw::GenerateUptime( 00033 unsigned int oldChannel, 00034 __time oldDuration, 00035 unsigned int& newChannel, 00036 __time& newDuration 00037 ) 00038 { 00039 newChannel = CRand::Generate(this->numChannels-1); 00040 if(newChannel >= oldChannel) newChannel++; 00041 assert(newChannel < this->numChannels); 00042 double rnd = CRand::Generate(); 00043 00044 newDuration = pow(rnd * (pow(this->durationMax,1-this->alpha) - pow(this->durationMin,1-this->alpha)) 00045 + pow(this->durationMin, 1-this->alpha), 1/(1-this->alpha)); 00046 } 00047 00048
Last updated: February 8, 2011