CYCLUS
Loading...
Searching...
No Matches
request.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_REQUEST_H_
2#define CYCLUS_SRC_REQUEST_H_
3
4#include <functional>
5#include <ostream>
6#include <string>
7
8#include <boost/shared_ptr.hpp>
9#include <boost/weak_ptr.hpp>
10
11namespace cyclus {
12
13class Material;
14
15/// Default preference values are unity. This has been updated from values of
16/// zero (which was the case prior to release 1.4). Preferences can be lower or
17/// higher than the default value, but must be positive.
18static const double kDefaultPref = 1;
19
20class Trader;
21template <class T> class RequestPortfolio;
22
23/// @class Request
24///
25/// @brief A Request encapsulates all the information required to communicate
26/// the needs of an agent in the Dynamic Resource Exchange, including the
27/// commodity it needs as well as a resource specification for that commodity.
28/// A Request is templated its resource.
29template <class T> class Request {
30 public:
31 typedef std::function<double(boost::shared_ptr<T>)> cost_function_t;
32
33 /// @brief a factory method for a request
34 /// @param target the target resource associated with this request
35 /// @param requester the requester
36 /// @param portfolio the porftolio of which this request is a part
37 /// @param commodity the commodity associated with this request
38 /// @param preference the preference associated with this request (relative to
39 /// others in the portfolio)
40 /// @param exclusive a flag denoting that this request must be met
41 /// exclusively,
42 /// i.e., in its entirety by a single offer
43 /// @param cost_function a standard function object that returns the cost of a
44 /// potential resource when called.
45 inline static Request<T>* Create(boost::shared_ptr<T> target,
48 std::string commodity,
49 double preference,
50 bool exclusive,
54 }
55 /// @brief a factory method for a request
56 /// @param target the target resource associated with this request
57 /// @param requester the requester
58 /// @param portfolio the porftolio of which this request is a part
59 /// @param commodity the commodity associated with this request
60 /// @param preference the preference associated with this request (relative to
61 /// others in the portfolio)
62 /// @param exclusive a flag denoting that this request must be met
63 /// exclusively,
64 /// i.e., in its entirety by a single offer
65 inline static Request<T>* Create(boost::shared_ptr<T> target,
68 std::string commodity = "",
69 double preference = kDefaultPref,
70 bool exclusive = false) {
73 }
74
75 /// @brief a factory method for a bid for a bid without a portfolio
76 /// @warning this factory should generally only be used for testing
77 inline static Request<T>* Create(boost::shared_ptr<T> target,
79 std::string commodity,
80 double preference,
81 bool exclusive,
85 }
86 /// @brief a factory method for a bid for a bid without a portfolio
87 /// @warning this factory should generally only be used for testing
88 inline static Request<T>* Create(boost::shared_ptr<T> target,
90 std::string commodity = "",
91 double preference = kDefaultPref,
92 bool exclusive = false) {
94 }
95
96 /// @return this request's target
97 inline boost::shared_ptr<T> target() const { return target_; }
98
99 /// @return the requester associated with this request
100 inline Trader* requester() const { return requester_; }
101
102 /// @return the commodity associated with this request
103 inline std::string commodity() const { return commodity_; }
104
105 /// @return the preference value for this request
106 inline double preference() const { return preference_; }
107
108 /// @return the portfolio of which this request is a part
109 inline typename RequestPortfolio<T>::Ptr portfolio() const {
110 return portfolio_.lock();
111 }
112
113 /// @return whether or not this an exclusive request
114 inline bool exclusive() const { return exclusive_; }
115
116 /// @return the cost function for the request
117 inline cost_function_t cost_function() const { return cost_function_; }
118
119 private:
120 /// @brief constructors are private to require use of factory methods
121 Request(boost::shared_ptr<T> target, Trader* requester, std::string commodity,
123 : target_(target),
124 requester_(requester),
125 commodity_(commodity),
126 preference_(preference),
127 exclusive_(exclusive),
128 cost_function_(cost_function) {}
129
130 /// @brief constructors are private to require use of factory methods
131 Request(boost::shared_ptr<T> target, Trader* requester,
132 std::string commodity = "", double preference = kDefaultPref,
133 bool exclusive = false)
134 : target_(target),
135 requester_(requester),
136 commodity_(commodity),
137 preference_(preference),
138 exclusive_(exclusive),
139 cost_function_(NULL) {}
140
141 Request(boost::shared_ptr<T> target, Trader* requester,
142 typename RequestPortfolio<T>::Ptr portfolio, std::string commodity,
144 : target_(target),
145 requester_(requester),
146 commodity_(commodity),
147 preference_(preference),
148 portfolio_(portfolio),
149 exclusive_(exclusive),
150 cost_function_(cost_function) {}
151
152 Request(boost::shared_ptr<T> target, Trader* requester,
154 std::string commodity = "", double preference = kDefaultPref,
155 bool exclusive = false)
156 : target_(target),
157 requester_(requester),
158 commodity_(commodity),
159 preference_(preference),
160 portfolio_(portfolio),
161 exclusive_(exclusive),
162 cost_function_(NULL) {}
163
164 boost::shared_ptr<T> target_;
165 Trader* requester_;
166 double preference_;
167 std::string commodity_;
168 boost::weak_ptr<RequestPortfolio<T>> portfolio_;
169 bool exclusive_;
170 cost_function_t cost_function_;
171};
172
173} // namespace cyclus
174
175#endif // CYCLUS_SRC_REQUEST_H_
A RequestPortfolio is a group of (possibly constrained) requests for resources.
boost::shared_ptr< RequestPortfolio< T > > Ptr
A Request encapsulates all the information required to communicate the needs of an agent in the Dynam...
Definition request.h:29
static Request< T > * Create(boost::shared_ptr< T > target, Trader *requester, std::string commodity, double preference, bool exclusive, cost_function_t cost_function)
a factory method for a bid for a bid without a portfolio
Definition request.h:77
static Request< T > * Create(boost::shared_ptr< T > target, Trader *requester, std::string commodity="", double preference=kDefaultPref, bool exclusive=false)
a factory method for a bid for a bid without a portfolio
Definition request.h:88
bool exclusive() const
Definition request.h:114
cost_function_t cost_function() const
Definition request.h:117
std::string commodity() const
Definition request.h:103
boost::shared_ptr< T > target() const
Definition request.h:97
std::function< double(boost::shared_ptr< T >)> cost_function_t
Definition request.h:31
double preference() const
Definition request.h:106
RequestPortfolio< T >::Ptr portfolio() const
Definition request.h:109
Trader * requester() const
Definition request.h:100
static Request< T > * Create(boost::shared_ptr< T > target, Trader *requester, typename RequestPortfolio< T >::Ptr portfolio, std::string commodity, double preference, bool exclusive, cost_function_t cost_function)
a factory method for a request
Definition request.h:45
static Request< T > * Create(boost::shared_ptr< T > target, Trader *requester, typename RequestPortfolio< T >::Ptr portfolio, std::string commodity="", double preference=kDefaultPref, bool exclusive=false)
a factory method for a request
Definition request.h:65
A simple API for agents that wish to exchange resources in the simulation.
Definition trader.h:24
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
static const double kDefaultPref
Default preference values are unity.
Definition request.h:18
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters