1#ifndef CYCLUS_SRC_EXCHANGE_TRANSLATOR_H_
2#define CYCLUS_SRC_EXCHANGE_TRANSLATOR_H_
47 const std::vector<typename RequestPortfolio<T>::Ptr>& requests =
49 typename std::vector<typename RequestPortfolio<T>::Ptr>::const_iterator
51 for (rp_it = requests.begin(); rp_it != requests.end(); ++rp_it) {
53 (*rp_it)->AddConstraint(c);
56 graph->AddRequestGroup(rs);
60 const std::vector<typename BidPortfolio<T>::Ptr>& bidports = ex_ctx_->bids;
61 typename std::vector<typename BidPortfolio<T>::Ptr>::const_iterator bp_it;
62 for (bp_it = bidports.begin(); bp_it != bidports.end(); ++bp_it) {
64 graph->AddSupplyGroup(ns);
67 const std::set<Bid<T>*>& bids = (*bp_it)->bids();
68 typename std::set<Bid<T>*>::const_iterator b_it;
69 for (b_it = bids.begin(); b_it != bids.end(); ++b_it) {
83 ex_ctx_->trader_prefs.at(req->
requester())[req][bid];
87 CLOG(
LEV_DEBUG1) <<
"Removing arc because of negative preference.";
89 }
else if (pref == 0) {
91 ss <<
"0-valued preferences have been deprecated. "
92 <<
"Please make preference value positive."
93 <<
"This message will go away in before the next release (1.5).";
98 a.
unode()->prefs[a] = pref;
99 int n_prefs = a.
unode()->prefs.size();
103 <<
"'s trade nodes:";
112 std::vector<Match>::const_iterator m_it;
114 <<
" trade matches.";
115 for (m_it = matches.begin(); m_it != matches.end(); ++m_it) {
157 typename std::vector<Request<T>*>::const_iterator r_it;
167 rs->AddExchangeNode(n);
173 <<
" request capacities";
174 typename std::set< CapacityConstraint<T> >::const_iterator c_it;
178 rs->AddCapacity(c_it->capacity());
192 std::map<typename T::Ptr, std::vector<ExchangeNode::Ptr> > excl_bid_grps;
194 typename std::set<Bid<T>*>::const_iterator b_it;
195 for (b_it = bp->
bids().begin();
196 b_it != bp->
bids().end();
202 b->request()->commodity(),
203 b->bidder()->manager()->id()));
204 bs->AddExchangeNode(n);
205 AddBid(translation_ctx, *b_it, n);
206 if (b->exclusive()) {
207 excl_bid_grps[b->offer()].push_back(n);
211 typename std::map<typename T::Ptr, std::vector<ExchangeNode::Ptr> >::iterator
213 for (m_it = excl_bid_grps.begin();
214 m_it != excl_bid_grps.end();
216 bs->AddExclGroup(m_it->second);
220 <<
" bid capacities";
222 typename std::set< CapacityConstraint<T> >::const_iterator c_it;
226 bs->AddCapacity(c_it->capacity());
242 Bid<T>* bid,
double pref) {
246 Arc arc(unode, vnode);
249 typename T::Ptr offer = bid->
offer();
265 const Match& match) {
272 t.
amt = match.second;
280 typename T::Ptr offer,
285 typename std::set< CapacityConstraint<T> >::const_iterator it;
286 for (it = constr.begin(); it != constr.end(); ++it) {
288 << it->convert(offer, &a, &ctx) / offer->quantity();
289 n->unit_capacities[a].push_back(it->convert(offer, &a, &ctx) /
const std::string prototype() const
Returns the agent's prototype.
virtual const int id() const
The agent instance's unique ID within a simulation.
An arc represents a possible connection between two nodes in the bipartite resource exchange graph.
boost::shared_ptr< ExchangeNode > unode() const
const std::set< CapacityConstraint< T > > & constraints() const
const std::set< Bid< T > * > & bids() const
boost::shared_ptr< BidPortfolio< T > > Ptr
A Bid encapsulates all the information required to communicate a bid response to a request for a reso...
Request< T > * request() const
BidPortfolio< T >::Ptr portfolio()
boost::shared_ptr< T > offer() const
A CapacityConstraint provides an ability to determine an agent's constraints on resource allocation g...
An ExchangeGraph is a resource-neutral representation of a ResourceExchange.
boost::shared_ptr< ExchangeGraph > Ptr
A ExchangeNodeGroup is a collection of ExchangeNodes, and is the ExchangeGraph representation of a Bi...
boost::shared_ptr< ExchangeNodeGroup > Ptr
An ExchangeTranslator facilitates translation from a resource specific exchange to a resource-neutral...
ExchangeTranslationContext< T > & translation_ctx()
ExchangeTranslator(ExchangeContext< T > *ex_ctx)
default constructor
const ExchangeTranslationContext< T > & translation_ctx() const
void BackTranslateSolution(const std::vector< Match > &matches, std::vector< Trade< T > > &ret)
Provide a vector of Trades given a vector of Matches.
void AddArc(Request< T > *req, Bid< T > *bid, ExchangeGraph::Ptr graph)
adds a bid-request arc to a graph, if the preference for the arc is non-negative
ExchangeGraph::Ptr Translate()
translate the ExchangeContext into an ExchangeGraph
A RequestGroup is a specific ExchangeNodeGroup with a notion of an total requested quantity.
boost::shared_ptr< RequestGroup > Ptr
const std::set< CapacityConstraint< T > > & constraints() const
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()
boost::shared_ptr< RequestPortfolio< T > > Ptr
A Request encapsulates all the information required to communicate the needs of an agent in the Dynam...
std::string commodity() const
boost::shared_ptr< T > target() const
RequestPortfolio< T >::Ptr portfolio() const
Trader * requester() const
A simple API for agents that wish to exchange resources in the simulation.
virtual Agent * manager()
For values that are too big, too small, etc.
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
ExchangeNodeGroup::Ptr TranslateBidPortfolio(ExchangeTranslationContext< T > &translation_ctx, const typename BidPortfolio< T >::Ptr bp)
translates a bid portfolio by adding bid nodes and accounting for capacities.
void AddRequest(ExchangeTranslationContext< T > &translation_ctx, Request< T > *r, ExchangeNode::Ptr n)
Adds a request-node mapping.
std::pair< Arc, double > Match
@ LEV_DEBUG5
debugging information - most verbose
@ LEV_DEBUG4
debugging information
@ LEV_DEBUG1
debugging information - least verbose
@ LEV_DEBUG2
debugging information
void AddBid(ExchangeTranslationContext< T > &translation_ctx, Bid< T > *b, ExchangeNode::Ptr n)
Adds a bid-node mapping.
RequestGroup::Ptr TranslateRequestPortfolio(ExchangeTranslationContext< T > &translation_ctx, const typename RequestPortfolio< T >::Ptr rp)
translates a request portfolio by adding request nodes and accounting for capacities.
Arc TranslateArc(const ExchangeTranslationContext< T > &translation_ctx, Bid< T > *bid)
translates an arc given a bid and subsequent data, and also updates the unit capacities for the assoc...
Trade< T > BackTranslateMatch(const ExchangeTranslationContext< T > &translation_ctx, const Match &match)
simple translation from a Match to a Trade, given internal state
void TranslateCapacities(typename T::Ptr offer, const typename std::set< CapacityConstraint< T > > &constr, ExchangeNode::Ptr n, const Arc &a, const ExchangeTranslationContext< T > &ctx)
updates a node's unit capacities given, a target resource and constraints
The ExchangeContext is designed to provide an ease-of-use interface for querying and reaggregating in...
ExchangeNodes are used in ExchangeGraphs to house information about a given translated Bid or Request...
boost::shared_ptr< ExchangeNode > Ptr
An ExchangeTranslationContext is a simple holder class for any information needed to translate a Reso...
std::map< Request< T > *, ExchangeNode::Ptr > request_to_node
std::map< ExchangeNode::Ptr, Bid< T > * > node_to_bid
std::map< ExchangeNode::Ptr, Request< T > * > node_to_request
std::map< Bid< T > *, ExchangeNode::Ptr > bid_to_node
A Trade is a simple container that associates a request for a resource with a bid for that resource.