From eccf7aa659b3b6df8d020e2b4daba49f65779e5f Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 9 Oct 2023 13:37:16 -0500 Subject: [PATCH] active and dormant buying periods --- src/toolkit/matl_buy_policy.cc | 27 +++++++++++++++------------ src/toolkit/matl_buy_policy.h | 14 +++++++------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/toolkit/matl_buy_policy.cc b/src/toolkit/matl_buy_policy.cc index 87268146f7..04ac045f88 100644 --- a/src/toolkit/matl_buy_policy.cc +++ b/src/toolkit/matl_buy_policy.cc @@ -20,8 +20,8 @@ MatlBuyPolicy::MatlBuyPolicy() : quantize_(-1), fill_to_(1), req_when_under_(1), - freq_active_(1), - freq_dormant_(0){ + active_(1), + dormant_(0){ Warn( "MatlBuyPolicy is experimental and its API may be subject to change"); } @@ -55,14 +55,14 @@ void MatlBuyPolicy::set_throughput(double x) { throughput_ = x; } -void MatlBuyPolicy::set_freq_active(int x) { +void MatlBuyPolicy::set_active(int x) { assert(x > 0); - freq_active_ = x; + active_ = x; } -void MatlBuyPolicy::set_freq_dormant(int x) { +void MatlBuyPolicy::set_dormant(int x) { assert(x >= 0); - freq_dormant_ = x; + dormant_ = x; } MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf* buf, @@ -95,14 +95,16 @@ MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf* buf, MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf* buf, std::string name, double throughput, - int freq_active, - int freq_dormant) { + int active, + int dormant) { Trader::manager_ = manager; buf_ = buf; name_ = name; set_throughput(throughput); - set_freq_active(freq_active); - set_freq_dormant(freq_dormant); + set_active(active); + set_dormant(dormant); + LGH(INFO3) << "has buy policy with active = " << active_ \ + << "time steps and dormant = " << dormant_ << " time steps." ; return *this; } @@ -162,13 +164,14 @@ std::set::Ptr> MatlBuyPolicy::GetMatlRequests() { std::set::Ptr> ports; bool make_req = buf_->quantity() < req_when_under_ * buf_->capacity(); double amt; - int cycle = freq_active_ + freq_dormant_; - if ((manager()->context()->time() % cycle) < freq_active_) { + + if (manager()->context()->time() % (active_ + dormant_) < active_) { amt = TotalQty(); } else { // in dormant part of cycle, return empty portfolio amt = 0; + LGH(INFO3) << "in dormant period for time step " << manager()->context()->time() << ", requesting " << amt << " kg." ; } if (!make_req || amt < eps()) return ports; diff --git a/src/toolkit/matl_buy_policy.h b/src/toolkit/matl_buy_policy.h index 0ec1629309..079b2c64cc 100644 --- a/src/toolkit/matl_buy_policy.h +++ b/src/toolkit/matl_buy_policy.h @@ -84,8 +84,8 @@ class MatlBuyPolicy : public Trader { /// capacity. The "on" and "off" phases are sampled and rounded to the /// nearest integer number of time steps from a truncated normal /// distribution from a mean, standard deviation, min, and max value. - /// @param freq_active the length of the on, actively buying period - /// @param freq_dormant the length of the dormant period + /// @param active the length of the on, actively buying period + /// @param dormant the length of the dormant period /// @{ MatlBuyPolicy& Init(Agent* manager, ResBuf* buf, std::string name); MatlBuyPolicy& Init(Agent* manager, ResBuf* buf, std::string name, @@ -93,8 +93,8 @@ class MatlBuyPolicy : public Trader { MatlBuyPolicy& Init(Agent* manager, ResBuf* buf, std::string name, double fill_to, double req_when_under); MatlBuyPolicy& Init(Agent* manager, ResBuf* buf, std::string name, - double throughput, int freq_active, - int freq_dormant); + double throughput, int active, + int dormant); MatlBuyPolicy& Init(Agent* manager, ResBuf* buf, std::string name, double throughput, double fill_to, double req_when_under, double quantize); @@ -172,13 +172,13 @@ class MatlBuyPolicy : public Trader { void set_req_when_under(double x); void set_quantize(double x); void set_throughput(double x); - void set_freq_active(int x); - void set_freq_dormant(int x); + void set_active(int x); + void set_dormant(int x); ResBuf* buf_; std::string name_; double fill_to_, req_when_under_, quantize_, throughput_; - int freq_active_, freq_dormant_; + int active_, dormant_; std::map rsrc_commods_; std::map commod_details_; };