All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
winner_determination_in_MUCA_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 //=======================================================================
18 #include "paal/auctions/winner_determination_in_MUCA/winner_determination_in_MUCA.hpp"
19 
20 #include <boost/function_output_iterator.hpp>
21 #include <boost/range/algorithm/copy.hpp>
22 
23 #include <algorithm>
24 #include <iostream>
25 #include <iterator>
26 #include <string>
27 #include <tuple>
28 #include <unordered_map>
29 #include <unordered_set>
30 #include <utility>
31 #include <vector>
32 
34 
35 int main()
36 {
37  using Bidder = std::string;
38  using Item = std::string;
39  using Items = std::unordered_set<Item>;
40  using Value = double;
41  using Bid = std::pair<Items, Value>;
42  using Bids = std::vector<Bid>;
43 
44  // create auction
45  const std::unordered_map<Bidder, Bids> bids {
46  {"John", {
47  {{"ball", "kite"}, 2},
48  {{"umbrella"}, 3},
49  {{"orange"}, 1.75},
50  {{"ball", "kite", "umbrella"}, 5},
51  {{"ball", "kite", "orange", "umbrella"}, 6.75},
52  }},
53  {"Bob", {
54  {{"orange"}, 1.5},
55  {{"apple"}, 2.0},
56  {{"apple", "orange"}, 4},
57  }},
58  {"Steve", {
59  {{"apple"}, 1},
60  {{"umbrella"}, 4},
61  {{"apple", "umbrella"}, 5},
62  }},
63  };
64  const std::vector<Bidder> bidders {"John", "Bob", "Steve"};
65  const std::vector<Item> items {"apple", "ball", "orange", "kite", "umbrella"};
66  auto get_bids = [&](const Bidder& bidder) -> const Bids& { return bids.at(bidder); };
67  auto get_value = [](const Bid& bid) { return bid.second; };
68  auto get_items = [](const Bid& bid) -> const Items& { return bid.first; };
70  bidders, items, get_bids, get_value, get_items
71  );
72 
73  // determine winners
74  Value social_welfare = 0;
76  bidders, items, get_bids, get_value, get_items
77  );
79  auction,
80  boost::make_function_output_iterator([&](std::pair<Bidder, Items> p)
81  {
82  auto bidder = p.first;
83  auto& cur_items = p.second;
84  social_welfare += valuation.call<paal::auctions::value_query>(bidder, cur_items);
85  std::cout << bidder << " got bundle: ";
86  boost::copy(cur_items, std::ostream_iterator<Item>(std::cout, ", "));
87  std::cout << std::endl;
88  })
89  );
90  std::cout << "social welfare: " << social_welfare << std::endl;
91 
92  return 0;
93 }
94 
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
std::string Bidder
[Demand Query Auction Components Example]
void determine_winners_in_gamma_oracle_auction(GammaOracleAuction &&auction, OutputIterator result, PriceMap price, Epsilon epsilon)
detail
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.
int main()
[Winner Determination In MUCA Example]