Skip to content

Commit

Permalink
add package to matl sell policy to getmatlbids
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed May 7, 2024
1 parent ac33833 commit 92452fa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
34 changes: 30 additions & 4 deletions src/toolkit/matl_sell_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ MatlSellPolicy::MatlSellPolicy() :
name_(""),
quantize_(0),
throughput_(std::numeric_limits<double>::max()),
ignore_comp_(false) {
ignore_comp_(false),
package_id_(Package::unpackaged_id()) {
Warn<EXPERIMENTAL_WARNING>(
"MatlSellPolicy is experimental and its API may be subject to change");
}
Expand All @@ -40,11 +41,23 @@ void MatlSellPolicy::set_ignore_comp(bool x) {
ignore_comp_ = x;
}

void MatlSellPolicy::set_package(int x) {
assert(x >= 1);
package_id_ = x;
if (manager() != NULL) {
package_ = manager()->context()->GetPackageById(package_id_);
} else {
// if no real context, only unpackaged can be used.
package_ = Package::unpackaged();
}
}

MatlSellPolicy& MatlSellPolicy::Init(Agent* manager, ResBuf<Material>* buf,
std::string name) {
Trader::manager_ = manager;
buf_ = buf;
name_ = name;
package_ = Package::unpackaged();
return *this;
}

Expand All @@ -54,6 +67,7 @@ MatlSellPolicy& MatlSellPolicy::Init(Agent* manager, ResBuf<Material>* buf,
buf_ = buf;
name_ = name;
set_throughput(throughput);
package_ = Package::unpackaged();
return *this;
}

Expand All @@ -63,6 +77,7 @@ MatlSellPolicy& MatlSellPolicy::Init(Agent* manager, ResBuf<Material>* buf,
buf_ = buf;
name_ = name;
set_ignore_comp(ignore_comp);
package_ = Package::unpackaged();
return *this;
}

Expand All @@ -74,18 +89,21 @@ MatlSellPolicy& MatlSellPolicy::Init(Agent* manager, ResBuf<Material>* buf,
name_ = name;
set_throughput(throughput);
set_ignore_comp(ignore_comp);
package_ = Package::unpackaged();
return *this;
}

MatlSellPolicy& MatlSellPolicy::Init(Agent* manager, ResBuf<Material>* buf,
std::string name, double throughput,
bool ignore_comp, double quantize) {
bool ignore_comp, double quantize,
int package_id) {
Trader::manager_ = manager;
buf_ = buf;
name_ = name;
set_quantize(quantize);
set_throughput(throughput);
set_ignore_comp(ignore_comp);
set_package(package_id);
return *this;
}

Expand All @@ -100,6 +118,12 @@ void MatlSellPolicy::Start() {
ss << "No manager set on Sell Policy " << name_;
throw ValueError(ss.str());
}
if (quantize_ < package_->fill_min() || quantize_ > package_->fill_max()) {
std::stringstream ss;
ss << "Quantize " << quantize_ << " is outside the package fill min/max values (" << package_->fill_min() << ", "
<< package_->fill_max() << ")";
throw ValueError(ss.str());
}
manager()->context()->RegisterTrader(this);
}

Expand Down Expand Up @@ -141,6 +165,7 @@ std::set<BidPortfolio<Material>::Ptr> MatlSellPolicy::GetMatlBids(
Material::Ptr m, offer;
double qty;
int nbids;
double package_fill;
std::set<std::string>::iterator sit;
std::vector<Request<Material>*>::const_iterator rit;
for (sit = commods_.begin(); sit != commods_.end(); ++sit) {
Expand All @@ -153,8 +178,9 @@ std::set<BidPortfolio<Material>::Ptr> MatlSellPolicy::GetMatlBids(
for (rit = requests.begin(); rit != requests.end(); ++rit) {
req = *rit;
qty = std::min(req->target()->quantity(), limit);
nbids = excl ? static_cast<int>(std::floor(qty / quantize_)) : 1;
qty = excl ? quantize_ : qty;
package_fill = std::min(qty, package_->GetFillMass(qty));
nbids = excl ? static_cast<int>(std::floor(qty / quantize_)) : static_cast<int>(std::floor(qty / package_fill));
qty = excl ? quantize_ : package_fill;
for (int i = 0; i < nbids; i++) {
m = buf_->Pop();
buf_->Push(m);
Expand Down
7 changes: 6 additions & 1 deletion src/toolkit/matl_sell_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "material.h"
#include "res_buf.h"
#include "trader.h"
#include "package.h"

namespace cyclus {
namespace toolkit {
Expand Down Expand Up @@ -83,7 +84,8 @@ class MatlSellPolicy : public Trader {
double throughput, bool ignore_comp);
MatlSellPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
double throughput, bool ignore_comp,
double quantize);
double quantize,
int package_id = Package::unpackaged_id());
/// @}

/// Instructs the policy to empty its buffer with offers on the given
Expand Down Expand Up @@ -124,13 +126,16 @@ class MatlSellPolicy : public Trader {
void set_quantize(double x);
void set_throughput(double x);
void set_ignore_comp(bool x);
void set_package(int x);

ResBuf<Material>* buf_;
std::set<std::string> commods_;
double quantize_;
double throughput_;
std::string name_;
bool ignore_comp_;
int package_id_;
Package::Ptr package_;
};

} // namespace toolkit
Expand Down

0 comments on commit 92452fa

Please sign in to comment.