1#ifndef CYCLUS_SRC_RESOURCE_EXCHANGE_H_
2#define CYCLUS_SRC_RESOURCE_EXCHANGE_H_
82 std::placeholders::_1));
93 std::placeholders::_1));
99 std::set<Trader*> traders = ex_ctx_.requesters;
106 std::placeholders::_1));
111 inline bool Empty() {
return ex_ctx_.bids_by_request.empty(); }
115 if (traders_.size() == 0) {
116 std::set<Trader*> orig = sim_ctx_->
traders();
117 std::set<Trader*>::iterator it;
118 for (it = orig.begin(); it != orig.end(); ++it) {
119 traders_.insert(*it);
125 void AddRequests_(Trader* t) {
127 typename std::set<typename RequestPortfolio<T>::Ptr>::iterator it;
128 for (it = rp.begin(); it != rp.end(); ++it) {
129 ex_ctx_.AddRequestPortfolio(*it);
134 void AddBids_(Trader* t) {
135 std::set<typename BidPortfolio<T>::Ptr> bp =
137 typename std::set<typename BidPortfolio<T>::Ptr>::iterator it;
138 for (it = bp.begin(); it != bp.end(); ++it) {
139 ex_ctx_.AddBidPortfolio(*it);
145 void AdjustPrefs_(Trader* t) {
148 Agent* m = t->manager()->parent();
155 struct trader_compare {
156 bool operator()(Trader* lhs, Trader* rhs)
const {
157 int left = lhs->manager()->id();
158 int right = rhs->manager()->id();
171 std::set<Trader*, trader_compare> traders_;
174 ExchangeContext<T> ex_ctx_;
a holding class for information related to a TradeExecutor
The abstract base class used by all types of agents that live and interact in a simulation.
virtual void AdjustMatlPrefs(PrefMap< Material >::type &prefs)
default implementation for material preferences.
virtual void AdjustProductPrefs(PrefMap< Product >::type &prefs)
default implementation for material preferences.
A simulation context provides access to necessary simulation-global functions and state.
const std::set< Trader * > & traders() const
The ResourceExchange class manages the communication for the supply and demand of resources in a simu...
void AdjustAll()
adjust preferences for requests given bid responses
void AddAllBids()
queries traders and collects all responses to requests for bids
bool Empty()
return true if this is an empty exchange (i.e., no requests exist, therefore no bids)
ResourceExchange(Context *ctx)
default constructor
void AddAllRequests()
queries traders and collects all requests for bids
ExchangeContext< T > & ex_ctx()
A simple API for agents that wish to exchange resources in the simulation.
virtual void AdjustMatlPrefs(PrefMap< Material >::type &prefs)
default implementation for material preferences.
virtual void AdjustProductPrefs(PrefMap< Product >::type &prefs)
default implementation for material preferences.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
static std::set< typename BidPortfolio< T >::Ptr > QueryBids(Trader *t, typename CommodMap< T >::type &map)
static void AdjustPrefs(Agent *m, typename PrefMap< T >::type &prefs)
Preference adjustment method helpers to convert from templates to the Agent inheritance hierarchy.
static std::set< typename RequestPortfolio< T >::Ptr > QueryRequests(Trader *t)
The ExchangeContext is designed to provide an ease-of-use interface for querying and reaggregating in...
std::map< Request< T > *, std::map< Bid< T > *, double > > type