1#ifndef CYCLUS_SRC_EXCHANGE_TRANSLATOR_H_
2#define CYCLUS_SRC_EXCHANGE_TRANSLATOR_H_
44 const std::vector<typename RequestPortfolio<T>::Ptr>& requests =
46 typename std::vector<typename RequestPortfolio<T>::Ptr>::const_iterator
48 for (rp_it = requests.begin(); rp_it != requests.end(); ++rp_it) {
50 (*rp_it)->AddConstraint(c);
53 graph->AddRequestGroup(rs);
57 const std::vector<typename BidPortfolio<T>::Ptr>& bidports = ex_ctx_->bids;
58 typename std::vector<typename BidPortfolio<T>::Ptr>::const_iterator bp_it;
59 for (bp_it = bidports.begin(); bp_it != bidports.end(); ++bp_it) {
61 graph->AddSupplyGroup(ns);
64 const std::set<Bid<T>*>& bids = (*bp_it)->bids();
65 typename std::set<Bid<T>*>::const_iterator b_it;
66 for (b_it = bids.begin(); b_it != bids.end(); ++b_it) {
79 double pref = ex_ctx_->trader_prefs.at(req->
requester())[req][bid];
83 CLOG(
LEV_DEBUG1) <<
"Removing arc because of negative preference.";
85 }
else if (pref == 0) {
87 ss <<
"0-valued preferences have been deprecated. "
88 <<
"Please make preference value positive."
89 <<
"This message will go away in before the next release (1.5).";
94 a.
unode()->prefs[a] = pref;
95 int n_prefs = a.
unode()->prefs.size();
108 std::vector<Match>::const_iterator m_it;
110 <<
" trade matches.";
111 for (m_it = matches.begin(); m_it != matches.end(); ++m_it) {
153 typename std::vector<Request<T>*>::const_iterator r_it;
160 rs->AddExchangeNode(n);
166 <<
" request capacities";
167 typename std::set<CapacityConstraint<T>>::const_iterator c_it;
170 rs->AddCapacity(c_it->capacity());
184 std::map<typename T::Ptr, std::vector<ExchangeNode::Ptr>> excl_bid_grps;
186 typename std::set<Bid<T>*>::const_iterator b_it;
187 for (b_it = bp->
bids().begin(); b_it != bp->
bids().end(); ++b_it) {
191 b->request()->commodity(),
192 b->bidder()->manager()->id()));
193 bs->AddExchangeNode(n);
194 AddBid(translation_ctx, *b_it, n);
195 if (b->exclusive()) {
196 excl_bid_grps[b->offer()].push_back(n);
200 typename std::map<typename T::Ptr, std::vector<ExchangeNode::Ptr>>::iterator
202 for (m_it = excl_bid_grps.begin(); m_it != excl_bid_grps.end(); ++m_it) {
203 bs->AddExclGroup(m_it->second);
207 <<
" bid capacities";
209 typename std::set<CapacityConstraint<T>>::const_iterator c_it;
212 bs->AddCapacity(c_it->capacity());
228 Bid<T>* bid,
double pref) {
232 Arc arc(unode, vnode);
235 typename T::Ptr offer = bid->
offer();
257 t.
amt = match.second;
269 typename std::set<CapacityConstraint<T>>::const_iterator it;
270 for (it = constr.begin(); it != constr.end(); ++it) {
272 <<
"Additing unit capacity: "
273 << it->convert(offer, &a, &ctx) / offer->quantity();
274 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
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.