Skip to content

Commit

Permalink
active and dormant buying periods
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Oct 17, 2023
1 parent b4b0550 commit eccf7aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
27 changes: 15 additions & 12 deletions src/toolkit/matl_buy_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<EXPERIMENTAL_WARNING>(
"MatlBuyPolicy is experimental and its API may be subject to change");
}
Expand Down Expand Up @@ -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<Material>* buf,
Expand Down Expand Up @@ -95,14 +95,16 @@ MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf<Material>* buf,

MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf<Material>* 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;
}

Expand Down Expand Up @@ -162,13 +164,14 @@ std::set<RequestPortfolio<Material>::Ptr> MatlBuyPolicy::GetMatlRequests() {
std::set<RequestPortfolio<Material>::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;
Expand Down
14 changes: 7 additions & 7 deletions src/toolkit/matl_buy_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ 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<Material>* buf, std::string name);
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
double throughput);
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
double fill_to, double req_when_under);
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
double throughput, int freq_active,
int freq_dormant);
double throughput, int active,
int dormant);
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
double throughput, double fill_to,
double req_when_under, double quantize);
Expand Down Expand Up @@ -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<Material>* buf_;
std::string name_;
double fill_to_, req_when_under_, quantize_, throughput_;
int freq_active_, freq_dormant_;
int active_, dormant_;
std::map<Material::Ptr, std::string> rsrc_commods_;
std::map<std::string, CommodDetail> commod_details_;
};
Expand Down

0 comments on commit eccf7aa

Please sign in to comment.