Skip to content

Commit

Permalink
Merge pull request #1552 from bam241/sell_pol
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke authored Jun 16, 2021
2 parents c72b266 + 9ce5a27 commit 9b52839
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
14 changes: 14 additions & 0 deletions news/sell_policy_quantize.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
**Added:** None

**Changed:**
- now default quantize are zero which corresponds to no quantize policy.

**Deprecated:** None

**Removed:** None

**Fixed:**
- fix sell_policy that was offering bids when capacity was inbetween 0 and the
quantize, bids that one was not able to fullfill and caused cyclus to crash.

**Security:** None
13 changes: 7 additions & 6 deletions src/toolkit/matl_sell_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace toolkit {
MatlSellPolicy::MatlSellPolicy() :
Trader(NULL),
name_(""),
quantize_(-1),
quantize_(0),
throughput_(std::numeric_limits<double>::max()),
ignore_comp_(false) {
Warn<EXPERIMENTAL_WARNING>(
Expand All @@ -27,7 +27,7 @@ MatlSellPolicy::~MatlSellPolicy() {
}

void MatlSellPolicy::set_quantize(double x) {
assert(x != 0);
assert(x >= 0);
quantize_ = x;
}

Expand Down Expand Up @@ -123,12 +123,13 @@ double MatlSellPolicy::Limit() const {
std::set<BidPortfolio<Material>::Ptr> MatlSellPolicy::GetMatlBids(
CommodMap<Material>::type& commod_requests) {
std::set<BidPortfolio<Material>::Ptr> ports;
if (buf_->empty() || buf_->quantity() < eps())
return ports;

BidPortfolio<Material>::Ptr port(new BidPortfolio<Material>());


double limit = Limit();
if (buf_->empty() || buf_->quantity() < eps()|| limit < eps())
return ports;

BidPortfolio<Material>::Ptr port(new BidPortfolio<Material>());
CapacityConstraint<Material> cc(limit);
port->AddConstraint(cc);
ports.insert(port);
Expand Down
19 changes: 18 additions & 1 deletion tests/toolkit/matl_sell_policy_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,31 @@ TEST_F(MatlSellPolicyTests, Bids) {
ASSERT_EQ((*(*obs.begin())->bids().begin())->offer()->comp(), comp);

// excl and ignore_comp
// Qty = 3, Throughput = 3, Quanta = 1.5 -> 2 transactions of 1 quanta
p.Init(NULL, &buff, "", qty, true, qty / 2).Set(commod);
obs = p.GetMatlBids(reqs);
ASSERT_EQ(obs.size(), 1);
ASSERT_EQ((*obs.begin())->bids().size(), 2);
ASSERT_FLOAT_EQ((*(*obs.begin())->bids().begin())->offer()->quantity(),
mat->quantity() / 2);
qty / 2);
ASSERT_EQ((*(*obs.begin())->bids().begin())->offer()->comp(), comp1);

// If available quantity is bigger than the quanta only an integer number of quanta is offered
// Qty = 3, Throughput = 3, Quanta = 2 -> only 1 transactions of 1 quanta
p.Init(NULL, &buff, "", qty, true, 2).Set(commod);
obs = p.GetMatlBids(reqs);
ASSERT_EQ(obs.size(), 1);
ASSERT_EQ((*obs.begin())->bids().size(), 1);
ASSERT_FLOAT_EQ((*(*obs.begin())->bids().begin())->offer()->quantity(),
2);
ASSERT_EQ((*(*obs.begin())->bids().begin())->offer()->comp(), comp1);


// quantize bigger than the quantity in storage
// Qty = 3, Throughput = 3, Quanta = 6 -> No transaction
p.Init(NULL, &buff, "", qty, true, qty * 2).Set(commod);
obs = p.GetMatlBids(reqs);
ASSERT_EQ(obs.size(), 0);
delete req;
}

Expand Down

0 comments on commit 9b52839

Please sign in to comment.