Skip to content

Commit

Permalink
Merge pull request #1317 from Baaaaam/abi_fix
Browse files Browse the repository at this point in the history
I don't understand why... Abi fix
  • Loading branch information
scopatz committed Nov 22, 2016
2 parents 895fe00 + 89b18ee commit 6947908
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 121 deletions.
96 changes: 60 additions & 36 deletions src/bid.h
Expand Up @@ -10,103 +10,127 @@
namespace cyclus {

class Trader;
template<class T> class BidPortfolio;
template <class T> class BidPortfolio;

/// @class Bid
///
/// @brief A Bid encapsulates all the information required to communicate a bid
/// response to a request for a resource, including the resource bid and the
/// bidder.
template <class T>
class Bid {
template <class T> class Bid {
public:
/// @brief a factory method for a bid
/// @param request the request being responded to by this bid
/// @param offer the resource being offered in response to the request
/// @param bidder the bidder
/// @param portfolio the porftolio of which this bid is a part
/// @param exclusive flag for whether the bid is exclusive
/// @param preference specifies the preference of a bid in a request
/// to bid arc. If NaN the request preference is used.
/// @param preference specifies the preference of a bid in a request
/// to bid arc. If NaN the request preference is used.
/// WARNING: This should only be set by the bidder using the
/// requests callback cost function. Bidders should not
/// arbitrarily set this preference.
/// requests callback cost function. Bidders should not
/// arbitrarily set this preference.
inline static Bid<T>* Create(Request<T>* request,
boost::shared_ptr<T> offer,
boost::shared_ptr<T>
offer,
Trader* bidder,
typename BidPortfolio<T>::Ptr portfolio,
bool exclusive = false,
double preference = std::numeric_limits<double>::quiet_NaN()) {
bool exclusive,
double preference) {
return new Bid<T>(request, offer, bidder, portfolio, exclusive, preference);
}

/// @brief a factory method for a bid
/// @param request the request being responded to by this bid
/// @param offer the resource being offered in response to the request
/// @param bidder the bidder
/// @param portfolio the porftolio of which this bid is a part
/// @param exclusive flag for whether the bid is exclusive
inline static Bid<T>* Create(Request<T>* request,
boost::shared_ptr<T>
offer,
Trader* bidder,
typename BidPortfolio<T>::Ptr portfolio,
bool exclusive = false) {
return Create(request, offer, bidder, portfolio, exclusive,
std::numeric_limits<double>::quiet_NaN());
}
/// @brief a factory method for a bid for a bid without a portfolio
/// @warning this factory should generally only be used for testing
inline static Bid<T>* Create(Request<T>* request, boost::shared_ptr<T> offer,
Trader* bidder, bool exclusive = false,
double preference = std::numeric_limits<double>::quiet_NaN()) {
Trader* bidder, bool exclusive,
double preference) {
return new Bid<T>(request, offer, bidder, exclusive, preference);
}
/// @brief a factory method for a bid for a bid without a portfolio
/// @warning this factory should generally only be used for testing
inline static Bid<T>* Create(Request<T>* request, boost::shared_ptr<T> offer,
Trader* bidder, bool exclusive = false) {
return Create(request, offer, bidder, exclusive,
std::numeric_limits<double>::quiet_NaN());
}

/// @return the request being responded to
inline Request<T>* request() const {
return request_;
}
inline Request<T>* request() const { return request_; }

/// @return the bid object for the request
inline boost::shared_ptr<T> offer() const {
return offer_;
}
inline boost::shared_ptr<T> offer() const { return offer_; }

/// @return the agent responding the request
inline Trader* bidder() const {
return bidder_;
}
inline Trader* bidder() const { return bidder_; }

/// @return the portfolio of which this bid is a part
inline typename BidPortfolio<T>::Ptr portfolio() {
return portfolio_.lock();
}
inline typename BidPortfolio<T>::Ptr portfolio() { return portfolio_.lock(); }

/// @return whether or not this an exclusive bid
inline bool exclusive() const {
return exclusive_;
}
inline bool exclusive() const { return exclusive_; }

/// @return the preference of this bid
inline double preference() const {
return preference_;
}
inline double preference() const { return preference_; }

private:
/// @brief constructors are private to require use of factory methods
Bid(Request<T>* request, boost::shared_ptr<T> offer, Trader* bidder,
bool exclusive = false,
double preference = std::numeric_limits<double>::quiet_NaN())
bool exclusive, double preference)
: request_(request),
offer_(offer),
bidder_(bidder),
exclusive_(exclusive),
preference_(preference) {}
/// @brief constructors are private to require use of factory methods
Bid(Request<T>* request, boost::shared_ptr<T> offer, Trader* bidder,
bool exclusive = false)
: request_(request),
offer_(offer),
bidder_(bidder),
exclusive_(exclusive),
preference_(std::numeric_limits<double>::quiet_NaN()) {}

Bid(Request<T>* request, boost::shared_ptr<T> offer, Trader* bidder,
typename BidPortfolio<T>::Ptr portfolio, bool exclusive = false,
double preference = std::numeric_limits<double>::quiet_NaN())
typename BidPortfolio<T>::Ptr portfolio, bool exclusive, double preference)
: request_(request),
offer_(offer),
bidder_(bidder),
portfolio_(portfolio),
exclusive_(exclusive),
preference_(preference) {}

Bid(Request<T>* request, boost::shared_ptr<T> offer, Trader* bidder,
typename BidPortfolio<T>::Ptr portfolio, bool exclusive = false)
: request_(request),
offer_(offer),
bidder_(bidder),
portfolio_(portfolio),
exclusive_(exclusive),
preference_(std::numeric_limits<double>::quiet_NaN()) {}

Request<T>* request_;
boost::shared_ptr<T> offer_;
Trader* bidder_;
boost::weak_ptr<BidPortfolio<T> > portfolio_;
boost::weak_ptr<BidPortfolio<T>> portfolio_;
bool exclusive_;
double preference_;
};

} // namespace cyclus

#endif // CYCLUS_SRC_BID_H_
58 changes: 31 additions & 27 deletions src/bid_portfolio.h
Expand Up @@ -2,8 +2,8 @@
#define CYCLUS_SRC_BID_PORTFOLIO_H_

#include <set>
#include <string>
#include <sstream>
#include <string>

#include <boost/shared_ptr.hpp>

Expand All @@ -15,11 +15,9 @@ namespace cyclus {

class Trader;


std::string GetTraderPrototype(Trader* bidder);
std::string GetTraderSpec(Trader* bidder);


/// @class BidPortfolio
///
/// @brief A BidPortfolio is a collection of bids as responses to requests for
Expand All @@ -31,9 +29,9 @@ std::string GetTraderSpec(Trader* bidder);
/// portfolio. Responses are grouped by the bidder. Constraints are assumed to
/// act over the entire set of possible bids.
template <class T>
class BidPortfolio : public boost::enable_shared_from_this< BidPortfolio<T> > {
class BidPortfolio : public boost::enable_shared_from_this<BidPortfolio<T>> {
public:
typedef boost::shared_ptr< BidPortfolio<T> > Ptr;
typedef boost::shared_ptr<BidPortfolio<T>> Ptr;

/// @brief default constructor
BidPortfolio() : bidder_(NULL) {}
Expand All @@ -52,26 +50,38 @@ class BidPortfolio : public boost::enable_shared_from_this< BidPortfolio<T> > {
/// @param bidder the bidder
/// @param exclusive indicates whether the bid is exclusive
/// @param preference sets the preference of the bid on a request
/// bid arc.
/// bid arc.
/// @throws KeyError if a bid is added from a different bidder than the
/// original
Bid<T>* AddBid(Request<T>* request, boost::shared_ptr<T> offer,
Trader* bidder, bool exclusive = false,
double preference = std::numeric_limits<double>::quiet_NaN()) {
Bid<T>* b =
Bid<T>::Create(request, offer, bidder, this->shared_from_this(),
exclusive, preference);
Trader* bidder, bool exclusive, double preference) {
Bid<T>* b = Bid<T>::Create(request, offer, bidder, this->shared_from_this(),
exclusive, preference);
VerifyResponder_(b);
if(offer->quantity() > 0 )
if (offer->quantity() > 0)
bids_.insert(b);
else{
else {
std::stringstream ss;
ss << GetTraderPrototype(bidder) << " from " << GetTraderSpec(bidder) << " is offering a bid quantity <= 0, Q = " << offer->quantity() ;
ss << GetTraderPrototype(bidder) << " from " << GetTraderSpec(bidder)
<< " is offering a bid quantity <= 0, Q = " << offer->quantity();
throw ValueError(ss.str());
}
return b;
}

/// @brief add a bid to the portfolio
/// @param request the request being responded to by this bid
/// @param offer the resource being offered in response to the request
/// @param bidder the bidder
/// @param exclusive indicates whether the bid is exclusive
/// @throws KeyError if a bid is added from a different bidder than the
/// original
Bid<T>* AddBid(Request<T>* request, boost::shared_ptr<T> offer,
Trader* bidder, bool exclusive = false) {
return AddBid(request, offer, bidder, exclusive,
std::numeric_limits<double>::quiet_NaN());
}

/// @brief add a capacity constraint associated with the portfolio
/// @param c the constraint to add
inline void AddConstraint(const CapacityConstraint<T>& c) {
Expand All @@ -80,22 +90,16 @@ class BidPortfolio : public boost::enable_shared_from_this< BidPortfolio<T> > {

/// @return the agent associated with the portfolio. If no bids have
/// been added, the bidder is NULL.
inline Trader* bidder() const {
return bidder_;
}
inline Trader* bidder() const { return bidder_; }

/// @return *deprecated* the commodity associated with the portfolio.
inline std::string commodity() const {
return "";
}
inline std::string commodity() const { return ""; }

/// @return const access to the bids
inline const std::set<Bid<T>*>& bids() const {
return bids_;
}
inline const std::set<Bid<T>*>& bids() const { return bids_; }

/// @return the set of constraints over the bids
inline const std::set< CapacityConstraint<T> >& constraints() const {
inline const std::set<CapacityConstraint<T>>& constraints() const {
return constraints_;
}

Expand Down Expand Up @@ -127,14 +131,14 @@ class BidPortfolio : public boost::enable_shared_from_this< BidPortfolio<T> > {
}

/// @brief *deprecated*
void VerifyCommodity_(const Bid<T>* r) { }
void VerifyCommodity_(const Bid<T>* r) {}

// bid_ is a set because there is a one-to-one correspondence between a
// bid and a request, i.e., bids are unique
std::set<Bid<T>*> bids_;

// constraints_ is a set because constraints are assumed to be unique
std::set< CapacityConstraint<T> > constraints_;
std::set<CapacityConstraint<T>> constraints_;

Trader* bidder_;
};
Expand Down

0 comments on commit 6947908

Please sign in to comment.