From d9c68d9c181ccd9ee5006db842f5b5e6842b9790 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 13 May 2024 16:03:47 -0500 Subject: [PATCH] each packaged material should only be one item long --- src/toolkit/matl_sell_policy.cc | 19 +++++++++++++------ src/toolkit/matl_sell_policy.h | 2 +- tests/toolkit/matl_sell_policy_tests.cc | 6 +++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/toolkit/matl_sell_policy.cc b/src/toolkit/matl_sell_policy.cc index 6e67288417..e646253bef 100644 --- a/src/toolkit/matl_sell_policy.cc +++ b/src/toolkit/matl_sell_policy.cc @@ -179,6 +179,8 @@ std::set::Ptr> MatlSellPolicy::GetMatlBids( } else { nbids = excl ? static_cast(std::floor(qty / quantize_)) : static_cast(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(); @@ -189,6 +191,14 @@ std::set::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; @@ -196,7 +206,7 @@ std::set::Ptr> MatlSellPolicy::GetMatlBids( void MatlSellPolicy::GetMatlTrades( const std::vector >& trades, - std::vector, std::vector > >& responses) { + std::vector, Material::Ptr> >& responses) { Composition::Ptr c; std::vector >::const_iterator it; for (it = trades.begin(); it != trades.end(); ++it) { @@ -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::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])); } } diff --git a/src/toolkit/matl_sell_policy.h b/src/toolkit/matl_sell_policy.h index 8bb2a456cf..d93ec8fe5a 100644 --- a/src/toolkit/matl_sell_policy.h +++ b/src/toolkit/matl_sell_policy.h @@ -119,7 +119,7 @@ class MatlSellPolicy : public Trader { CommodMap::type& commod_requests); virtual void GetMatlTrades( const std::vector >& trades, - std::vector, std::vector > >& responses); + std::vector, Material::Ptr> >& responses); /// }@ private: diff --git a/tests/toolkit/matl_sell_policy_tests.cc b/tests/toolkit/matl_sell_policy_tests.cc index b505fddacd..e1f9f05446 100644 --- a/tests/toolkit/matl_sell_policy_tests.cc +++ b/tests/toolkit/matl_sell_policy_tests.cc @@ -127,7 +127,7 @@ TEST_F(MatlSellPolicyTests, Trades) { MatlSellPolicy p; std::string commod("commod"); std::vector > trades; - std::vector, std::vector > > obs; + std::vector, Material::Ptr> > obs; Request* req = Request::Create(mat1, fac1, commod); Bid* bid = Bid::Create(req, mat, fac1); @@ -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;