1 #ifndef CYCLUS_SRC_REQUEST_PORTFOLIO_H_ 2 #define CYCLUS_SRC_REQUEST_PORTFOLIO_H_ 10 #include <boost/enable_shared_from_this.hpp> 11 #include <boost/shared_ptr.hpp> 24 return total += r->
target()->quantity();
37 boost::shared_ptr<T> offer,
48 std::map<Request<T>*,
double>
coeffs;
87 :
public boost::enable_shared_from_this<RequestPortfolio<T>> {
89 typedef boost::shared_ptr<RequestPortfolio<T>>
Ptr;
96 typename std::vector<Request<T>*>::iterator it;
97 for (it = requests_.begin(); it != requests_.end(); ++it) {
120 commodity, preference, exclusive, cost_function);
122 requests_.push_back(r);
124 qty_ += target->quantity();
141 bool exclusive =
false) {
142 return AddRequest(target, requester, commodity, preference, exclusive,
151 std::accumulate(rs.begin(), rs.end(), 0.0, SumQty<T>) / rs.size();
154 for (
int i = 0; i < rs.size(); i++) {
156 qty = r->
target()->quantity();
157 mass_coeffs_[r] = r->
target()->quantity() / avg_qty;
167 constraints_.insert(c);
178 inline double qty()
const {
return qty_; }
181 inline const std::vector<Request<T>*>&
requests()
const {
return requests_; }
184 inline const std::set<CapacityConstraint<T>>&
constraints()
const {
197 requester_ = rhs.requester_;
198 requests_ = rhs.requests_;
199 constraints_ = rhs.constraints_;
201 typename std::vector<Request<T>*>::iterator it;
202 for (it = requests_.begin(); it != requests_.end(); ++it) {
203 it->get()->set_portfolio(this->shared_from_this());
214 if (requester_ == NULL) {
216 }
else if (requester_ != r->
requester()) {
217 std::string msg =
"Insertion error: requesters do not match.";
224 std::vector<Request<T>*> requests_;
227 std::map<Request<T>*,
double> mass_coeffs_;
230 std::set<CapacityConstraint<T>> constraints_;
239 #endif // CYCLUS_SRC_REQUEST_PORTFOLIO_H_ a simple interface for converting resource objects to unit capacities
An arc represents a possible connection between two nodes in the bipartite resource exchange graph...
static const double kDefaultPref
Default preference values are unity.
boost::shared_ptr< T > target() const
void AddConstraint(const CapacityConstraint< T > &c)
add a capacity constraint associated with the portfolio, if it doesn't already exist ...
boost::shared_ptr< RequestPortfolio< T > > Ptr
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
boost::shared_ptr< ExchangeNode > unode() const
A CapacityConstraint provides an ability to determine an agent's constraints on resource allocation g...
A simple API for agents that wish to exchange resources in the simulation.
const std::set< CapacityConstraint< T > > & constraints() const
Request< T > * AddRequest(boost::shared_ptr< T > target, Trader *requester, std::string commodity, double preference, bool exclusive, cost_function_t cost_function)
add a request to the portfolio
const std::vector< Request< T > * > & requests() const
Request< T > * AddRequest(boost::shared_ptr< T > target, Trader *requester, std::string commodity="", double preference=kDefaultPref, bool exclusive=false)
add a request to the portfolio
~RequestPortfolio()
deletes all requests associated with it
Trader * requester() const
void AddRequest(ExchangeTranslationContext< T > &translation_ctx, Request< T > *r, ExchangeNode::Ptr n)
Adds a request-node mapping.
virtual bool operator==(Converter< T > &other) const
operator== is available for subclassing, see cyclus::TrivialConverter for an example ...
Converter< T >::Ptr qty_converter()
returns a capacity converter for this portfolios request quantities
std::map< Request< T > *, double > coeffs
virtual double convert(boost::shared_ptr< T > offer, Arc const *a, ExchangeTranslationContext< T > const *ctx) const
convert a capacitated quantity for an offer in its exchange context
void AddMutualReqs(const std::vector< Request< T > *> &rs)
adds a collection of requests (already having been registered with this portfolio) as multicommodity ...
Trader * requester() const
An ExchangeTranslationContext is a simple holder class for any information needed to translate a Reso...
boost::shared_ptr< Converter< T > > Ptr
provide coefficients for default mass constraints
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
double SumQty(double total, Request< T > *r)
accumulator sum for request quantities
QtyCoeffConverter(const std::map< Request< T > *, double > &coeffs)
std::function< double(boost::shared_ptr< T >)> cost_function_t
double qty() const
, all requests in a portfolio must have the same quantity, which is checked during AddRequest() ...
std::map< ExchangeNode::Ptr, Request< T > * > node_to_request
For failed retrieval/insertion of key-based data into/from data structures.
A Request encapsulates all the information required to communicate the needs of an agent in the Dynam...
A RequestPortfolio is a group of (possibly constrainted) requests for resources.