Skip to content

Commit

Permalink
Merge pull request cyclus#1830 from nuclearkatie/buy_pol_time-based
Browse files Browse the repository at this point in the history
Active/dormant cycle lengths database table
  • Loading branch information
gonuke authored Nov 27, 2024
2 parents a5ec440 + 37b872f commit 9dbf089
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Since last release
* Methods to reset behavaiors of MaterialBuyPolicy (#1822)
* More random distributions for the random number generator (#1821, #1827)
* Added example of header code injection for facility cost (#1829)
* Table for recording active/dormant cycle periods (#1830)

**Changed:**

Expand Down
45 changes: 38 additions & 7 deletions src/toolkit/matl_buy_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,40 @@ void MatlBuyPolicy::AcceptMatlTrades(
}

void MatlBuyPolicy::SetNextActiveTime() {
next_active_end_ = active_dist_->sample() + manager()->context()->time();
int active_length = active_dist_->sample();
next_active_end_ = active_length + manager()->context()->time();
if (manager() != NULL) {
if (use_cumulative_capacity()) {
RecordActiveDormantTime(manager()->context()->time(), "CumulativeCap", active_length);
} else {
RecordActiveDormantTime(manager()->context()->time(), "Active", active_length);
}
}
return;
};

void MatlBuyPolicy::SetNextDormantTime() {
int dormant_length;
int dormant_start;
if (use_cumulative_capacity()) {
// need the +1 when not using next_active_end_
next_dormant_end_ = (
dormant_dist_->sample() + manager()->context()->time() + 1);
// cumulative_cap dormant portion is updated only after the active cycle
// ends, because it's based on actual material recieved and not a dist
// that can be sampled at any time. Therefore, need the +1 when
// because next_active_end_ is not useful
dormant_length = dormant_dist_->sample();
dormant_start = manager()->context()->time() + 1;
}
else if (next_dormant_end_ >= 0) {
// dormant dist is used, and so is active dist. Just need to sample for
// length and add to active cycle
dormant_length = dormant_dist_->sample();
dormant_start = std::max(next_active_end_, 1);
} else { // next_active_end_ < 0 used to indicate always active. Do not enter dormant
return;
}
else if (next_dormant_end_ >= 0) {
next_dormant_end_ = dormant_dist_->sample() +
std::max(next_active_end_, 1);
next_dormant_end_ = dormant_length + dormant_start;
if (manager() != NULL) {
RecordActiveDormantTime(dormant_start, "Dormant", dormant_length);
}
return;
}
Expand All @@ -379,5 +400,15 @@ void MatlBuyPolicy::CheckActiveDormantCumulativeTimes() {
return;
}

void MatlBuyPolicy::RecordActiveDormantTime(int time, std::string type, int length) {
manager()->context()->NewDatum("BuyPolActiveDormant")
->AddVal("Agent", manager()->id())
->AddVal("Time", time)
->AddVal("Type", type)
->AddVal("Length", length)
->Record();
return;
}

} // namespace toolkit
} // namespace cyclus
1 change: 1 addition & 0 deletions src/toolkit/matl_buy_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class MatlBuyPolicy : public Trader {
void SetNextDormantTime();
double SampleRequestSize();
void CheckActiveDormantCumulativeTimes();
void RecordActiveDormantTime(int time, std::string type, int length);

private:
struct CommodDetail {
Expand Down

0 comments on commit 9dbf089

Please sign in to comment.