CYCLUS
trader_management.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_TRADER_MANAGEMENT_H_
2 #define CYCLUS_SRC_TRADER_MANAGEMENT_H_
3 
4 #include "error.h"
5 #include "exchange_context.h"
6 #include "product.h"
7 #include "material.h"
8 #include "trader.h"
9 
10 namespace cyclus {
11 
12 // template specializations to support inheritance and virtual functions
13 template<class T>
14 inline static std::set<typename RequestPortfolio<T>::Ptr>
16  throw StateError("Non-specialized version of QueryRequests not supported");
17 }
18 
19 template<>
20 inline std::set<RequestPortfolio<Material>::Ptr>
22  return t->GetMatlRequests();
23 }
24 
25 template<>
26 inline std::set<RequestPortfolio<Product>::Ptr>
28  return t->GetProductRequests();
29 }
30 
31 template<class T>
32 inline static std::set<typename BidPortfolio<T>::Ptr>
33  QueryBids(Trader* t, typename CommodMap<T>::type& map) {
34  throw StateError("Non-specialized version of QueryBids not supported");
35 }
36 
37 template<>
38 inline std::set<BidPortfolio<Material>::Ptr>
40  return t->GetMatlBids(map);
41 }
42 
43 template<>
44 inline std::set<BidPortfolio<Product>::Ptr>
46  return t->GetProductBids(map);
47 }
48 
49 template<class T>
50 inline static void PopulateTradeResponses(
51  Trader* trader,
52  const std::vector< Trade<T> >& trades,
53  std::vector< std::pair<Trade<T>, typename T::Ptr> >& responses) {
54  throw StateError("Non-specialized version of "
55  "PopulateTradeResponses not supported");
56 }
57 
58 template<>
60  Trader* trader,
61  const std::vector< Trade<Material> >& trades,
62  std::vector<std::pair<Trade<Material>, Material::Ptr> >& responses) {
63  dynamic_cast<Trader*>(trader)->GetMatlTrades(trades, responses);
64 }
65 
66 template<>
68  Trader* trader,
69  const std::vector< Trade<Product> >& trades,
70  std::vector<std::pair<Trade<Product>, Product::Ptr> >& responses) {
71  trader->GetProductTrades(trades, responses);
72 }
73 
74 template<class T>
75 inline static void AcceptTrades(
76  Trader* trader,
77  const std::vector< std::pair<Trade<T>, typename T::Ptr> >& responses) {
78  throw StateError("Non-specialized version of AcceptTrades not supported");
79 }
80 
81 template<>
82 inline void AcceptTrades(
83  Trader* trader,
84  const std::vector< std::pair<Trade<Material>, Material::Ptr> >& responses) {
85  dynamic_cast<Trader*>(trader)->AcceptMatlTrades(responses);
86 }
87 
88 template<>
89 inline void AcceptTrades(
90  Trader* trader,
91  const std::vector< std::pair<Trade<Product>, Product::Ptr> >& responses) {
92  trader->AcceptProductTrades(responses);
93 }
94 
95 } // namespace cyclus
96 
97 #endif // CYCLUS_SRC_TRADER_MANAGEMENT_H_
std::map< std::string, std::vector< Request< T > * > > type
For failed object state expectations.
Definition: error.h:53
static std::set< typename BidPortfolio< T >::Ptr > QueryBids(Trader *t, typename CommodMap< T >::type &map)
boost::shared_ptr< Material > Ptr
Definition: material.h:75
void PopulateTradeResponses< Material >(Trader *trader, const std::vector< Trade< Material > > &trades, std::vector< std::pair< Trade< Material >, Material::Ptr > > &responses)
A simple API for agents that wish to exchange resources in the simulation.
Definition: trader.h:24
boost::shared_ptr< Product > Ptr
Definition: product.h:24
static std::set< typename RequestPortfolio< T >::Ptr > QueryRequests(Trader *t)
virtual void AcceptProductTrades(const std::vector< std::pair< Trade< Product >, Product::Ptr > > &responses)
default implementation for product trade acceptance
Definition: trader.h:83
static void PopulateTradeResponses(Trader *trader, const std::vector< Trade< T > > &trades, std::vector< std::pair< Trade< T >, typename T::Ptr > > &responses)
static void AcceptTrades(Trader *trader, const std::vector< std::pair< Trade< T >, typename T::Ptr > > &responses)
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
A Trade is a simple container that associates a request for a resource with a bid for that resource...
Definition: trade.h:16
std::set< BidPortfolio< Product >::Ptr > QueryBids< Product >(Trader *t, CommodMap< Product >::type &map)
std::set< BidPortfolio< Material >::Ptr > QueryBids< Material >(Trader *t, CommodMap< Material >::type &map)
std::set< RequestPortfolio< Material >::Ptr > QueryRequests< Material >(Trader *t)
void PopulateTradeResponses< Product >(Trader *trader, const std::vector< Trade< Product > > &trades, std::vector< std::pair< Trade< Product >, Product::Ptr > > &responses)
std::set< RequestPortfolio< Product >::Ptr > QueryRequests< Product >(Trader *t)