|
995 |
* \return A random number from a distribution specified by m,v, and b. |
995 |
* \return A random number from a distribution specified by m,v, and b. |
996 |
*/ |
996 |
*/ |
997 |
static double GetSingleValue(double m, double v, double b = INFINITE_VALUE); |
997 |
static double GetSingleValue(double m, double v, double b = INFINITE_VALUE); |
|
|
998 |
|
999 |
|
1000 |
double GetMean (void) const; |
1001 |
double GetVariance (void) const; |
1002 |
double GetBound (void) const; |
1003 |
|
998 |
private: |
1004 |
private: |
999 |
double m_mean; // Mean value of RV |
1005 |
double m_mean; // Mean value of RV |
1000 |
double m_variance; // Mean value of RV |
1006 |
double m_variance; // Mean value of RV |
|
1118 |
} |
1124 |
} |
1119 |
} |
1125 |
} |
1120 |
|
1126 |
|
|
|
1127 |
double |
1128 |
NormalVariableImpl::GetMean (void) const |
1129 |
{ |
1130 |
return m_mean; |
1131 |
} |
1132 |
|
1133 |
double |
1134 |
NormalVariableImpl::GetVariance (void) const |
1135 |
{ |
1136 |
return m_variance; |
1137 |
} |
1138 |
|
1139 |
double |
1140 |
NormalVariableImpl::GetBound (void) const |
1141 |
{ |
1142 |
return m_bound; |
1143 |
} |
1144 |
|
1121 |
NormalVariable::NormalVariable() |
1145 |
NormalVariable::NormalVariable() |
1122 |
: RandomVariable (NormalVariableImpl ()) |
1146 |
: RandomVariable (NormalVariableImpl ()) |
1123 |
{} |
1147 |
{} |
|
1137 |
{ |
1161 |
{ |
1138 |
return NormalVariableImpl::GetSingleValue (m, v, b); |
1162 |
return NormalVariableImpl::GetSingleValue (m, v, b); |
1139 |
} |
1163 |
} |
1140 |
|
|
|
1141 |
|
1164 |
|
1142 |
//----------------------------------------------------------------------------- |
1165 |
//----------------------------------------------------------------------------- |
1143 |
//----------------------------------------------------------------------------- |
1166 |
//----------------------------------------------------------------------------- |
|
1634 |
os << "Uniform:" << uniform->GetMin () << ":" << uniform->GetMax (); |
1657 |
os << "Uniform:" << uniform->GetMin () << ":" << uniform->GetMax (); |
1635 |
return os; |
1658 |
return os; |
1636 |
} |
1659 |
} |
|
|
1660 |
NormalVariableImpl *normal = dynamic_cast<NormalVariableImpl *> (base); |
1661 |
if (normal != 0) |
1662 |
{ |
1663 |
os << "Normal:" << normal->GetMean () << ":" << normal->GetVariance (); |
1664 |
double bound = normal->GetBound (); |
1665 |
if (bound != NormalVariableImpl::INFINITE_VALUE) |
1666 |
{ |
1667 |
os << ":" << bound; |
1668 |
} |
1669 |
return os; |
1670 |
} |
1637 |
// XXX: support other distributions |
1671 |
// XXX: support other distributions |
1638 |
os.setstate (std::ios_base::badbit); |
1672 |
os.setstate (std::ios_base::badbit); |
1639 |
return os; |
1673 |
return os; |
|
1679 |
var = UniformVariable (a, b); |
1713 |
var = UniformVariable (a, b); |
1680 |
} |
1714 |
} |
1681 |
} |
1715 |
} |
1682 |
else if (type == "Normal" || type == "Gaussian") |
1716 |
else if (type == "Normal") |
1683 |
{ |
1717 |
{ |
1684 |
if (value.size () == 0) |
1718 |
if (value.size () == 0) |
1685 |
{ |
1719 |
{ |
|
1690 |
tmp = value.find (":"); |
1724 |
tmp = value.find (":"); |
1691 |
if (tmp == value.npos) |
1725 |
if (tmp == value.npos) |
1692 |
{ |
1726 |
{ |
1693 |
NS_FATAL_ERROR ("bad Normal/Gaussian value: " << value); |
1727 |
NS_FATAL_ERROR ("bad Normal value: " << value); |
1694 |
} |
1728 |
} |
1695 |
std::string::size_type tmp2; |
1729 |
std::string::size_type tmp2; |
1696 |
std::string sub = value.substr (tmp + 1, value.npos); |
1730 |
std::string sub = value.substr (tmp + 1, value.npos); |
|
1713 |
issA >> a; |
1747 |
issA >> a; |
1714 |
issB >> b; |
1748 |
issB >> b; |
1715 |
issC >> c; |
1749 |
issC >> c; |
1716 |
std::cerr << "NormalVariable ("<<a<<", "<<b<<", "<<c<<");" << std::endl; |
|
|
1717 |
var = NormalVariable (a, b, c); |
1750 |
var = NormalVariable (a, b, c); |
1718 |
} |
1751 |
} |
1719 |
} |
1752 |
} |
|
1823 |
|
1856 |
|
1824 |
// Test attribute serialization |
1857 |
// Test attribute serialization |
1825 |
{ |
1858 |
{ |
1826 |
RandomVariableValue val; |
1859 |
{ |
1827 |
val.DeserializeFromString ("Uniform:0.1:0.2", MakeRandomVariableChecker ()); |
1860 |
RandomVariableValue val; |
1828 |
RandomVariable rng = val.Get (); |
1861 |
val.DeserializeFromString ("Uniform:0.1:0.2", MakeRandomVariableChecker ()); |
1829 |
NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Uniform:0.1:0.2"); |
1862 |
RandomVariable rng = val.Get (); |
|
|
1863 |
NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Uniform:0.1:0.2"); |
1864 |
} |
1865 |
{ |
1866 |
RandomVariableValue val; |
1867 |
val.DeserializeFromString ("Normal:0.1:0.2", MakeRandomVariableChecker ()); |
1868 |
RandomVariable rng = val.Get (); |
1869 |
NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Normal:0.1:0.2"); |
1870 |
} |
1871 |
{ |
1872 |
RandomVariableValue val; |
1873 |
val.DeserializeFromString ("Normal:0.1:0.2:0.15", MakeRandomVariableChecker ()); |
1874 |
RandomVariable rng = val.Get (); |
1875 |
NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Normal:0.1:0.2:0.15"); |
1876 |
} |
1830 |
} |
1877 |
} |
1831 |
|
1878 |
|
1832 |
return result; |
1879 |
return result; |