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;
97 typename std::vector<Request<T>*>::iterator it;
98 for (it = requests_.begin(); it != requests_.end(); ++it) {
117 std::string commodity,
double preference,
121 commodity, preference, exclusive, cost_function);
123 requests_.push_back(r);
125 qty_ += target->quantity();
140 std::string commodity =
"",
142 bool exclusive =
false) {
152 std::accumulate(rs.begin(), rs.end(), 0.0,
SumQty<T>) / rs.size();
155 for (
int i = 0; i < rs.size(); i++) {
158 mass_coeffs_[r] = r->
target()->quantity() / avg_qty;
168 constraints_.insert(c);
179 inline double qty()
const {
return qty_; }
182 inline const std::vector<Request<T>*>&
requests()
const {
return requests_; }
185 inline const std::set<CapacityConstraint<T>>&
constraints()
const {
198 requester_ = rhs.requester_;
199 requests_ = rhs.requests_;
200 constraints_ = rhs.constraints_;
202 typename std::vector<Request<T>*>::iterator it;
203 for (it = requests_.begin(); it != requests_.end(); ++it) {
204 it->get()->set_portfolio(this->shared_from_this());
214 void VerifyRequester_(
const Request<T>* r) {
215 if (requester_ == NULL) {
216 requester_ = r->requester();
217 }
else if (requester_ != r->requester()) {
218 std::string msg =
"Insertion error: requesters do not match.";
225 std::vector<Request<T>*> requests_;
228 std::map<Request<T>*,
double> mass_coeffs_;
231 std::set<CapacityConstraint<T>> constraints_;
An arc represents a possible connection between two nodes in the bipartite resource exchange graph.
boost::shared_ptr< ExchangeNode > unode() const
A CapacityConstraint provides an ability to determine an agent's constraints on resource allocation g...
A RequestPortfolio is a group of (possibly constrained) requests for resources.
const std::set< CapacityConstraint< T > > & constraints() const
std::function< double(boost::shared_ptr< T >)> cost_function_t
void AddMutualReqs(const std::vector< Request< T > * > &rs)
adds a collection of requests (already having been registered with this portfolio) as multicommodity ...
Converter< T >::Ptr qty_converter()
returns a capacity converter for this portfolios request quantities
~RequestPortfolio()
deletes all requests associated with it
const std::vector< Request< T > * > & requests() const
double qty() const
, all requests in a portfolio must have the same quantity, which is checked during AddRequest()
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
Request< T > * request_ptr
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
Trader * requester() 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
A Request encapsulates all the information required to communicate the needs of an agent in the Dynam...
boost::shared_ptr< T > target() const
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
A simple API for agents that wish to exchange resources in the simulation.
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
static const double kDefaultPref
Default preference values are unity.
double SumQty(double total, Request< T > *r)
accumulator sum for request quantities
a simple interface for converting resource objects to unit capacities
boost::shared_ptr< Converter< T > > Ptr
An ExchangeTranslationContext is a simple holder class for any information needed to translate a Reso...
std::map< ExchangeNode::Ptr, Request< T > * > node_to_request
provide coefficients for default mass constraints
virtual bool operator==(Converter< T > &other) const
operator== is available for subclassing, see cyclus::TrivialConverter for an example
std::map< Request< T > *, double > coeffs
QtyCoeffConverter(const 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