|
763 |
virtual double GetValue(); |
763 |
virtual double GetValue(); |
764 |
virtual RandomVariableBase* Copy(void) const; |
764 |
virtual RandomVariableBase* Copy(void) const; |
765 |
|
765 |
|
|
|
766 |
double GetMean (void) const; |
767 |
double GetVariance (void) const; |
768 |
double GetBound (void) const; |
769 |
|
766 |
private: |
770 |
private: |
767 |
double m_mean; // Mean value of RV |
771 |
double m_mean; // Mean value of RV |
768 |
double m_variance; // Mean value of RV |
772 |
double m_variance; // Mean value of RV |
|
833 |
RandomVariableBase* NormalVariableImpl::Copy() const |
837 |
RandomVariableBase* NormalVariableImpl::Copy() const |
834 |
{ |
838 |
{ |
835 |
return new NormalVariableImpl(*this); |
839 |
return new NormalVariableImpl(*this); |
|
|
840 |
} |
841 |
|
842 |
double |
843 |
NormalVariableImpl::GetMean (void) const |
844 |
{ |
845 |
return m_mean; |
846 |
} |
847 |
|
848 |
double |
849 |
NormalVariableImpl::GetVariance (void) const |
850 |
{ |
851 |
return m_variance; |
852 |
} |
853 |
|
854 |
double |
855 |
NormalVariableImpl::GetBound (void) const |
856 |
{ |
857 |
return m_bound; |
836 |
} |
858 |
} |
837 |
|
859 |
|
838 |
NormalVariable::NormalVariable() |
860 |
NormalVariable::NormalVariable() |
|
1280 |
os << "Uniform:" << uniform->GetMin () << ":" << uniform->GetMax (); |
1302 |
os << "Uniform:" << uniform->GetMin () << ":" << uniform->GetMax (); |
1281 |
return os; |
1303 |
return os; |
1282 |
} |
1304 |
} |
|
|
1305 |
NormalVariableImpl *normal = dynamic_cast<NormalVariableImpl *> (base); |
1306 |
if (normal != 0) |
1307 |
{ |
1308 |
os << "Normal:" << normal->GetMean () << ":" << normal->GetVariance (); |
1309 |
double bound = normal->GetBound (); |
1310 |
if (bound != NormalVariableImpl::INFINITE_VALUE) |
1311 |
{ |
1312 |
os << ":" << bound; |
1313 |
} |
1314 |
return os; |
1315 |
} |
1283 |
// XXX: support other distributions |
1316 |
// XXX: support other distributions |
1284 |
os.setstate (std::ios_base::badbit); |
1317 |
os.setstate (std::ios_base::badbit); |
1285 |
return os; |
1318 |
return os; |
|
1325 |
var = UniformVariable (a, b); |
1358 |
var = UniformVariable (a, b); |
1326 |
} |
1359 |
} |
1327 |
} |
1360 |
} |
|
|
1361 |
else if (type == "Normal") |
1362 |
{ |
1363 |
if (value.size () == 0) |
1364 |
{ |
1365 |
var = NormalVariable (); |
1366 |
} |
1367 |
else |
1368 |
{ |
1369 |
tmp = value.find (":"); |
1370 |
if (tmp == value.npos) |
1371 |
{ |
1372 |
NS_FATAL_ERROR ("bad Normal value: " << value); |
1373 |
} |
1374 |
std::string::size_type tmp2; |
1375 |
std::string sub = value.substr (tmp + 1, value.npos); |
1376 |
tmp2 = sub.find (":"); |
1377 |
if (tmp2 == value.npos) |
1378 |
{ |
1379 |
istringstream issA (value.substr (0, tmp)); |
1380 |
istringstream issB (sub); |
1381 |
double a, b; |
1382 |
issA >> a; |
1383 |
issB >> b; |
1384 |
var = NormalVariable (a, b); |
1385 |
} |
1386 |
else |
1387 |
{ |
1388 |
istringstream issA (value.substr (0, tmp)); |
1389 |
istringstream issB (sub.substr (0, tmp2)); |
1390 |
istringstream issC (sub.substr (tmp2 + 1, value.npos)); |
1391 |
double a, b, c; |
1392 |
issA >> a; |
1393 |
issB >> b; |
1394 |
issC >> c; |
1395 |
var = NormalVariable (a, b, c); |
1396 |
} |
1397 |
} |
1398 |
} |
1328 |
else |
1399 |
else |
1329 |
{ |
1400 |
{ |
1330 |
NS_FATAL_ERROR ("RandomVariable deserialization not implemented for " << type); |
1401 |
NS_FATAL_ERROR ("RandomVariable deserialization not implemented for " << type); |
|
1396 |
|
1465 |
|
1397 |
// Test attribute serialization |
1466 |
// Test attribute serialization |
1398 |
{ |
1467 |
{ |
1399 |
RandomVariableValue val; |
1468 |
{ |
1400 |
val.DeserializeFromString ("Uniform:0.1:0.2", MakeRandomVariableChecker ()); |
1469 |
RandomVariableValue val; |
1401 |
RandomVariable rng = val.Get (); |
1470 |
val.DeserializeFromString ("Uniform:0.1:0.2", MakeRandomVariableChecker ()); |
1402 |
NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Uniform:0.1:0.2"); |
1471 |
RandomVariable rng = val.Get (); |
|
|
1472 |
NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Uniform:0.1:0.2"); |
1473 |
} |
1474 |
{ |
1475 |
RandomVariableValue val; |
1476 |
val.DeserializeFromString ("Normal:0.1:0.2", MakeRandomVariableChecker ()); |
1477 |
RandomVariable rng = val.Get (); |
1478 |
NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Normal:0.1:0.2"); |
1479 |
} |
1480 |
{ |
1481 |
RandomVariableValue val; |
1482 |
val.DeserializeFromString ("Normal:0.1:0.2:0.15", MakeRandomVariableChecker ()); |
1483 |
RandomVariable rng = val.Get (); |
1484 |
NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Normal:0.1:0.2:0.15"); |
1485 |
} |
1403 |
} |
1486 |
} |
1404 |
|
1487 |
|
1405 |
return result; |
1488 |
return result; |