CYCLUS
bid.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_BID_H_
2 #define CYCLUS_SRC_BID_H_
3 
4 #include <boost/shared_ptr.hpp>
5 #include <boost/weak_ptr.hpp>
6 #include <limits>
7 
8 #include "request.h"
9 
10 namespace cyclus {
11 
12 class Trader;
13 template <class T> class BidPortfolio;
14 
15 /// @class Bid
16 ///
17 /// @brief A Bid encapsulates all the information required to communicate a bid
18 /// response to a request for a resource, including the resource bid and the
19 /// bidder.
20 template <class T> class Bid {
21  public:
22  /// @brief a factory method for a bid
23  /// @param request the request being responded to by this bid
24  /// @param offer the resource being offered in response to the request
25  /// @param bidder the bidder
26  /// @param portfolio the porftolio of which this bid is a part
27  /// @param exclusive flag for whether the bid is exclusive
28  /// @param preference specifies the preference of a bid in a request
29  /// to bid arc. If NaN the request preference is used.
30  /// WARNING: This should only be set by the bidder using the
31  /// requests callback cost function. Bidders should not
32  /// arbitrarily set this preference.
33  inline static Bid<T>* Create(Request<T>* request,
34  boost::shared_ptr<T>
35  offer,
36  Trader* bidder,
38  bool exclusive,
39  double preference) {
41  }
42 
43  /// @brief a factory method for a bid
44  /// @param request the request being responded to by this bid
45  /// @param offer the resource being offered in response to the request
46  /// @param bidder the bidder
47  /// @param portfolio the porftolio of which this bid is a part
48  /// @param exclusive flag for whether the bid is exclusive
49  inline static Bid<T>* Create(Request<T>* request,
50  boost::shared_ptr<T>
51  offer,
52  Trader* bidder,
54  bool exclusive = false) {
55  return Create(request, offer, bidder, portfolio, exclusive,
56  std::numeric_limits<double>::quiet_NaN());
57  }
58  /// @brief a factory method for a bid for a bid without a portfolio
59  /// @warning this factory should generally only be used for testing
60  inline static Bid<T>* Create(Request<T>* request, boost::shared_ptr<T> offer,
61  Trader* bidder, bool exclusive,
62  double preference) {
64  }
65  /// @brief a factory method for a bid for a bid without a portfolio
66  /// @warning this factory should generally only be used for testing
67  inline static Bid<T>* Create(Request<T>* request, boost::shared_ptr<T> offer,
68  Trader* bidder, bool exclusive = false) {
69  return Create(request, offer, bidder, exclusive,
70  std::numeric_limits<double>::quiet_NaN());
71  }
72 
73  /// @return the request being responded to
74  inline Request<T>* request() const { return request_; }
75 
76  /// @return the bid object for the request
77  inline boost::shared_ptr<T> offer() const { return offer_; }
78 
79  /// @return the agent responding the request
80  inline Trader* bidder() const { return bidder_; }
81 
82  /// @return the portfolio of which this bid is a part
83  inline typename BidPortfolio<T>::Ptr portfolio() { return portfolio_.lock(); }
84 
85  /// @return whether or not this an exclusive bid
86  inline bool exclusive() const { return exclusive_; }
87 
88  /// @return the preference of this bid
89  inline double preference() const { return preference_; }
90 
91  private:
92  /// @brief constructors are private to require use of factory methods
93  Bid(Request<T>* request, boost::shared_ptr<T> offer, Trader* bidder,
94  bool exclusive, double preference)
95  : request_(request),
96  offer_(offer),
97  bidder_(bidder),
98  exclusive_(exclusive),
99  preference_(preference) {}
100  /// @brief constructors are private to require use of factory methods
101  Bid(Request<T>* request, boost::shared_ptr<T> offer, Trader* bidder,
102  bool exclusive = false)
103  : request_(request),
104  offer_(offer),
105  bidder_(bidder),
106  exclusive_(exclusive),
107  preference_(std::numeric_limits<double>::quiet_NaN()) {}
108 
109  Bid(Request<T>* request, boost::shared_ptr<T> offer, Trader* bidder,
110  typename BidPortfolio<T>::Ptr portfolio, bool exclusive, double preference)
111  : request_(request),
112  offer_(offer),
113  bidder_(bidder),
114  portfolio_(portfolio),
115  exclusive_(exclusive),
116  preference_(preference) {}
117 
118  Bid(Request<T>* request, boost::shared_ptr<T> offer, Trader* bidder,
119  typename BidPortfolio<T>::Ptr portfolio, bool exclusive = false)
120  : request_(request),
121  offer_(offer),
122  bidder_(bidder),
123  portfolio_(portfolio),
124  exclusive_(exclusive),
125  preference_(std::numeric_limits<double>::quiet_NaN()) {}
126 
127  Request<T>* request_;
128  boost::shared_ptr<T> offer_;
129  Trader* bidder_;
130  boost::weak_ptr<BidPortfolio<T>> portfolio_;
131  bool exclusive_;
132  double preference_;
133 };
134 
135 } // namespace cyclus
136 #endif // CYCLUS_SRC_BID_H_
boost::shared_ptr< T > offer() const
Definition: bid.h:77
boost::shared_ptr< BidPortfolio< T > > Ptr
Definition: bid_portfolio.h:34
Trader * bidder() const
Definition: bid.h:80
static Bid< T > * Create(Request< T > *request, boost::shared_ptr< T > offer, Trader *bidder, bool exclusive=false)
a factory method for a bid for a bid without a portfolio
Definition: bid.h:67
A simple API for agents that wish to exchange resources in the simulation.
Definition: trader.h:24
bool exclusive() const
Definition: bid.h:86
BidPortfolio< T >::Ptr portfolio()
Definition: bid.h:83
A Bid encapsulates all the information required to communicate a bid response to a request for a reso...
Definition: bid.h:20
double preference() const
Definition: bid.h:89
static Bid< T > * Create(Request< T > *request, boost::shared_ptr< T > offer, Trader *bidder, typename BidPortfolio< T >::Ptr portfolio, bool exclusive=false)
a factory method for a bid
Definition: bid.h:49
A BidPortfolio is a collection of bids as responses to requests for resources and associated constrai...
Definition: bid.h:13
static Bid< T > * Create(Request< T > *request, boost::shared_ptr< T > offer, Trader *bidder, bool exclusive, double preference)
a factory method for a bid for a bid without a portfolio
Definition: bid.h:60
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
Request< T > * request() const
Definition: bid.h:74
static Bid< T > * Create(Request< T > *request, boost::shared_ptr< T > offer, Trader *bidder, typename BidPortfolio< T >::Ptr portfolio, bool exclusive, double preference)
a factory method for a bid
Definition: bid.h:33
A Request encapsulates all the information required to communicate the needs of an agent in the Dynam...
Definition: request.h:29