Skip to content

Commit

Permalink
check that buf is in tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Feb 6, 2024
1 parent 915adc3 commit 7913770
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/toolkit/matl_buy_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ void MatlBuyPolicy::set_total_inv_tracker(TotalInvTracker* t) {
std::vector<ResBuf<Material>*> bufs = {buf_};
buf_tracker_->Init(bufs, buf_->capacity());
}
else if (!t->buf_in_tracker(buf_)) {
std::stringstream ss;
ss << "TotalInvTracker does not contain ResBuf used in buy policy";
throw ValueError(ss.str());
}
else {
buf_tracker_ = t;
}
Expand All @@ -73,8 +78,7 @@ void MatlBuyPolicy::set_inv_policy(std::string inv_policy, double fill, double r

void MatlBuyPolicy::set_fill_to(double x) {
assert(x > 0);
assert(x <= buf_->capacity());
fill_to_ = x;
fill_to_ = std::min(x, buf_->capacity());
}

void MatlBuyPolicy::set_req_at(double x) {
Expand All @@ -84,7 +88,7 @@ void MatlBuyPolicy::set_req_at(double x) {

void MatlBuyPolicy::set_cumulative_cap(double x) {
assert(x > 0);
cumulative_cap_ = x;
cumulative_cap_ = std::min(x, buf_->capacity());
}

void MatlBuyPolicy::set_quantize(double x) {
Expand Down
7 changes: 7 additions & 0 deletions src/toolkit/total_inv_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ class TotalInvTracker {
max_inv_size_ = cap;
}

bool buf_in_tracker(ResBuf<Material>* buf) {
for (int i = 0; i < num_bufs(); i++) {
if (bufs_[i] == buf) { return true; }
}
return false;
}

private:
double max_inv_size_;
double qty_;
Expand Down

0 comments on commit 7913770

Please sign in to comment.