Skip to content

Commit

Permalink
each packaged material should only be one item long
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed May 13, 2024
1 parent 45bef3f commit d9c68d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
19 changes: 13 additions & 6 deletions src/toolkit/matl_sell_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ std::set<BidPortfolio<Material>::Ptr> MatlSellPolicy::GetMatlBids(
} else {
nbids = excl ? static_cast<int>(std::floor(qty / quantize_)) : static_cast<int>(std::floor(qty / package_fill));
}
double remaining_qty = fmod(qty, package_fill);

qty = excl ? quantize_ : package_fill;
for (int i = 0; i < nbids; i++) {
m = buf_->Pop();
Expand All @@ -189,14 +191,22 @@ std::set<BidPortfolio<Material>::Ptr> MatlSellPolicy::GetMatlBids(
port->AddBid(req, offer, this, excl);
LG(INFO3) << " - bid " << qty << " kg on a request for " << commod;
}

if (!excl && remaining_qty > package_->fill_min()) {
offer = ignore_comp_ ? \
Material::CreateUntracked(remaining_qty, req->target()->comp()) : \
Material::CreateUntracked(remaining_qty, m->comp());
port->AddBid(req, offer, this, excl);
LG(INFO3) << " - bid " << remaining_qty << " kg on a request for " << commod;
}
}
}
return ports;
}

void MatlSellPolicy::GetMatlTrades(
const std::vector<Trade<Material> >& trades,
std::vector<std::pair<Trade<Material>, std::vector<Material::Ptr> > >& responses) {
std::vector<std::pair<Trade<Material>, Material::Ptr> >& responses) {
Composition::Ptr c;
std::vector<Trade<Material> >::const_iterator it;
for (it = trades.begin(); it != trades.end(); ++it) {
Expand All @@ -207,12 +217,9 @@ void MatlSellPolicy::GetMatlTrades(
// push any extra material that couldn't be packaged back onto buffer
buf_->Push(mat);
if (ignore_comp_) {
std::vector<Material::Ptr>::iterator pit;
for (pit = mat_pkgd.begin(); pit != mat_pkgd.end(); ++pit) {
(*pit)->Transmute(it->request->target()->comp());
mat_pkgd[0]->Transmute(it->request->target()->comp());
}
}
responses.push_back(std::make_pair(*it, mat_pkgd));
responses.push_back(std::make_pair(*it, mat_pkgd[0]));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/toolkit/matl_sell_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class MatlSellPolicy : public Trader {
CommodMap<Material>::type& commod_requests);
virtual void GetMatlTrades(
const std::vector<Trade<Material> >& trades,
std::vector<std::pair<Trade<Material>, std::vector<Material::Ptr> > >& responses);
std::vector<std::pair<Trade<Material>, Material::Ptr> >& responses);
/// }@

private:
Expand Down
6 changes: 3 additions & 3 deletions tests/toolkit/matl_sell_policy_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ TEST_F(MatlSellPolicyTests, Trades) {
MatlSellPolicy p;
std::string commod("commod");
std::vector<Trade<Material> > trades;
std::vector<std::pair<Trade<Material>, std::vector<Material::Ptr> > > obs;
std::vector<std::pair<Trade<Material>, Material::Ptr> > obs;

Request<Material>* req = Request<Material>::Create(mat1, fac1, commod);
Bid<Material>* bid = Bid<Material>::Create(req, mat, fac1);
Expand All @@ -138,14 +138,14 @@ TEST_F(MatlSellPolicyTests, Trades) {
p.Init(NULL, &buff, "").Set(commod);
p.GetMatlTrades(trades, obs);
ASSERT_EQ(obs.size(), 1);
ASSERT_EQ(obs.begin()->second[0]->comp(), comp);
ASSERT_EQ(obs.begin()->second->comp(), comp);

// ignore comp
obs.clear();
p.Init(NULL, &buff, "", qty, true).Set(commod);
p.GetMatlTrades(trades, obs);
ASSERT_EQ(obs.size(), 1);
ASSERT_EQ(obs.begin()->second[0]->comp(), comp1);
ASSERT_EQ(obs.begin()->second->comp(), comp1);

delete bid;
delete req;
Expand Down

0 comments on commit d9c68d9

Please sign in to comment.