5 #define LG(X) LOG(LEV_##X, "selpol") 7 LOG(LEV_##X, "selpol") << "policy " << name_ << " (agent " \ 8 << Trader::manager()->prototype() << "-" \ 9 << Trader::manager()->id() << "): " 18 throughput_(
std::numeric_limits<double>::max()),
20 Warn<EXPERIMENTAL_WARNING>(
21 "MatlSellPolicy is experimental and its API may be subject to change");
29 void MatlSellPolicy::set_quantize(
double x) {
34 void MatlSellPolicy::set_throughput(
double x) {
39 void MatlSellPolicy::set_ignore_comp(
bool x) {
56 set_throughput(throughput);
65 set_ignore_comp(ignore_comp);
75 set_throughput(throughput);
76 set_ignore_comp(ignore_comp);
82 bool ignore_comp,
double quantize) {
86 set_quantize(quantize);
87 set_throughput(throughput);
88 set_ignore_comp(ignore_comp);
93 commods_.insert(commod);
100 ss <<
"No manager set on Sell Policy " << name_;
108 std::stringstream ss;
109 ss <<
"No manager set on Sell Policy " << name_;
117 double bcap = buf_->quantity();
118 double limit =
Excl() ? \
119 quantize_ *
static_cast<int>(std::floor(bcap / quantize_)) : bcap;
120 return std::min(throughput_, limit);
125 std::set<BidPortfolio<Material>::Ptr> ports;
126 if (buf_->empty() || buf_->quantity() <
eps())
131 double limit =
Limit();
135 LGH(INFO3) <<
"bidding out " << limit <<
" kg";
143 std::set<std::string>::iterator sit;
144 std::vector<Request<Material>*>::const_iterator rit;
145 for (sit = commods_.begin(); sit != commods_.end(); ++sit) {
147 if (commod_requests.count(commod) < 1)
150 const std::vector<Request<Material>*>& requests =
151 commod_requests.at(commod);
152 for (rit = requests.begin(); rit != requests.end(); ++rit) {
154 qty = std::min(req->
target()->quantity(), limit);
155 nbids = excl ?
static_cast<int>(std::floor(qty / quantize_)) : 1;
156 qty = excl ? quantize_ : qty;
157 for (
int i = 0; i < nbids; i++) {
160 offer = ignore_comp_ ? \
161 Material::CreateUntracked(qty, req->
target()->comp()) : \
163 port->
AddBid(req, offer,
this, excl);
164 LG(INFO3) <<
" - bid " << qty <<
" kg on a request for " << commod;
175 std::vector<Trade<Material> >::const_iterator it;
176 for (it = trades.begin(); it != trades.end(); ++it) {
177 double qty = it->amt;
178 LGH(INFO3) <<
" sending " << qty <<
" kg of " << it->request->commodity();
181 mat->Transmute(it->request->target()->comp());
182 responses.push_back(std::make_pair(*it, mat));
std::map< std::string, std::vector< Request< T > * > > type
boost::shared_ptr< BidPortfolio< T > > Ptr
void RegisterTrader(Trader *e)
Registers an agent as a participant in resource exchanges.
boost::shared_ptr< Composition > Ptr
boost::shared_ptr< T > target() const
For values that are too big, too small, etc.
boost::shared_ptr< Material > Ptr
std::string name(int nuc)
A CapacityConstraint provides an ability to determine an agent's constraints on resource allocation g...
A simple API for agents that wish to exchange resources in the simulation.
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.
double eps_rsrc()
an epsilon value to be used by resources
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...
Bid< T > * AddBid(Request< T > *request, boost::shared_ptr< T > offer, Trader *bidder, bool exclusive, double preference)
add a bid to the portfolio
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
void AddConstraint(const CapacityConstraint< T > &c)
add a capacity constraint associated with the portfolio
A Request encapsulates all the information required to communicate the needs of an agent in the Dynam...