7 #define LG(X) LOG(LEV_##X, "buypol") 9 LOG(LEV_##X, "buypol") << "policy " << name_ << " (agent " \ 10 << Trader::manager()->prototype() << "-" \ 11 << Trader::manager()->id() << "): " 19 throughput_(
std::numeric_limits<double>::max()),
23 Warn<EXPERIMENTAL_WARNING>(
24 "MatlBuyPolicy is experimental and its API may be subject to change");
32 void MatlBuyPolicy::set_fill_to(
double x) {
34 x /= buf_->capacity();
35 assert(x > 0 && x <= 1.);
39 void MatlBuyPolicy::set_req_when_under(
double x) {
41 x /= buf_->capacity();
42 assert(x > 0 && x <= 1.);
46 void MatlBuyPolicy::set_quantize(
double x) {
51 void MatlBuyPolicy::set_throughput(
double x) {
69 set_throughput(throughput);
75 double fill_to,
double req_when_under) {
80 set_req_when_under(req_when_under);
86 double fill_to,
double req_when_under,
92 set_req_when_under(req_when_under);
93 set_quantize(quantize);
94 set_throughput(throughput);
100 c[10010000] = 1e-100;
105 return Set(commod, c, 1.0);
113 commod_details_[commod] = d;
119 std::stringstream ss;
120 ss <<
"No manager set on Buy Policy " << name_;
128 std::stringstream ss;
129 ss <<
"No manager set on Buy Policy " << name_;
136 rsrc_commods_.clear();
137 std::set<RequestPortfolio<Material>::Ptr> ports;
138 bool make_req = buf_->quantity() < req_when_under_ * buf_->capacity();
140 if (!make_req || amt <
eps())
144 double req_amt =
ReqQty();
146 LGH(INFO3) <<
"requesting " << amt <<
" kg via " << n_req <<
" request(s)";
149 for (
int i = 0; i != n_req; i++) {
151 std::vector<Request<Material>*> mreqs;
152 std::map<std::string, CommodDetail>::iterator it;
153 for (it = commod_details_.begin(); it != commod_details_.end(); ++it) {
155 CommodDetail d = it->second;
156 LG(INFO3) <<
" - one " << amt <<
" kg request of " << commod;
170 std::vector<std::pair<Trade<Material>,
Material::Ptr> >::const_iterator it;
171 rsrc_commods_.clear();
172 for (it = resps.begin(); it != resps.end(); ++it) {
173 rsrc_commods_[it->second] = it->first.request->commodity();
174 LGH(INFO3) <<
"got " << it->second->quantity() <<
" kg of " 175 << it->first.request->commodity();
176 buf_->Push(it->second);
void RegisterTrader(Trader *e)
Registers an agent as a participant in resource exchanges.
boost::shared_ptr< Composition > Ptr
boost::shared_ptr< RequestPortfolio< T > > Ptr
For values that are too big, too small, etc.
boost::shared_ptr< Material > Ptr
std::string name(int nuc)
A simple API for agents that wish to exchange resources in the simulation.
Request< T > * AddRequest(boost::shared_ptr< T > target, Trader *requester, std::string commodity, double preference, bool exclusive, cost_function_t cost_function)
add a request to the portfolio
std::map< Nuc, double > CompMap
a raw definition of nuclides and corresponding (dimensionless quantities).
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...
virtual Agent * manager()
void UnregisterTrader(Trader *e)
Unregisters an agent as a participant in resource exchanges.
Context * context() const
Returns this agent's simulation context.
void AddMutualReqs(const std::vector< Request< T > *> &rs)
adds a collection of requests (already having been registered with this portfolio) as multicommodity ...
The abstract base class used by all types of agents that live and interact in a simulation.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
A Trade is a simple container that associates a request for a resource with a bid for that resource...
double eps()
a generic epsilon value
static Ptr CreateFromMass(CompMap v)
Creates a new composition from v with its components having appropriate mass-based ratios...
A Request encapsulates all the information required to communicate the needs of an agent in the Dynam...
A RequestPortfolio is a group of (possibly constrainted) requests for resources.