Alex Bikfalvi
SimStream Documentation
ModelChannelFlat3Cat.cpp
00001 #include "Headers.h" 00002 #include "ModelChannelFlat3Cat.h" 00003 #include "Rand.h" 00004 00005 CModelChannelFlat3Cat::CModelChannelFlat3Cat( 00006 __uint32 numChannels, 00007 __uint32 numPopular1, 00008 __uint32 numPopular2, 00009 double probPopular1, 00010 double probPopular2 00011 ) : CModelChannelData(numChannels) 00012 { 00013 this->numPopular1 = numPopular1; 00014 this->numPopular2 = numPopular1+numPopular2; 00015 this->probPopular1 = (__uint32)(0xFFFFFFFF * probPopular1); 00016 this->probPopular2 = (__uint32)(0xFFFFFFFF * (probPopular1+probPopular2)); 00017 } 00018 00019 void CModelChannelFlat3Cat::GenerateUptime(__uint32 &newCh, __time &duration) 00020 { 00021 __uint32 pr = CRand::GenerateUInt32(); 00022 __uint32 ch = CRand::GenerateUInt32(); 00023 __uint32 dindex; 00024 00025 //#ifndef DETRAND 00026 // rand_s(&pr); 00027 // rand_s(&ch); 00028 //#else 00029 // pr = (((__uint32)rand()) << 17) | (((__uint32)rand()) << 2) | (((__uint32)rand()) & 0x3); 00030 // ch = (((__uint32)rand()) << 17) | (((__uint32)rand()) << 2) | (((__uint32)rand()) & 0x3); 00031 //#endif 00032 00033 dindex = channelCdfIndex[pr >> 15]; 00034 duration = channelCdf[dindex][0]; 00035 00036 pr = CRand::GenerateUInt32(); 00037 //#ifndef DETRAND 00038 // rand_s(&pr); 00039 //#else 00040 // pr = (((__uint32)rand()) << 17) | (((__uint32)rand()) << 2) | (((__uint32)rand()) & 0x3); 00041 //#endif 00042 00043 // Generate new channel (a random channel) 00044 if(pr < this->probPopular1) 00045 newCh = (__uint32)(((__uint64)ch)*this->numPopular1/0x100000000LL); 00046 else if(pr < this->probPopular2) 00047 newCh = this->numPopular1 + (__uint32)(((__uint64)ch)*(this->numPopular2-this->numPopular1)/0x100000000LL); 00048 else 00049 newCh = this->numPopular2 + (__uint32)(((__uint64)ch)*(this->numChannels-this->numPopular2)/0x100000000LL); 00050 00051 assert(newCh < this->numChannels); 00052 } 00053 00054 void CModelChannelFlat3Cat::GenerateUptime(__uint32 oldCh, __time oldDuration, __uint32 &newCh, __time &duration) 00055 { 00056 __uint32 pr = CRand::GenerateUInt32(); 00057 __uint32 prb = CRand::GenerateUInt32(); 00058 __uint32 ch = CRand::GenerateUInt32(); 00059 __uint32 dindex; 00060 00061 //#ifndef DETRAND 00062 // rand_s(&pr); 00063 // rand_s(&ch); 00064 // rand_s(&prb); 00065 //#else 00066 // pr = (((__uint32)rand()) << 17) | (((__uint32)rand()) << 2) | (((__uint32)rand()) & 0x3); 00067 // ch = (((__uint32)rand()) << 17) | (((__uint32)rand()) << 2) | (((__uint32)rand()) & 0x3); 00068 // prb = (((__uint32)rand()) << 17) | (((__uint32)rand()) << 2) | (((__uint32)rand()) & 0x3); 00069 //#endif 00070 00071 dindex = channelCdfIndex[pr >> 15]; 00072 duration = channelCdf[dindex][0]; 00073 00074 pr = CRand::GenerateUInt32(); 00075 //#ifndef DETRAND 00076 // rand_s(&pr); 00077 //#else 00078 // pr = (((__uint32)rand()) << 17) | (((__uint32)rand()) << 2) | (((__uint32)rand()) & 0x3); 00079 //#endif 00080 00081 // Switch 00082 if(pr < this->probPopular1) 00083 { 00084 // Switch to category 1 00085 if(oldCh < this->numPopular1) 00086 { 00087 // Switch from category 1 00088 newCh = (__uint32)(((__uint64)ch)*(this->numPopular1-1)/0x100000000LL); 00089 if(newCh >= oldCh) newCh++; 00090 } 00091 else 00092 // Switch from category 2 or 3 00093 newCh = (__uint32)(((__uint64)ch)*(this->numPopular1)/0x100000000LL); 00094 } 00095 else if(pr < this->probPopular2) 00096 { 00097 // Switch to category 2 00098 if(oldCh < this->numPopular1) 00099 // Switch from category 1 00100 newCh = this->numPopular1 + (__uint32)(((__uint64)ch)*(this->numPopular2-this->numPopular1)/0x100000000LL); 00101 else if(oldCh < this->numPopular2) 00102 { 00103 // Switch from category 2 00104 newCh = this->numPopular1 + (__uint32)(((__uint64)ch)*(this->numPopular2-this->numPopular1-1)/0x100000000LL); 00105 if(newCh >= oldCh) newCh++; 00106 } 00107 else 00108 // Switch from category 3 00109 newCh = this->numPopular1 + (__uint32)(((__uint64)ch)*(this->numPopular2-this->numPopular1)/0x100000000LL); 00110 } 00111 else 00112 { 00113 // Switch to category 3 00114 if(oldCh < this->numPopular2) 00115 // Switch from category 1 or 2 00116 newCh = this->numPopular2 + (__uint32)(((__uint64)ch)*(this->numChannels-this->numPopular2)/0x100000000LL); 00117 else 00118 { 00119 // Switch from category 3 00120 newCh = this->numPopular2 + (__uint32)(((__uint64)ch)*(this->numChannels-this->numPopular2-1)/0x100000000LL); 00121 if(newCh >= oldCh) newCh++; 00122 } 00123 } 00124 00125 assert(newCh != oldCh); 00126 assert(newCh < this->numChannels); 00127 }
Last updated: February 8, 2011