1#ifndef CYCLUS_SRC_RESOURCE_EXCHANGE_H_
2#define CYCLUS_SRC_RESOURCE_EXCHANGE_H_
72 std::for_each(traders_.begin(),
74 std::bind(&cyclus::ResourceExchange<T>::AddRequests_,
76 std::placeholders::_1));
82 std::for_each(traders_.begin(),
84 std::bind(&cyclus::ResourceExchange<T>::AddBids_,
86 std::placeholders::_1));
92 std::set<Trader*> traders = ex_ctx_.requesters;
93 std::for_each(traders.begin(),
95 std::bind(&cyclus::ResourceExchange<T>::AdjustPrefs_,
97 std::placeholders::_1));
102 inline bool Empty() {
return ex_ctx_.bids_by_request.empty(); }
106 if (traders_.size() == 0) {
107 std::set<Trader*> orig = sim_ctx_->
traders();
108 std::set<Trader*>::iterator it;
109 for (it = orig.begin(); it != orig.end(); ++it) {
110 traders_.insert(*it);
116 void AddRequests_(Trader* t) {
118 typename std::set<typename RequestPortfolio<T>::Ptr>::iterator it;
119 for (it = rp.begin(); it != rp.end(); ++it) {
120 ex_ctx_.AddRequestPortfolio(*it);
125 void AddBids_(Trader* t) {
126 std::set<typename BidPortfolio<T>::Ptr> bp =
128 typename std::set<typename BidPortfolio<T>::Ptr>::iterator it;
129 for (it = bp.begin(); it != bp.end(); ++it) {
130 ex_ctx_.AddBidPortfolio(*it);
136 void AdjustPrefs_(Trader* t) {
139 Agent* m = t->manager()->parent();
146 struct trader_compare {
147 bool operator()(Trader* lhs, Trader* rhs)
const {
148 int left = lhs->manager()->id();
149 int right = rhs->manager()->id();
162 std::set<Trader*, trader_compare> traders_;
165 ExchangeContext<T> ex_ctx_;
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
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