![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include "MarkovBase.hpp" 00029 #include "MarkovDiscreteTime.hpp" 00030 #include "TrafficSpec.hpp" 00031 #include <WNS/logger/Logger.hpp> 00032 #include <float.h> // DBL_MAX 00033 00034 #ifndef WNS_MARKOVCHAIN_MARKOVDISCRETETIMETRAFFIC_HPP 00035 #define WNS_MARKOVCHAIN_MARKOVDISCRETETIMETRAFFIC_HPP 00036 namespace wns { namespace markovchain { 00037 00044 class MarkovDiscreteTimeTraffic : 00045 public MarkovDiscreteTime<TrafficSpec> 00046 00047 { 00048 public: 00053 MarkovDiscreteTimeTraffic(int _numberOfChains) : 00054 MarkovDiscreteTime<TrafficSpec>(_numberOfChains), 00055 rateScale(1.0), 00056 meanRate(0.0), 00057 minRate(DBL_MAX), 00058 maxRate(0.0) 00059 { 00060 MESSAGE_SINGLE(VERBOSE,logger, "MarkovDiscreteTimeTraffic() called"); 00061 } 00062 00066 ~MarkovDiscreteTimeTraffic() 00067 { 00068 } 00069 00070 00074 void 00075 readStatesFromFile (std::istream& in) 00076 { 00077 std::string line; 00078 int stateCounter = 0; 00079 vectorOfStates = std::vector<TrafficSpec>(numberOfStates); 00080 00081 while (in.good() && (stateCounter<numberOfStates)) { 00082 std::getline(in, line); 00083 int comment_pos=line.find_first_not_of(" \t"); 00084 if (line[comment_pos] == '#') { // comment 00085 } else { // not a comment line 00086 00087 MESSAGE_SINGLE(NORMAL,logger, "readStatesFromFile(#" << stateCounter <<"): \""<< line << "\""); 00088 std::istringstream instream(line); 00089 int stateNumber; 00090 std::string pdf; 00091 double arg0, arg1; 00092 //double meanRate = -1.0; 00093 instream >> stateNumber; 00094 instream >> pdf; 00095 instream >> arg0; 00096 instream >> arg1; 00097 //instream >> meanRate; 00098 TrafficSpec trafficSpec = TrafficSpec(pdf,arg0,arg1); 00099 vectorOfStates[stateNumber] = trafficSpec; 00100 stateCounter++; 00101 } 00102 } 00103 } 00104 00108 virtual void 00109 calculateStateProbabilities() 00110 { 00111 // here the state probabilities are calculated: 00112 MarkovDiscreteTime<TrafficSpec>::calculateStateProbabilities(); 00113 // in this class we have the traffic properties within the state 00114 // so we can calculate more... 00115 meanRate=0.0; maxRate=0.0; minRate=DBL_MAX; 00116 for(int i=0; i<numberOfStates; i++) { 00117 double p=stateProbabilities[i]; 00118 const TrafficSpec* trafficSpec = getStateContent(i); 00119 //double meanIAT = trafficSpec->getInterArrivalTimeDistribution()->getMean(); 00120 //double meanPKS = trafficSpec->getPacketSizeDistribution()->getMean(); 00121 double stateMeanRate = rateScale * trafficSpec->getMeanRate(); 00122 MESSAGE_SINGLE(NORMAL, logger, "state[" << i << "]: p=" << p << " rate=" << stateMeanRate); 00123 meanRate += p * stateMeanRate; 00124 if (stateMeanRate<minRate) minRate=stateMeanRate; 00125 if (stateMeanRate>maxRate) maxRate=stateMeanRate; 00126 } 00127 MESSAGE_BEGIN(NORMAL, logger, m, "traffic properties (rates in bits/s):\n"); 00128 m << "mean=" << meanRate 00129 << " min=" << minRate 00130 << " max=" << maxRate; 00131 MESSAGE_END(); 00132 } 00133 00134 double getMeanRate() const 00135 { 00136 assure(minRate<DBL_MAX,"calculateStateProbabilities() not called before"); 00137 return meanRate; 00138 } 00139 00140 double getMinRate() const 00141 { 00142 assure(minRate<DBL_MAX,"calculateStateProbabilities() not called before"); 00143 return minRate; 00144 } 00145 00146 double getMaxRate() const 00147 { 00148 assure(minRate<DBL_MAX,"calculateStateProbabilities() not called before"); 00149 return maxRate; 00150 } 00151 00152 protected: 00156 double rateScale; 00157 // ^ must be known here to calculate the mean/min/max rate correctly 00158 // it is not used to scale the traffic here 00159 // because this is done in a SubGenerator 00161 double meanRate; 00163 double minRate; 00165 double maxRate; 00166 }; 00167 00168 }//markovchain 00169 }//wns 00170 #endif //WNS_MARKOVCHAIN_MARKOVDISCRETETIMETRAFFIC_HPP 00171
1.5.5