![]() |
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 #include "MarkovBase.hpp" 00028 #include "TrafficSpec.hpp" 00029 #include "MarkovContinuousTime.hpp" 00030 #include <WNS/logger/Logger.hpp> 00031 #include <float.h> // DBL_MAX 00032 00033 #ifndef WNS_MARKOVCHAIN_MARKOVCONTINUOUSTIMETRAFFIC_HPP 00034 #define WNS_MARKOVCHAIN_MARKOVCONTINUOUSTIMETRAFFIC_HPP 00035 00036 namespace wns { namespace markovchain { 00037 00044 class MarkovContinuousTimeTraffic : 00045 public MarkovContinuousTime<TrafficSpec> 00046 { 00047 public: 00052 MarkovContinuousTimeTraffic(int _numberOfChains) : 00053 MarkovContinuousTime<TrafficSpec>(_numberOfChains), 00054 rateScale(1.0), 00055 meanRate(0.0), 00056 minRate(DBL_MAX), 00057 maxRate(0.0) 00058 { 00059 MESSAGE_SINGLE(VERBOSE,logger, "MarkovContinuousTimeTraffic(C=" << _numberOfChains << ") called"); 00060 } 00061 00065 ~MarkovContinuousTimeTraffic() 00066 { 00067 MESSAGE_SINGLE(VERBOSE,logger, "~MarkovContinuousTimeTraffic() called"); 00068 } 00069 00073 void 00074 readStatesFromFile (std::istream& in) 00075 { 00076 std::string line; 00077 int stateCounter = 0; 00078 //vectorOfStates = std::vector<TrafficSpec>(numberOfStates); 00079 // ^ prepareTransitionMatrix() does allocation 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 MESSAGE_SINGLE(VERBOSE,logger, "readStatesFromFile(#"<< stateCounter <<"): \""<<line<<"\""); 00086 std::istringstream instream(line); 00087 int stateNumber; 00088 std::string pdf; 00089 double arg0, arg1; 00090 //double meanRate = -1.0; 00091 instream >> stateNumber; 00092 instream >> pdf; 00093 instream >> arg0; 00094 instream >> arg1; 00095 //instream >> meanRate; 00096 TrafficSpec trafficSpec = TrafficSpec(pdf, arg0, arg1); 00097 vectorOfStates[stateNumber] = trafficSpec; 00098 stateCounter++; 00099 } 00100 } 00101 } // readStatesFromFile 00102 00106 virtual void 00107 calculateStateProbabilities() 00108 { 00109 // here the state probabilities are calculated: 00110 MarkovContinuousTime<TrafficSpec>::calculateStateProbabilities(); 00111 // in this class we have the traffic properties within the state 00112 // so we can calculate more... 00113 meanRate=0.0; maxRate=0.0; minRate=DBL_MAX; 00114 for(int i=0; i<numberOfStates; i++) { 00115 double p=stateProbabilities[i]; 00116 const TrafficSpec* trafficSpec = getStateContent(i); 00117 //double meanIAT = trafficSpec->getInterArrivalTimeDistribution()->getMean(); 00118 //double meanPKS = trafficSpec->getPacketSizeDistribution()->getMean(); 00119 double stateMeanRate = rateScale * trafficSpec->getMeanRate(); 00120 MESSAGE_SINGLE(NORMAL, logger, "state[" << i << "]: p=" << p << " rate=" << stateMeanRate); 00121 stateMeanRate *= numberOfChains; // aggregated traffic 00122 meanRate += p * stateMeanRate; 00123 if (stateMeanRate<minRate) minRate=stateMeanRate; 00124 if (stateMeanRate>maxRate) maxRate=stateMeanRate; 00125 } 00126 MESSAGE_BEGIN(NORMAL, logger, m, "traffic properties [bits/s]:"); 00127 m << " mean=" << meanRate 00128 << " min=" << minRate 00129 << " max=" << maxRate; 00130 MESSAGE_END(); 00131 } 00132 00133 double getMeanRate() const 00134 { 00135 assure(minRate<DBL_MAX,"calculateStateProbabilities() not called before"); 00136 return meanRate; 00137 } 00138 00139 double getMinRate() const 00140 { 00141 assure(minRate<DBL_MAX,"calculateStateProbabilities() not called before"); 00142 return minRate; 00143 } 00144 00145 double getMaxRate() const 00146 { 00147 assure(minRate<DBL_MAX,"calculateStateProbabilities() not called before"); 00148 return maxRate; 00149 } 00150 00151 protected: 00155 double rateScale; 00156 // ^ must be known here to calculate the mean/min/max rate correctly 00157 // it is not used to scale the traffic here 00158 // because this is done in a SubGenerator 00160 double meanRate; 00162 double minRate; 00164 double maxRate; 00165 }; 00166 00167 }//markovchain 00168 }//wns 00169 #endif // WNS_MARKOVCHAIN_MARKOVCONTINUOUSTIMETRAFFIC_HPP 00170 00171
1.5.5