All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
auction_components.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_AUCTION_COMPONENTS_HPP
16 #define PAAL_AUCTION_COMPONENTS_HPP
17 
21 #include "paal/utils/concepts.hpp"
22 #include "paal/utils/functors.hpp"
24 
25 #include <boost/concept_check.hpp>
26 #include <boost/optional/optional.hpp>
27 #include <boost/range/concepts.hpp>
28 
29 #include <type_traits>
30 #include <unordered_set>
31 #include <utility>
32 
33 namespace paal {
35 namespace auctions {
36 
37  // Base
38 
42  struct bidders;
46  struct items;
50  struct get_copies_num;
51 
52  // Value Query Auction
53 
57  struct value_query;
58 
59  // Demand Query Auction
60 
64  struct demand_query;
65 
66  // Gamma Oracle Auction
67 
71  struct gamma_oracle;
75  struct gamma;
76 
78 namespace concepts {
79  template <typename Auction>
80  class auction {
81  template <class Component>
82  using component_to_range_t = typename std::remove_reference<
84  typename std::decay<Auction>::type>::
85  template type<Component>::type
86  >::type;
87 
88  public:
89 
90  auction() = delete;
91 
92  using bidders_t = component_to_range_t<bidders>;
93  BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<bidders_t>));
94  BOOST_CONCEPT_ASSERT((utils::concepts::readable_range<bidders_t>));
95 
96  using items_t = component_to_range_t<items>;
97  BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<items_t>));
98  BOOST_CONCEPT_ASSERT((utils::concepts::readable_range<items_t>));
99  using item_val_t = range_to_elem_t<items_t>;
100 
101  BOOST_CONCEPT_USAGE(auction)
102  {
103  auto copies = a.template call<get_copies_num>(
104  *std::begin(a.template get<items>()));
105  using get_copies_num_result_t = puretype(copies);
106  static_assert(std::is_integral<get_copies_num_result_t>::value,
107  "return type of get_copies_num is not integral!");
108  }
109 
110  protected:
111  Auction a;
112 
113  auto get_item() -> decltype(*std::begin(a.template get<items>()))
114  {
115  return *std::begin(a.template get<items>());
116  }
117 
118  auto get_bidder() -> decltype(*std::begin(a.template get<bidders>()))
119  {
120  return *std::begin(a.template get<bidders>());
121  }
122  };
123 
124  template <typename ValueQueryAuction>
125  class value_query_auction : public auction<ValueQueryAuction> {
127 
128  public:
129 
130  BOOST_CONCEPT_USAGE(value_query_auction)
131  {
132  auto value_query_ = this->a.template get<value_query>();
133  auto val = value_query_(this->get_bidder(), std::unordered_set<
134  typename base::item_val_t>{this->get_item()});
135  using value_query_result_t = puretype(val);
136  static_assert(std::is_arithmetic<value_query_result_t>::value,
137  "return type of value_query is not arithmetic!");
138  }
139  };
140 
141  template <typename DemandQueryAuction>
142  struct demand_query_auction : auction<DemandQueryAuction> {
143 
144  BOOST_CONCEPT_USAGE(demand_query_auction)
145  {
146  auto demand_query_ = this->a.template get<demand_query>();
147  auto get_price = utils::return_one_functor();
148  auto res = demand_query_(this->get_bidder(), get_price);
149  using demand_query_result_items_t = decltype(res.first);
150  BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<
151  demand_query_result_items_t>));
152  BOOST_CONCEPT_ASSERT((utils::concepts::readable_range<
153  demand_query_result_items_t>));
154  using demand_query_result_value_t = puretype(res.second);
155  static_assert(std::is_arithmetic<demand_query_result_value_t>::value,
156  "second member of the result from demand query oracle is not arithmetic!");
157  }
158  };
159 
160  template <typename GammaOracleAuction>
161  struct gamma_oracle_auction : auction<GammaOracleAuction> {
162 
163  using gamma_t = typename data_structures::component_traits<
164  typename std::decay<GammaOracleAuction>::type>::
165  template type<gamma>::type;
166  static_assert(std::is_arithmetic<gamma_t>::value,
167  "gamma type is not arithmetic!");
168 
169  BOOST_CONCEPT_USAGE(gamma_oracle_auction)
170  {
171  auto gamma_oracle_ = this->a.template get<gamma_oracle>();
172  auto get_price = utils::return_one_functor();
173  auto threshold = 0.;
174  auto res = gamma_oracle_(this->get_bidder(), get_price, threshold);
175  if (res) {}
176  if (!res) {}
177  using gamma_oracle_result_items_t = decltype(res->first);
178  BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<
179  gamma_oracle_result_items_t>));
180  BOOST_CONCEPT_ASSERT((utils::concepts::readable_range<
181  gamma_oracle_result_items_t>));
182  using gamma_oracle_result_price_t = puretype(res->second.num);
183  static_assert(std::is_arithmetic<gamma_oracle_result_price_t>::value,
184  "numerator of frac returned from gamma oracle is not arithmetic!");
185  using gamma_oracle_result_value_t = puretype(res->second.den);
186  static_assert(std::is_arithmetic<gamma_oracle_result_value_t>::value,
187  "denominator of frac returned from gamma oracle is not arithmetic!");
188  }
189  };
190 
191 }
192 
193  // Base
194 
201  bidders,
202  items,
204  >;
205 
206  namespace detail {
208  template <typename... Names>
209  using add_to_base_auction =
210  typename data_structures::join<
213  >::type;
214  };
215 
216  // Value Query Auction
217 
222 
228  template <typename... Args>
229  using value_query_auction_components = typename value_query_components::type<Args...>;
230 
239  template <typename... Args>
240  auto make_value_query_auction_components(Args&&... args) ->
241  decltype(value_query_components::make_components(std::forward<Args>(args)...))
242  {
243  auto res = value_query_components::make_components(std::forward<Args>(args)...);
244  BOOST_CONCEPT_ASSERT((concepts::value_query_auction<decltype(res)>));
245  return res;
246  }
247 
248  // Demand Query Auction
249 
254 
260  template <typename... Args>
261  using demand_query_auction_components = typename demand_query_components::type<Args...>;
262 
271  template <typename... Args>
273  {
274  auto res = demand_query_components::make_components(std::forward<Args>(args)...);
275  BOOST_CONCEPT_ASSERT((concepts::demand_query_auction<decltype(res)>));
276  return res;
277  }
278 
279  // Gamma Oracle Auction
280 
285 
291  template <typename... Args>
292  using gamma_oracle_auction_components = typename gamma_oracle_components::type<Args...>;
293 
302  template <typename... Args>
303  auto make_gamma_oracle_auction_components(Args&&... args) ->
304  decltype(gamma_oracle_components::make_components(std::forward<Args>(args)...))
305  {
306  auto res = gamma_oracle_components::make_components(std::forward<Args>(args)...);
307  BOOST_CONCEPT_ASSERT((concepts::gamma_oracle_auction<decltype(res)>));
308  return res;
309  }
310 
311 }
312 }
313 #endif // PAAL_AUCTION_COMPONENTS_HPP
typename boost::range_value< Range >::type range_to_elem_t
for given range returns type of its element
detail::add_to_base_auction< value_query > value_query_components
detail
typename value_query_components::type< Args...> value_query_auction_components
value query auction components template alias
typename gamma_oracle_components::type< Args...> gamma_oracle_auction_components
gamma oracle auction components template alias
typename demand_query_components::type< Args...> demand_query_auction_components
demand query auction components template alias
detail::add_to_base_auction< gamma_oracle, gamma > gamma_oracle_components
definition for the components class for a gamma oracle auction.
auto make_value_query_auction_components(Args &&...args) -> decltype(value_query_components::make_components(std::forward< Args >(args)...))
make function for value query components
#define puretype(t)
for given expression returns its type with removed const and reference
This structure can be passed on Names list and represents Name and the default type value...
Definition: components.hpp:33
This file contains set of simple useful functors or functor adapters.
typename data_structures::join< base_auction_components, data_structures::components< Names...> >::type add_to_base_auction
extend base auction components with other components.
Concept class for readable range concept.
Definition: concepts.hpp:79
detail::add_to_base_auction< demand_query > demand_query_components
definition for the components class for a demand query auction
auto make_demand_query_auction_components(Args &&...args)
make function for demand query components
data_structures::components< bidders, items, data_structures::NameWithDefault< get_copies_num, utils::return_one_functor > > base_auction_components
concepts
auto make_gamma_oracle_auction_components(Args &&...args) -> decltype(gamma_oracle_components::make_components(std::forward< Args >(args)...))
make function for gamma oracle components