CYCLUS
trader.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_TRADER_H_
2 #define CYCLUS_SRC_TRADER_H_
3 
4 #include <set>
5 
6 #include "bid_portfolio.h"
7 #include "composition.h"
8 #include "exchange_context.h"
9 #include "product.h"
10 #include "material.h"
11 #include "request_portfolio.h"
12 #include "trade.h"
13 
14 namespace cyclus {
15 
16 /// @class Trader
17 ///
18 /// @brief A simple API for agents that wish to exchange resources in the
19 /// simulation
20 ///
21 /// A Trader is a mixin class designed for agents that wish to exchange
22 /// resources. It defines the API for the querying of requests, offers, and the
23 /// corresponding exchanges.
24 class Trader {
25  public:
26  Trader(Agent* manager) : manager_(manager) {}
27 
28  virtual Agent* manager() {
29  return manager_;
30  }
31 
32  /// @brief default implementation for material requests
33  virtual std::set<RequestPortfolio<Material>::Ptr>
35  return std::set<RequestPortfolio<Material>::Ptr>();
36  }
37 
38  /// @brief default implementation for product requests
39  virtual std::set<RequestPortfolio<Product>::Ptr>
41  return std::set<RequestPortfolio<Product>::Ptr>();
42  }
43 
44  /// @brief default implementation for material requests
45  virtual std::set<BidPortfolio<Material>::Ptr>
47  return std::set<BidPortfolio<Material>::Ptr>();
48  }
49 
50  /// @brief default implementation for product requests
51  virtual std::set<BidPortfolio<Product>::Ptr>
53  return std::set<BidPortfolio<Product>::Ptr>();
54  }
55 
56  /// default implementation for material preferences.
57  virtual void AdjustMatlPrefs(PrefMap<Material>::type& prefs) {}
58 
59  /// default implementation for material preferences.
61 
62  /// @brief default implementation for responding to material trades
63  /// @param trades all trades in which this trader is the supplier
64  /// @param responses a container to populate with responses to each trade
65  virtual void GetMatlTrades(
66  const std::vector< Trade<Material> >& trades,
67  std::vector<std::pair<Trade<Material>, Material::Ptr> >& responses) {}
68 
69  /// @brief default implementation for responding to product trades
70  /// @param trades all trades in which this trader is the supplier
71  /// @param responses a container to populate with responses to each trade
72  virtual void GetProductTrades(
73  const std::vector< Trade<Product> >& trades,
74  std::vector<std::pair<Trade<Product>,
75  Product::Ptr> >& responses) {}
76 
77  /// @brief default implementation for material trade acceptance
78  virtual void AcceptMatlTrades(
79  const std::vector<std::pair<Trade<Material>,
80  Material::Ptr> >& responses) {}
81 
82  /// @brief default implementation for product trade acceptance
83  virtual void AcceptProductTrades(
84  const std::vector<std::pair<Trade<Product>,
85  Product::Ptr> >& responses) {}
86 
87  protected:
89 
90  private:
91  /// @warning this function is hidden to prevent an invalid signature that can
92  /// raise difficult to find bugs
93  virtual std::set<BidPortfolio<Material>::Ptr>
94  GetMatlBids(const CommodMap<Material>::type& commod_requests) {
95  return std::set<BidPortfolio<Material>::Ptr>();
96  }
97 
98  /// @warning this function is hidden to prevent an invalid signature that can
99  /// raise difficult to find bugs
100  virtual std::set<BidPortfolio<Product>::Ptr>
101  GetProductBids(const CommodMap<Product>::type& commod_requests) {
102  return std::set<BidPortfolio<Product>::Ptr>();
103  }
104 };
105 
106 } // namespace cyclus
107 
108 #endif // CYCLUS_SRC_TRADER_H_
std::map< std::string, std::vector< Request< T > * > > type
virtual void GetProductTrades(const std::vector< Trade< Product > > &trades, std::vector< std::pair< Trade< Product >, Product::Ptr > > &responses)
default implementation for responding to product trades
Definition: trader.h:72
boost::shared_ptr< Material > Ptr
Definition: material.h:75
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
Trader(Agent *manager)
Definition: trader.h:26
virtual std::set< RequestPortfolio< Material >::Ptr > GetMatlRequests()
default implementation for material requests
Definition: trader.h:34
std::map< Request< T > *, std::map< Bid< T > *, double > > type
virtual void AcceptProductTrades(const std::vector< std::pair< Trade< Product >, Product::Ptr > > &responses)
default implementation for product trade acceptance
Definition: trader.h:83
virtual void AdjustMatlPrefs(PrefMap< Material >::type &prefs)
default implementation for material preferences.
Definition: trader.h:57
virtual Agent * manager()
Definition: trader.h:28
virtual void GetMatlTrades(const std::vector< Trade< Material > > &trades, std::vector< std::pair< Trade< Material >, Material::Ptr > > &responses)
default implementation for responding to material trades
Definition: trader.h:65
virtual void AdjustProductPrefs(PrefMap< Product >::type &prefs)
default implementation for material preferences.
Definition: trader.h:60
virtual std::set< BidPortfolio< Material >::Ptr > GetMatlBids(CommodMap< Material >::type &commod_requests)
default implementation for material requests
Definition: trader.h:46
Agent * manager_
Definition: trader.h:88
The abstract base class used by all types of agents that live and interact in a simulation.
Definition: agent.h:51
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
virtual std::set< BidPortfolio< Product >::Ptr > GetProductBids(CommodMap< Product >::type &commod_requests)
default implementation for product requests
Definition: trader.h:52
virtual void AcceptMatlTrades(const std::vector< std::pair< Trade< Material >, Material::Ptr > > &responses)
default implementation for material trade acceptance
Definition: trader.h:78
virtual std::set< RequestPortfolio< Product >::Ptr > GetProductRequests()
default implementation for product requests
Definition: trader.h:40