6#define LG(X) LOG(LEV_##X, "selpol")
8 LOG(LEV_##X, "selpol") << "policy " << name_ << " (agent " \
9 << Trader::manager()->prototype() << "-" \
10 << Trader::manager()->id() << "): "
21 package_(
Package::unpackaged()),
24 "MatlSellPolicy is experimental and its API may be subject to change");
32void MatlSellPolicy::set_quantize(
double x) {
37void MatlSellPolicy::set_throughput(
double x) {
42void MatlSellPolicy::set_ignore_comp(
bool x) {
46void MatlSellPolicy::set_package(std::string
x) {
53 if (
pkg->strategy() ==
"first" ||
pkg->strategy() ==
"equal") {
54 std::vector<double>
fill =
pkg->GetFillMass(quantize_);
55 if (
fill.size() > 1 || std::fmod(
fill.front(), quantize_) > 0) {
56 ss <<
"Quantize " << quantize_
57 <<
" is not fully packagable based on fill min/max values ("
58 <<
pkg->fill_min() <<
", " <<
pkg->fill_max() <<
")";
59 throw ValueError(
ss.str());
62 ss <<
"Package strategy " <<
pkg->strategy()
63 <<
" is not allowed for sell policies with quantize.";
64 throw ValueError(
ss.str());
71void MatlSellPolicy::set_transport_unit(std::string
x) {
76 std::vector<double>
fill = package_->GetFillMass(quantize_);
82 ss <<
"Quantize " << quantize_
83 <<
" packages cannot be shipped according to transport unit fill "
85 <<
tu->fill_min() <<
", " <<
tu->fill_max() <<
")";
86 throw ValueError(
ss.str());
133 std::string package_name,
141 set_package(package_name);
147 commods_.insert(commod);
153 std::stringstream
ss;
154 ss <<
"No manager set on Sell Policy " << name_;
162 std::stringstream
ss;
163 ss <<
"No manager set on Sell Policy " << name_;
171 double bcap = buf_->quantity();
173 quantize_ *
static_cast<int>(std::floor(
bcap / quantize_)) :
bcap;
174 return std::min(throughput_,
limit);
179 std::set<BidPortfolio<Material>::Ptr>
ports;
183 if (buf_->empty() || buf_->quantity() <
eps()||
limit <
eps())
200 std::vector<double> bids;
201 std::set<std::string>::iterator
sit;
202 std::vector<Request<Material>*>::const_iterator
rit;
203 for (
sit = commods_.begin();
sit != commods_.end(); ++
sit) {
205 if (commod_requests.count(commod) < 1)
208 const std::vector<Request<Material>*>& requests =
209 commod_requests.at(commod);
210 for (
rit = requests.begin();
rit != requests.end(); ++
rit) {
212 qty = std::min(
req->target()->quantity(),
limit);
214 std::vector<double> bids;
216 int n_full_bids =
static_cast<int>(std::floor(qty / quantize_));
219 bids = package_->GetFillMass(qty);
223 int shippable_pkgs = transport_unit_->MaxShippablePackages(bids.size());
232 std::vector<double>::iterator
bit;
233 for (
bit = bids.begin();
bit != bids.end(); ++
bit) {
234 offer = ignore_comp_ ? \
235 Material::CreateUntracked(*
bit,
req->target()->comp()) : \
236 Material::CreateUntracked(*
bit, m->comp());
238 LG(
INFO3) <<
" - bid " << *
bit <<
" kg on a request for " << commod;
249 std::vector<Trade<Material> >::const_iterator
it;
259 LGH(
INFO3) <<
" sending " << qty <<
" kg of " <<
it->request->commodity();
266 if (package_->name() !=
mat->package_name()) {
288 trade_mat->Transmute(
it->request->target()->comp());
The abstract base class used by all types of agents that live and interact in a simulation.
Context * context() const
Returns this agent's simulation context.
A BidPortfolio is a collection of bids as responses to requests for resources and associated constrai...
boost::shared_ptr< BidPortfolio< T > > Ptr
A CapacityConstraint provides an ability to determine an agent's constraints on resource allocation g...
boost::shared_ptr< Composition > Ptr
void UnregisterTrader(Trader *e)
Unregisters an agent as a participant in resource exchanges.
void RegisterTrader(Trader *e)
Registers an agent as a participant in resource exchanges.
Package::Ptr GetPackage(std::string name)
Retrieve a registered package.
TransportUnit::Ptr GetTransportUnit(std::string name)
Retrieve a registered transport unit.
The material class is primarily responsible for enabling basic material manipulation while helping en...
boost::shared_ptr< Material > Ptr
static Ptr CreateUntracked(double quantity, Composition::Ptr c)
Creates a new material resource that does not actually exist as part of the simulation and is untrack...
Package is a class that packages materials into discrete items in ways.
boost::shared_ptr< Package > Ptr
static std::string unpackaged_name()
A Request encapsulates all the information required to communicate the needs of an agent in the Dynam...
A simple API for agents that wish to exchange resources in the simulation.
virtual Agent * manager()
TransportUnit is a class that can be used in conjunction with packages to restrict the amount of mate...
static std::string unrestricted_name()
boost::shared_ptr< TransportUnit > Ptr
For values that are too big, too small, etc.
bool AlmostEq(const CompMap &v1, const CompMap &v2, double threshold)
Returns true if all nuclides of v1 and v2 are the same within threshold.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
double eps_rsrc()
an epsilon value to be used by resources
double eps()
a generic epsilon value
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
std::map< std::string, std::vector< Request< T > * > > type
A Trade is a simple container that associates a request for a resource with a bid for that resource.