comparing with ssh://code@code.nsnam.org/repos/ns-3-dev searching for changes changeset: 4209:3f9b0bad5afb user: Gustavo J. A. M. Carneiro date: Mon Feb 02 16:50:44 2009 +0000 summary: Deserialize Normal/Gaussian random variables diff -r ef9ae8962bbb -r 3f9b0bad5afb src/core/random-variable.cc --- a/src/core/random-variable.cc Mon Feb 23 16:07:46 2009 +0000 +++ b/src/core/random-variable.cc Mon Feb 02 16:50:44 2009 +0000 @@ -1679,6 +1679,45 @@ var = UniformVariable (a, b); } } + else if (type == "Normal" || type == "Gaussian") + { + if (value.size () == 0) + { + var = NormalVariable (); + } + else + { + tmp = value.find (":"); + if (tmp == value.npos) + { + NS_FATAL_ERROR ("bad Normal/Gaussian value: " << value); + } + std::string::size_type tmp2; + std::string sub = value.substr (tmp + 1, value.npos); + tmp2 = sub.find (":"); + if (tmp2 == value.npos) + { + istringstream issA (value.substr (0, tmp)); + istringstream issB (sub); + double a, b; + issA >> a; + issB >> b; + var = NormalVariable (a, b); + } + else + { + istringstream issA (value.substr (0, tmp)); + istringstream issB (sub.substr (0, tmp2)); + istringstream issC (sub.substr (tmp2 + 1, value.npos)); + double a, b, c; + issA >> a; + issB >> b; + issC >> c; + std::cerr << "NormalVariable ("< date: Wed Feb 25 11:20:52 2009 +0000 summary: NormalVariable serialization diff -r 3f9b0bad5afb -r d7d68e56dd20 src/core/random-variable.cc --- a/src/core/random-variable.cc Mon Feb 02 16:50:44 2009 +0000 +++ b/src/core/random-variable.cc Wed Feb 25 11:20:52 2009 +0000 @@ -995,6 +995,12 @@ * \return A random number from a distribution specified by m,v, and b. */ static double GetSingleValue(double m, double v, double b = INFINITE_VALUE); + + + double GetMean (void) const; + double GetVariance (void) const; + double GetBound (void) const; + private: double m_mean; // Mean value of RV double m_variance; // Mean value of RV @@ -1118,6 +1124,24 @@ } } +double +NormalVariableImpl::GetMean (void) const +{ + return m_mean; +} + +double +NormalVariableImpl::GetVariance (void) const +{ + return m_variance; +} + +double +NormalVariableImpl::GetBound (void) const +{ + return m_bound; +} + NormalVariable::NormalVariable() : RandomVariable (NormalVariableImpl ()) {} @@ -1137,7 +1161,6 @@ { return NormalVariableImpl::GetSingleValue (m, v, b); } - //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -1634,6 +1657,17 @@ os << "Uniform:" << uniform->GetMin () << ":" << uniform->GetMax (); return os; } + NormalVariableImpl *normal = dynamic_cast (base); + if (normal != 0) + { + os << "Normal:" << normal->GetMean () << ":" << normal->GetVariance (); + double bound = normal->GetBound (); + if (bound != NormalVariableImpl::INFINITE_VALUE) + { + os << ":" << bound; + } + return os; + } // XXX: support other distributions os.setstate (std::ios_base::badbit); return os; @@ -1679,7 +1713,7 @@ var = UniformVariable (a, b); } } - else if (type == "Normal" || type == "Gaussian") + else if (type == "Normal") { if (value.size () == 0) { @@ -1690,7 +1724,7 @@ tmp = value.find (":"); if (tmp == value.npos) { - NS_FATAL_ERROR ("bad Normal/Gaussian value: " << value); + NS_FATAL_ERROR ("bad Normal value: " << value); } std::string::size_type tmp2; std::string sub = value.substr (tmp + 1, value.npos); @@ -1713,7 +1747,6 @@ issA >> a; issB >> b; issC >> c; - std::cerr << "NormalVariable ("<