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) {
84 Agent* requester =
m_it->first.second->manager();
85 typename std::vector< std::pair<Trade<T>,
typename T::Ptr> >&
87 typename std::vector< std::pair<Trade<T>,
typename T::Ptr> >::iterator
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_;
122 typename std::vector< Trade<T> >::const_iterator
it;
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;
152 Trader* requester =
r_it->first.request->requester();
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)
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
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...
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.