1#ifndef CYCLUS_SRC_EXCHANGE_TRANSLATOR_H_
2#define CYCLUS_SRC_EXCHANGE_TRANSLATOR_H_
18template <
class T>
class ExchangeContext;
47 const std::vector<typename RequestPortfolio<T>::Ptr>& requests =
49 typename std::vector<typename RequestPortfolio<T>::Ptr>::const_iterator
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;
64 graph->AddSupplyGroup(
ns);
67 const std::set<Bid<T>*>& bids = (*bp_it)->bids();
68 typename std::set<Bid<T>*>::const_iterator
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();
102 <<
req->requester()->manager()->prototype()
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;
158 for (
r_it =
rp->requests().begin();
159 r_it !=
rp->requests().end();
166 r->requester()->manager()->id()));
167 rs->AddExchangeNode(n);
173 <<
" request capacities";
174 typename std::set< CapacityConstraint<T> >::const_iterator
c_it;
175 for (
c_it =
rp->constraints().begin();
176 c_it !=
rp->constraints().end();
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();
202 b->request()->commodity(),
203 b->bidder()->manager()->id()));
204 bs->AddExchangeNode(n);
206 if (b->exclusive()) {
211 typename std::map<typename T::Ptr, std::vector<ExchangeNode::Ptr> >::iterator
216 bs->AddExclGroup(
m_it->second);
220 <<
" bid capacities";
222 typename std::set< CapacityConstraint<T> >::const_iterator
c_it;
223 for (
c_it =
bp->constraints().begin();
224 c_it !=
bp->constraints().end();
226 bs->AddCapacity(
c_it->capacity());
242 Bid<T>* bid,
double pref) {
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;
288 <<
it->convert(offer, &
a, &ctx) / offer->quantity();
289 n->unit_capacities[
a].push_back(
it->convert(offer, &
a, &ctx) /
An arc represents a possible connection between two nodes in the bipartite resource exchange graph.
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
boost::shared_ptr< RequestPortfolio< T > > Ptr
A Request encapsulates all the information required to communicate the needs of an agent in the Dynam...
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...
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
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.