![]() |
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. 16, 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 <WNS/distribution/Operation.hpp> 00029 00030 using namespace wns::distribution; 00031 using namespace wns::distribution::operation; 00032 00033 STATIC_FACTORY_REGISTER_WITH_CREATOR(ADD, Distribution, "ADD", wns::PyConfigViewCreator); 00034 STATIC_FACTORY_REGISTER_WITH_CREATOR(MUL, Distribution, "MUL", wns::PyConfigViewCreator); 00035 STATIC_FACTORY_REGISTER_WITH_CREATOR(SUB, Distribution, "SUB", wns::PyConfigViewCreator); 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(DIV, Distribution, "DIV", wns::PyConfigViewCreator); 00037 STATIC_FACTORY_REGISTER_WITH_CREATOR(Above, Distribution, "ABOVE", wns::PyConfigViewCreator); 00038 STATIC_FACTORY_REGISTER_WITH_CREATOR(Below, Distribution, "BELOW", wns::PyConfigViewCreator); 00039 00040 STATIC_FACTORY_REGISTER_WITH_CREATOR(ADD, Distribution, "ADD", wns::distribution::RNGConfigCreator); 00041 STATIC_FACTORY_REGISTER_WITH_CREATOR(MUL, Distribution, "MUL", wns::distribution::RNGConfigCreator); 00042 STATIC_FACTORY_REGISTER_WITH_CREATOR(SUB, Distribution, "SUB", wns::distribution::RNGConfigCreator); 00043 STATIC_FACTORY_REGISTER_WITH_CREATOR(DIV, Distribution, "DIV", wns::distribution::RNGConfigCreator); 00044 STATIC_FACTORY_REGISTER_WITH_CREATOR(Above, Distribution, "ABOVE", wns::distribution::RNGConfigCreator); 00045 STATIC_FACTORY_REGISTER_WITH_CREATOR(Below, Distribution, "BELOW", wns::distribution::RNGConfigCreator); 00046 00047 Binary::Binary(const pyconfig::View& config): 00048 Distribution(), 00049 config_(config) 00050 { 00051 init(); 00052 } // Binary 00053 00054 Binary::Binary(wns::rng::RNGen* rng, const pyconfig::View& config): 00055 Distribution(rng), 00056 config_(config) 00057 { 00058 init(); 00059 } // Binary 00060 00061 void 00062 Binary::init() 00063 { 00064 pyconfig::View firstConfig(config_, "first"); 00065 std::string firstName = firstConfig.get<std::string>("__plugin__"); 00066 first_ = RNGDistributionFactory::creator(firstName)->create(getRNG(), firstConfig); 00067 00068 pyconfig::View secondConfig(config_, "second"); 00069 std::string secondName = secondConfig.get<std::string>("__plugin__"); 00070 second_ = RNGDistributionFactory::creator(secondName)->create(getRNG(), secondConfig); 00071 } 00072 00073 double 00074 ADD::operator()() 00075 { 00076 return (*first_)() + (*second_)(); 00077 } // get 00078 00079 double 00080 ADD::getMean() const 00081 { 00082 IHasMean* disOne; 00083 IHasMean* disTwo; 00084 00085 disOne = dynamic_cast<IHasMean*>(first_); 00086 assure(disOne, "First distribution does not implement getMean()"); 00087 00088 disTwo = dynamic_cast<IHasMean*>(second_); 00089 assure(disTwo, "First distribution does not implement getMean()"); 00090 00091 return disOne->getMean() + disTwo->getMean(); 00092 } // get 00093 00094 std::string 00095 ADD::paramString() const 00096 { 00097 std::ostringstream tmp; 00098 tmp << "(" << *first_ << "+" << *second_ << ")"; 00099 return tmp.str(); 00100 } 00101 00102 double 00103 MUL::operator()() 00104 { 00105 return (*first_)() * (*second_)(); 00106 } // get 00107 00108 double 00109 MUL::getMean() const 00110 { 00111 IHasMean* disOne; 00112 IHasMean* disTwo; 00113 00114 disOne = dynamic_cast<IHasMean*>(first_); 00115 assure(disOne, "First distribution does not implement getMean()"); 00116 00117 disTwo = dynamic_cast<IHasMean*>(second_); 00118 assure(disTwo, "First distribution does not implement getMean()"); 00119 00120 return disOne->getMean() * disTwo->getMean(); 00121 } // get 00122 00123 std::string 00124 MUL::paramString() const 00125 { 00126 std::ostringstream tmp; 00127 tmp << "(" << *first_ << "*" << *second_ << ")"; 00128 return tmp.str(); 00129 } 00130 00131 00132 double 00133 SUB::operator()() 00134 { 00135 return (*first_)() - (*second_)(); 00136 } // get 00137 00138 double 00139 SUB::getMean() const 00140 { 00141 IHasMean* disOne; 00142 IHasMean* disTwo; 00143 00144 disOne = dynamic_cast<IHasMean*>(first_); 00145 assure(disOne, "First distribution does not implement getMean()"); 00146 00147 disTwo = dynamic_cast<IHasMean*>(second_); 00148 assure(disTwo, "First distribution does not implement getMean()"); 00149 00150 return disOne->getMean() - disTwo->getMean(); 00151 } // get 00152 00153 std::string 00154 SUB::paramString() const 00155 { 00156 std::ostringstream tmp; 00157 tmp << "(" << *first_ << "-" << *second_ << ")"; 00158 return tmp.str(); 00159 } 00160 00161 double 00162 DIV::operator()() 00163 { 00164 return (*first_)() / (*second_)(); 00165 } // get 00166 00167 double 00168 DIV::getMean() const 00169 { 00170 IHasMean* disOne; 00171 IHasMean* disTwo; 00172 00173 disOne = dynamic_cast<IHasMean*>(first_); 00174 assure(disOne, "First distribution does not implement getMean()"); 00175 00176 disTwo = dynamic_cast<IHasMean*>(second_); 00177 assure(disTwo, "First distribution does not implement getMean()"); 00178 00179 assure(disTwo->getMean() != 0.0, "Distributions::DIV: divide by zero"); 00180 return disOne->getMean() / disTwo->getMean(); 00181 } // get 00182 00183 std::string 00184 DIV::paramString() const 00185 { 00186 std::ostringstream tmp; 00187 tmp << "(" << *first_ << "/" << *second_ << ")"; 00188 return tmp.str(); 00189 } 00190 00191 00192 DistributionAndFloat::DistributionAndFloat(const pyconfig::View& config) : 00193 Distribution(), 00194 config_(config) 00195 { 00196 init(); 00197 } 00198 00199 DistributionAndFloat::DistributionAndFloat(wns::rng::RNGen* rng, const pyconfig::View& config) : 00200 Distribution(rng), 00201 config_(config) 00202 { 00203 init(); 00204 } 00205 00206 void 00207 DistributionAndFloat::init() 00208 { 00209 pyconfig::View subjectConfig(config_, "subject"); 00210 std::string subjectName = subjectConfig.get<std::string>("__plugin__"); 00211 subject_ = RNGDistributionFactory::creator(subjectName)->create(getRNG(), subjectConfig); 00212 00213 arg_ = config_.get<double>("arg"); 00214 } 00215 00216 double 00217 Above::operator()() 00218 { 00219 double result; 00220 00221 do { 00222 result = (*subject_)(); 00223 } while(result <= arg_); 00224 00225 return result; 00226 } // get 00227 00228 std::string 00229 Above::paramString() const 00230 { 00231 std::ostringstream tmp; 00232 tmp << "Above(" << *subject_ << "," << arg_ << ")"; 00233 return tmp.str(); 00234 } 00235 00236 double 00237 Below::operator()() 00238 { 00239 double result; 00240 00241 do { 00242 result = (*subject_)(); 00243 } while(result >= arg_); 00244 00245 return result; 00246 } // get 00247 00248 std::string 00249 Below::paramString() const 00250 { 00251 std::ostringstream tmp; 00252 tmp << "Below(" << *subject_ << "," << arg_ << ")"; 00253 return tmp.str(); 00254 } 00255 00256 00257 00258 /* 00259 Local Variables: 00260 mode: c++ 00261 fill-column: 80 00262 c-basic-offset: 8 00263 c-comment-only-line-offset: 0 00264 c-tab-always-indent: t 00265 indent-tabs-mode: t 00266 tab-width: 8 00267 End: 00268 */ 00269
1.5.5