All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
auction_traits.hpp
Go to the documentation of this file.
1 
8 #ifndef PAAL_AUCTION_TRAITS_HPP
9 #define PAAL_AUCTION_TRAITS_HPP
10 
13 #include "paal/utils/functors.hpp"
15 
16 #include <boost/optional/optional.hpp>
17 
18 #include <iterator>
19 #include <unordered_set>
20 #include <utility>
21 
22 namespace paal {
23 namespace auctions {
24 
30 template <class Auction>
32  using bidders_universe_t =
33  decltype(std::declval<Auction>().template get<bidders>());
34  using bidder_iterator_t =
35  typename boost::range_iterator<bidders_universe_t>::type;
36  using bidder_t = range_to_ref_t<bidders_universe_t>;
37  using bidder_val_t = range_to_elem_t<bidders_universe_t>;
38  using items_universe_t =
39  decltype(std::declval<Auction>().template get<items>());
40  using item_t = range_to_ref_t<items_universe_t>;
41  using item_val_t = range_to_elem_t<items_universe_t>;
42  using copies_num_t = puretype(
43  std::declval<Auction>().template call<get_copies_num>(
44  std::declval<item_t>()
45  )
46  );
47 };
48 
54 template <class ValueQueryAuction>
55 class value_query_auction_traits: public auction_traits<ValueQueryAuction> {
57 
58  public:
59  using value_t = puretype(std::declval<const ValueQueryAuction&>().template call<value_query>(
60  std::declval<typename base::bidder_t>(),
61  std::unordered_set<typename base::item_val_t>() // any container of items with count method
62  ));
63 };
64 
70 template <class DemandQueryAuction>
71 struct demand_query_auction_traits : public auction_traits<DemandQueryAuction> {
72 
73  using result_t = puretype(
74  std::declval<DemandQueryAuction>().template call<demand_query>(
75  std::declval<typename auction_traits<DemandQueryAuction>::bidder_t>(),
76  // this is a little tricky, in order to obtain the value type, we pass prices and threshold
77  // as double types, because value type needs to be able to operate with doubles anyway
78  utils::make_dynamic_return_constant_functor(double(1.0)) // any functor with double operator()
79  )
80  );
81  using items_t = typename result_t::first_type;
82  using value_t = typename result_t::second_type;
83 };
84 
90 template <class GammaOracleAuction>
91 class gamma_oracle_auction_traits: public auction_traits<GammaOracleAuction> {
92  using temp_result_t = puretype(
93  *std::declval<GammaOracleAuction>(). template call<gamma_oracle>(
94  std::declval<typename auction_traits<GammaOracleAuction>::bidder_t>(),
95  // this is a little tricky, in order to obtain the value type, we pass prices
96  // as double types, because value type needs to be able to operate with doubles anyway
97  utils::make_dynamic_return_constant_functor(double(1.0)), // any functor with double operator()
98  double(1.0) // any double
99  )
100  );
101 
102  public:
103  using items_t = typename temp_result_t::first_type;
104  using value_t = typename temp_result_t::second_type::den_type;
106  using result_t = boost::optional<std::pair<items_t, frac_t>>;
107 };
108 
109 }
110 }
111 #endif // PAAL_AUCTION_TRAITS_HPP
typename boost::range_value< Range >::type range_to_elem_t
for given range returns type of its element
auto make_dynamic_return_constant_functor(T t)
make function for dynamic_return_constant_functor
Definition: functors.hpp:121
Types associated with value query auction.
#define puretype(t)
for given expression returns its type with removed const and reference
This file contains set of simple useful functors or functor adapters.
Types associated with all auctions.
Types associated with gamma oracle auction.
Implementation of fractions, which are used only for comparison purposes, and thus they can be used w...
Types associated with demand query auction.
typename boost::range_reference< Range >::type range_to_ref_t
for given range returns type of its reference
simple class to represent fraction
Definition: fraction.hpp:31