1#ifndef CYCLUS_SRC_TRADE_EXECUTOR_H_
2#define CYCLUS_SRC_TRADE_EXECUTOR_H_
29 std::map<Trader*, std::vector< std::pair<Trade<T>,
typename T::Ptr> > >
34 std::map<std::pair<Trader*, Trader*>,
35 std::vector< std::pair<Trade<T>,
typename T::Ptr> > >
all_trades;
79 typename std::map<std::pair<Trader*, Trader*>,
80 std::vector< std::pair<Trade<T>,
typename T::Ptr> > >::iterator m_it;
81 for (m_it = trade_ctx_.all_trades.begin();
82 m_it != trade_ctx_.all_trades.end(); ++m_it) {
83 Agent* supplier = m_it->first.first->manager();
84 Agent* requester = m_it->first.second->manager();
85 typename std::vector< std::pair<Trade<T>,
typename T::Ptr> >&
86 trades = m_it->second;
87 typename std::vector< std::pair<Trade<T>,
typename T::Ptr> >::iterator
89 for (v_it = trades.begin(); v_it != trades.end(); ++v_it) {
91 typename T::Ptr rsrc = v_it->second;
95 ->AddVal(
"SenderId", supplier->
id())
96 ->AddVal(
"ReceiverId", requester->
id())
97 ->AddVal(
"ResourceId", rsrc->state_id())
98 ->AddVal(
"Commodity", trade.
request->commodity())
99 ->AddVal(
"Time", ctx->
time())
114 const std::vector< Trade<T> >& trades_;
121 const std::vector<
Trade<T> >& trades) {
122 typename std::vector< Trade<T> >::const_iterator it;
123 for (it = trades.begin(); it != trades.end(); ++it) {
125 trade_ctx.
suppliers.insert(it->bid->bidder());
126 trade_ctx.
requesters.insert(it->request->requester());
134 std::set<Trader*>::iterator it;
139 std::vector< std::pair<Trade<T>,
typename T::Ptr> > responses;
144 typename std::vector< std::pair<Trade<T>,
typename T::Ptr> >::iterator r_it;
145 for (r_it = responses.begin(); r_it != responses.end(); ++r_it) {
152 Trader* requester = r_it->first.request->requester();
154 trade_ctx.
all_trades[std::make_pair(supplier, requester)].push_back(*r_it);
161 std::set<Trader*>::iterator it;
The abstract base class used by all types of agents that live and interact in a simulation.
virtual const int id() const
The agent instance's unique ID within a simulation.
A simulation context provides access to necessary simulation-global functions and state.
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
virtual int time()
Returns the current simulation timestep.
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
The TradeExecutor is an object whose task is to execute a collection of Trades.
TradeExecutor(const std::vector< Trade< T > > &trades)
const TradeExecutionContext< T > & trade_ctx() const
TradeExecutionContext< T > & trade_ctx()
void ExecuteTrades(Context *ctx)
execute all trades, collecting responders from bidders and sending responses to requesters
void ExecuteTrades()
execute all trades, collecting responders from bidders and sending responses to requesters
void RecordTrades(Context *ctx)
Record all trades with the appropriate backends.
A simple API for agents that wish to exchange resources in the simulation.
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
static void PopulateTradeResponses(Trader *trader, const std::vector< Trade< T > > &trades, std::vector< std::pair< Trade< T >, typename T::Ptr > > &responses)
static void SendTradeResources(TradeExecutionContext< T > &trade_ctx)
static void AcceptTrades(Trader *trader, const std::vector< std::pair< Trade< T >, typename T::Ptr > > &responses)
void GroupTradesBySupplier(TradeExecutionContext< T > &trade_ctx, const std::vector< Trade< T > > &trades)
populates suppliers_, requesters_, and trades_by_supplier_
static void GetTradeResponses(TradeExecutionContext< T > &trade_ctx)
queries each supplier for the responses to thier matched trade and populates trades_by_requester_ and...
void Warn(const std::string &msg)
Issue a warning with the approriate message, accoring to the current warning settings.
std::set< Trader * > requesters
std::map< std::pair< Trader *, Trader * >, std::vector< std::pair< Trade< T >, typename T::Ptr > > > all_trades
std::set< Trader * > suppliers
std::map< Trader *, std::vector< std::pair< Trade< T >, typename T::Ptr > > > trades_by_requester
std::map< Trader *, std::vector< Trade< T > > > trades_by_supplier
A Trade is a simple container that associates a request for a resource with a bid for that resource.