All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
single_minded_auctions.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_SINGLE_MINDED_AUCTIONS_HPP
16 #define PAAL_SINGLE_MINDED_AUCTIONS_HPP
17 
19 #include "paal/utils/functors.hpp"
21 
22 #include <boost/range/iterator_range.hpp>
23 
24 #include <utility>
25 
26 namespace paal {
27 namespace auctions {
28 
29  namespace concepts {
30  template <
31  class Bidders,
32  class Items,
33  class GetValue,
34  class GetItems,
35  class GetCopiesNum
36  >
37  class single_minded {
38  Bidders bidders;
39  Items items;
40  GetValue get_value;
41  GetItems get_items;
42  GetCopiesNum get_copies_num;
43 
44  single_minded() {}
45 
46  public:
47  BOOST_CONCEPT_USAGE(single_minded)
48  {
49  using value_t = puretype(get_value(*std::begin(bidders)));
50  static_assert(std::is_arithmetic<value_t>::value,
51  "get_value return type is not arithmetic!");
52  auto&& bid_items = get_items(*std::begin(bidders));
53  using bundle_t = puretype(bid_items);
54  static_assert(std::is_move_constructible<bundle_t>::value,
55  "bundle_t is not move constructible!");
56  static_assert(std::is_default_constructible<bundle_t>::value,
57  "bundle_t is not default constructible!");
58  BOOST_CONCEPT_ASSERT((boost::ForwardRangeConcept<
59  decltype(bid_items)>));
60  }
61  };
62  }
63 
64  namespace detail {
65 
66  struct get_bids {
67  template <class Bidder>
68  auto operator()(Bidder&& b)
69  const -> decltype(utils::make_singleton_range(std::forward<Bidder>(b)))
70  {
71  return utils::make_singleton_range(std::forward<Bidder>(b));
72  }
73  };
74 
75  }
76 
91  template<
92  class Bidders,
93  class Items,
94  class GetValue,
95  class GetItems,
96  class GetCopiesNum = utils::return_one_functor
97  >
99  Bidders&& bidders,
100  Items&& items,
101  GetValue get_value,
102  GetItems get_items,
103  GetCopiesNum get_copies_num = GetCopiesNum{}
104  )
106  std::forward<Bidders>(bidders),
107  std::forward<Items>(items),
108  detail::get_bids(),
109  get_value,
110  get_items,
111  get_copies_num
112  )) {
113  BOOST_CONCEPT_ASSERT((concepts::single_minded<Bidders, Items, GetValue, GetItems, GetCopiesNum>));
115  std::forward<Bidders>(bidders),
116  std::forward<Items>(items),
117  detail::get_bids(),
118  get_value,
119  get_items,
120  get_copies_num
121  );
122  }
123 
124  // TODO all constructions in this file are essentially the same, maybe it's possible
125  // to refactor it using some C++ magic?
126 
141  template<
142  class Bidders,
143  class Items,
144  class GetValue,
145  class GetItems,
146  class GetCopiesNum = utils::return_one_functor
147  >
149  Bidders&& bidders,
150  Items&& items,
151  GetValue get_value,
152  GetItems get_items,
153  GetCopiesNum get_copies_num = GetCopiesNum{}
154  )
156  std::forward<Bidders>(bidders),
157  std::forward<Items>(items),
158  detail::get_bids(),
159  get_value,
160  get_items,
161  get_copies_num
162  )) {
163  BOOST_CONCEPT_ASSERT((concepts::single_minded<Bidders, Items, GetValue, GetItems, GetCopiesNum>));
165  std::forward<Bidders>(bidders),
166  std::forward<Items>(items),
167  detail::get_bids(),
168  get_value,
169  get_items,
170  get_copies_num
171  );
172  }
173 
188  template<
189  class Bidders,
190  class Items,
191  class GetValue,
192  class GetItems,
193  class GetCopiesNum = utils::return_one_functor
194  >
196  Bidders&& bidders,
197  Items&& items,
198  GetValue get_value,
199  GetItems get_items,
200  GetCopiesNum get_copies_num = GetCopiesNum{}
201  )
203  std::forward<Bidders>(bidders),
204  std::forward<Items>(items),
205  detail::get_bids(),
206  get_value,
207  get_items,
208  get_copies_num
209  )) {
210  BOOST_CONCEPT_ASSERT((concepts::single_minded<Bidders, Items, GetValue, GetItems, GetCopiesNum>));
212  std::forward<Bidders>(bidders),
213  std::forward<Items>(items),
214  detail::get_bids(),
215  get_value,
216  get_items,
217  get_copies_num
218  );
219  }
220 
232  template<class Bidders, class GetItems, class OutputIterator>
233  void extract_items_from_single_minded(Bidders&& bidders, GetItems get_items, OutputIterator output)
234  {
236  std::forward<Bidders>(bidders),
238  get_items,
239  output
240  );
241  }
242 
243 }
244 }
245 #endif // PAAL_SINGLE_MINDED_AUCTIONS_HPP
auto make_singleton_range(Elem &&elem) -> decltype(boost::make_iterator_range(make_singleton_iterator_begin(std::forward< Elem >(elem)), make_singleton_iterator_end< Elem >()))
function to create a singleton range
auto make_single_minded_to_value_query_auction(Bidders &&bidders, Items &&items, GetValue get_value, GetItems get_items, GetCopiesNum get_copies_num=GetCopiesNum{}) -> decltype(make_xor_bids_to_value_query_auction(std::forward< Bidders >(bidders), std::forward< Items >(items), detail::get_bids(), get_value, get_items, get_copies_num))
detail
auto make_xor_bids_to_demand_query_auction(Bidders &&bidders, Items &&items, GetBids get_bids, GetValue get_value, GetItems get_items, GetCopiesNum get_copies_num=GetCopiesNum{})
detail
Definition: xor_bids.hpp:264
auto make_xor_bids_to_value_query_auction(Bidders &&bidders, Items &&items, GetBids get_bids, GetValue get_value, GetItems get_items, GetCopiesNum get_copies_num=GetCopiesNum{}) -> decltype(make_value_query_auction_components(std::forward< Bidders >(bidders), std::forward< Items >(items), detail::xor_bids_value_query< GetBids, GetValue, GetItems >(get_bids, get_value, get_items), get_copies_num))
detail
Definition: xor_bids.hpp:170
void extract_items_from_single_minded(Bidders &&bidders, GetItems get_items, OutputIterator output)
Extract all items appearing in all bidders&#39; bids. This function doesn&#39;t eliminate duplicates...
std::string Bidder
[Demand Query Auction Components Example]
auto make_xor_bids_to_gamma_oracle_auction(Bidders &&bidders, Items &&items, GetBids get_bids, GetValue get_value, GetItems get_items, GetCopiesNum get_copies_num=GetCopiesNum{}) -> decltype(make_gamma_oracle_auction_components(std::forward< Bidders >(bidders), std::forward< Items >(items), detail::xor_bids_gamma_oracle< GetBids, GetValue, GetItems >(get_bids, get_value, get_items), 1, get_copies_num))
detail
Definition: xor_bids.hpp:418
Interfaces for creating auctions from xor bids valuations.
#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.
void extract_items_from_xor_bids(Bidders &&bidders, GetBids get_bids, GetItems get_items, OutputIterator output)
extract all items appearing in all bids. This function doesn&#39;t eliminate duplicates, this is left out to the caller.
Definition: xor_bids.hpp:458
auto make_single_minded_to_demand_query_auction(Bidders &&bidders, Items &&items, GetValue get_value, GetItems get_items, GetCopiesNum get_copies_num=GetCopiesNum{}) -> decltype(make_xor_bids_to_demand_query_auction(std::forward< Bidders >(bidders), std::forward< Items >(items), detail::get_bids(), get_value, get_items, get_copies_num))
Create demand query auction from single minded valuations.
auto make_single_minded_to_gamma_oracle_auction(Bidders &&bidders, Items &&items, GetValue get_value, GetItems get_items, GetCopiesNum get_copies_num=GetCopiesNum{}) -> decltype(make_xor_bids_to_gamma_oracle_auction(std::forward< Bidders >(bidders), std::forward< Items >(items), detail::get_bids(), get_value, get_items, get_copies_num))
Create gamma oracle auction from single minded valuations.