CYCLUS
Loading...
Searching...
No Matches
exchange_context.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_EXCHANGE_CONTEXT_H_
2#define CYCLUS_SRC_EXCHANGE_CONTEXT_H_
3
4#include <assert.h>
5#include <map>
6#include <cmath>
7#include <string>
8#include <utility>
9#include <vector>
10
11#include "bid.h"
12#include "bid_portfolio.h"
13#include "request.h"
14#include "request_portfolio.h"
15
16// Undefines isnan from pyne
17#ifdef isnan
18 #undef isnan
19#endif
20
21
22namespace cyclus {
23
24template <class T>
25struct PrefMap {
26 typedef std::map<Request<T>*, std::map<Bid<T>*, double> > type;
28 typedef Bid<T>* bid_ptr;
29};
30
31template <class T>
32struct CommodMap {
33 typedef std::map<std::string, std::vector<Request<T>*> > type;
35};
36
37/// @class ExchangeContext
38///
39/// @brief The ExchangeContext is designed to provide an ease-of-use interface
40/// for querying and reaggregating information regarding requests and bids of a
41/// resource exchange.
42///
43/// The ExchangeContext is used by a ResourceExchange or related class to
44/// provide introspection into the requests and bids it collects. Specifically,
45/// this class is designed to assist in phases of the Dynamic Resource
46/// Exchange. The second phase, Response to Request for Bids, is assisted by
47/// grouping requests by commodity type. The third phase, preference adjustment,
48/// is assisted by grouping bids by the requester being responded to.
49template <class T>
51 public:
52 /// @brief adds a request to the context
54 requests.push_back(port);
55 const std::vector<Request<T>*>& vr = port->requests();
56 typename std::vector<Request<T>*>::const_iterator it;
57
58 for (it = vr.begin(); it != vr.end(); ++it) {
59 Request<T>* pr = *it;
60 AddRequest(*it);
61 }
62 }
63
64 /// @brief Adds an individual request
66 assert(pr->requester() != NULL);
67 requesters.insert(pr->requester());
68 commod_requests[pr->commodity()].push_back(pr);
69 }
70
71 /// @brief adds a bid to the context
73 bids.push_back(port);
74 const std::set<Bid<T>*>& vr = port->bids();
75 typename std::set<Bid<T>*>::const_iterator it;
76
77 for (it = vr.begin(); it != vr.end(); ++it) {
78 Bid<T>* pb = *it;
79 AddBid(pb);
80 }
81 }
82
83 /// @brief adds a bid to the appropriate containers, default trade preference
84 /// between request and bid is set
85 /// @param pb the bid
86 void AddBid(Bid<T>* pb) {
87 assert(pb->bidder() != NULL);
88 bidders.insert(pb->bidder());
89
90 bids_by_request[pb->request()].push_back(pb);
91
92 double bid_pref = pb->preference();
93 trader_prefs[pb->request()->requester()][pb->request()].insert(
94 std::make_pair(pb, std::isnan(bid_pref) ? pb->request()->preference() : bid_pref));
95 }
96
97 /// @brief a reference to an exchange's set of requests
98 std::vector<typename RequestPortfolio<T>::Ptr> requests;
99
100 /// @brief a reference to an exchange's set of bids
101 std::vector<typename BidPortfolio<T>::Ptr> bids;
102
103 /// @brief known requesters
104 std::set<Trader*> requesters;
105
106 /// @brief known bidders
107 std::set<Trader*> bidders;
108
109 /// @brief maps commodity name to requests for that commodity
111
112 /// @brief maps request to all bids for request
113 std::map< Request<T>*, std::vector<Bid<T>*> >
115
116 /// @brief maps commodity name to requests for that commodity
117 std::map<Trader*, typename PrefMap<T>::type> trader_prefs;
118};
119
120} // namespace cyclus
121
122#endif // CYCLUS_SRC_EXCHANGE_CONTEXT_H_
boost::shared_ptr< BidPortfolio< T > > Ptr
A Bid encapsulates all the information required to communicate a bid response to a request for a reso...
Definition bid.h:21
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
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
Request< T > * request_ptr
std::map< std::string, std::vector< Request< T > * > > type
The ExchangeContext is designed to provide an ease-of-use interface for querying and reaggregating in...
std::vector< typename BidPortfolio< T >::Ptr > bids
a reference to an exchange's set of bids
void AddBid(Bid< T > *pb)
adds a bid to the appropriate containers, default trade preference between request and bid is set
void AddRequest(Request< T > *pr)
Adds an individual request.
std::map< Trader *, typename PrefMap< T >::type > trader_prefs
maps commodity name to requests for that commodity
std::map< Request< T > *, std::vector< Bid< T > * > > bids_by_request
maps request to all bids for request
std::vector< typename RequestPortfolio< T >::Ptr > requests
a reference to an exchange's set of requests
void AddBidPortfolio(const typename BidPortfolio< T >::Ptr port)
adds a bid to the context
std::set< Trader * > requesters
known requesters
void AddRequestPortfolio(const typename RequestPortfolio< T >::Ptr port)
adds a request to the context
CommodMap< T >::type commod_requests
maps commodity name to requests for that commodity
std::set< Trader * > bidders
known bidders
std::map< Request< T > *, std::map< Bid< T > *, double > > type
Request< T > * request_ptr