From eda706e0a8bab2b5d1408fed5fef6711a47d06ec Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Wed, 17 Jan 2024 08:10:17 -0700 Subject: [PATCH] dont allow size dist with max>1 --- src/toolkit/matl_buy_policy.cc | 10 +++++----- tests/toolkit/matl_buy_policy_tests.cc | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/toolkit/matl_buy_policy.cc b/src/toolkit/matl_buy_policy.cc index bea60b7dc4..7a70a62146 100644 --- a/src/toolkit/matl_buy_policy.cc +++ b/src/toolkit/matl_buy_policy.cc @@ -77,6 +77,10 @@ void MatlBuyPolicy::init_active_dormant() { if (size_dist_ == NULL) { size_dist_ = boost::shared_ptr(new FixedDoubleDist(1.0)); } + + if (size_dist_->max() > 1) { + throw ValueError("Size distribution cannot have a max greater than 1."); + } SetNextActiveTime(); LGH(INFO4) << "first active time end: " << next_active_end_ << std::endl; @@ -260,11 +264,7 @@ void MatlBuyPolicy::SetNextDormantTime() { } double MatlBuyPolicy::SampleRequestSize() { - double random_request_size_ = size_dist_->sample(); - if (random_request_size_ > 1) { - random_request_size_ = random_request_size_ / size_dist_->max(); - } - return random_request_size_; + return size_dist_->sample(); } diff --git a/tests/toolkit/matl_buy_policy_tests.cc b/tests/toolkit/matl_buy_policy_tests.cc index 66e948a4d3..f18cb42f02 100644 --- a/tests/toolkit/matl_buy_policy_tests.cc +++ b/tests/toolkit/matl_buy_policy_tests.cc @@ -337,8 +337,7 @@ TEST_F(MatlBuyPolicyTests, UniformActiveDormant) { TEST_F(MatlBuyPolicyTests, NormalActiveDormant) { using cyclus::QueryResult; - boost::shared_ptr a_dist = - boost::shared_ptr(new NormalIntDist(5, 1, 2, 10)); + boost::shared_ptr a_dist = boost::shared_ptr(new NormalIntDist(5, 1, 2, 10)); boost::shared_ptr d_dist = boost::shared_ptr(new NormalIntDist(3, 0.5, 1, 5)); int dur = 25; @@ -376,7 +375,7 @@ TEST_F(MatlBuyPolicyTests, NormalActiveDormant) { TEST_F(MatlBuyPolicyTests, MixedActiveDormant) { using cyclus::QueryResult; - boost::shared_ptr a_dist = boost::shared_ptr(new NormalIntDist(5, 1)); + boost::shared_ptr a_dist = boost::shared_ptr(new NormalIntDist(5, 1, 0, 1e299)); boost::shared_ptr d_dist = boost::shared_ptr(new UniformIntDist(1, 3)); int dur = 12; @@ -499,7 +498,7 @@ TEST_F(MatlBuyPolicyTests, RandomSizeAndFrequency) { QueryResult qr2 = sim.db().Query("Transactions", NULL); EXPECT_EQ(0, qr2.GetVal("Time", 0)); - EXPECT_EQ(5, qr2.GetVal("Time", 2)); + EXPECT_EQ(4, qr2.GetVal("Time", 2)); delete a; }