Skip to content

Commit

Permalink
dont allow size dist with max>1
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Jan 17, 2024
1 parent e93ce30 commit eda706e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/toolkit/matl_buy_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ void MatlBuyPolicy::init_active_dormant() {
if (size_dist_ == NULL) {
size_dist_ = boost::shared_ptr<FixedDoubleDist>(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;
Expand Down Expand Up @@ -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();
}


Expand Down
7 changes: 3 additions & 4 deletions tests/toolkit/matl_buy_policy_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ TEST_F(MatlBuyPolicyTests, UniformActiveDormant) {
TEST_F(MatlBuyPolicyTests, NormalActiveDormant) {
using cyclus::QueryResult;

boost::shared_ptr<NormalIntDist> a_dist =
boost::shared_ptr<NormalIntDist>(new NormalIntDist(5, 1, 2, 10));
boost::shared_ptr<NormalIntDist> a_dist = boost::shared_ptr<NormalIntDist>(new NormalIntDist(5, 1, 2, 10));
boost::shared_ptr<NormalIntDist> d_dist = boost::shared_ptr<NormalIntDist>(new NormalIntDist(3, 0.5, 1, 5));

int dur = 25;
Expand Down Expand Up @@ -376,7 +375,7 @@ TEST_F(MatlBuyPolicyTests, NormalActiveDormant) {
TEST_F(MatlBuyPolicyTests, MixedActiveDormant) {
using cyclus::QueryResult;

boost::shared_ptr<NormalIntDist> a_dist = boost::shared_ptr<NormalIntDist>(new NormalIntDist(5, 1));
boost::shared_ptr<NormalIntDist> a_dist = boost::shared_ptr<NormalIntDist>(new NormalIntDist(5, 1, 0, 1e299));
boost::shared_ptr<UniformIntDist> d_dist = boost::shared_ptr<UniformIntDist>(new UniformIntDist(1, 3));

int dur = 12;
Expand Down Expand Up @@ -499,7 +498,7 @@ TEST_F(MatlBuyPolicyTests, RandomSizeAndFrequency) {

QueryResult qr2 = sim.db().Query("Transactions", NULL);
EXPECT_EQ(0, qr2.GetVal<int>("Time", 0));
EXPECT_EQ(5, qr2.GetVal<int>("Time", 2));
EXPECT_EQ(4, qr2.GetVal<int>("Time", 2));

delete a;
}
Expand Down

0 comments on commit eda706e

Please sign in to comment.