All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
xor_bids_example.cpp
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 //=======================================================================
17 
18 #include <iostream>
19 #include <string>
20 #include <unordered_map>
21 #include <unordered_set>
22 #include <utility>
23 #include <vector>
24 
26 int main()
27 {
28  using Bidder = std::string;
29  using Item = std::string;
30  using Items = std::unordered_set<Item>;
31  using Value = int;
32  using Bid = std::pair<Items, Value>;
33  using Bids = std::vector<Bid>;
34  namespace pa = paal::auctions;
35 
36  std::unordered_map<Bidder, Bids> bids {
37  {"Pooh Bear", {
38  {{"honey"}, 10},
39  }},
40  {"Rabbit", {
41  {{"baby carrot"}, 1},
42  {{"carrot"}, 2},
43  {{"baby carrot", "carrot"}, 4},
44  }},
45  };
46  std::vector<Bidder> bidders {"Pooh Bear", "Rabbit"};
47  std::vector<Item> items {"honey", "baby carrot", "carrot", "jam"};
48  auto get_bids = [&](Bidder bidder) -> const Bids& { return bids.at(bidder); };
49  auto get_value = [](const Bid& bid) { return bid.second; };
50  auto get_items = [](const Bid& bid) -> const Items& { return bid.first; };
51  auto get_copies_num = [](Item item) { return item == "baby carrot" ? 2 : 1; };
52 
54  bidders, items, get_bids, get_value, get_items, get_copies_num
55  );
56 
57  Items bundle {"carrot", "honey", "baby carrot"};
58 
59  std::cout << "pooh bear valuation: " <<
60  auction.call<pa::value_query>("Pooh Bear", bundle) << std::endl;
61 
62  std::cout << "rabbit valuation: " <<
63  auction.call<pa::value_query>("Rabbit", bundle) << std::endl;
64 
65  return 0;
66 }
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
int main()
[Xor Bids Auctions Example]
std::string Bidder
[Demand Query Auction Components Example]
Interfaces for creating auctions from xor bids valuations.