Skip to content

Commit

Permalink
add methods to reset/unset build policy
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke committed Oct 25, 2024
1 parent 89eee5e commit 15af029
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/toolkit/matl_buy_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ MatlBuyPolicy::~MatlBuyPolicy() {
manager()->context()->UnregisterTrader(this);
}

MatlBuyPolicy& MatlBuyPolicy::ResetBehavior() {
throughput_ = std::numeric_limits<double>::max();
quantize_ = 1;
fill_to_ = std::numeric_limits<double>::max();
req_at_ = std::numeric_limits<double>::max();
cumulative_cap_ = -1;
cycle_total_inv_ = 0;
active_dist_ = NULL;
dormant_dist_ = NULL;
size_dist_ = NULL;
return *this;
}

void MatlBuyPolicy::set_manager(Agent* m) {
if (m != NULL) {
Trader::manager_ = m;
Expand Down Expand Up @@ -238,6 +251,12 @@ MatlBuyPolicy& MatlBuyPolicy::Set(std::string commod, Composition::Ptr c,
return *this;
}

MatlBuyPolicy& MatlBuyPolicy::Unset(std::string commod){

commod_details_.erase(commod);
return *this;
}

void MatlBuyPolicy::Start() {
if (manager() == NULL) {
std::stringstream ss;
Expand Down
10 changes: 10 additions & 0 deletions src/toolkit/matl_buy_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ class MatlBuyPolicy : public Trader {
IntDistribution::Ptr);
/// @}

/// Reset a material buy policy parameters that govern its behavior
/// to the default state. Preserve the Trader that manages the policy.
/// The primary use case of this method is when there is a desire to
/// change the behavior of a policy. This reset can be called prior
/// to calling a new `Init()` to establish the new behavior.
MatlBuyPolicy& ResetBehavior();

/// Instructs the policy to fill its buffer with requests on the given
/// commodity of composition c and the given preference. This must be called
/// at least once or the policy will do nothing. The policy can request on an
Expand All @@ -156,6 +163,9 @@ class MatlBuyPolicy : public Trader {
MatlBuyPolicy& Set(std::string commod, Composition::Ptr c, double pref);
/// @}

/// Instructs the policy to stop requesting a speific commodity
MatlBuyPolicy& Unset(std::string commod);

/// Registers this policy as a trader in the current simulation. This
/// function must be called for the policy to begin participating in resource
/// exchange. Init MUST be called prior to calling this function. Start is
Expand Down

0 comments on commit 15af029

Please sign in to comment.