All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
fractional_winner_determination_in_MUCA_example.cpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Robert Rosolek
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 //=======================================================================
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 int main()
35 {
36  using Bidder = std::string;
37  using Item = std::string;
38  using Items = std::unordered_set<Item>;
39  using Value = long double;
40  using Bid = std::pair<Items, Value>;
41  using Bids = std::vector<Bid>;
42  using Assignment = std::tuple<Bidder, Items, double>;
43 
44  // create auction
45  const std::unordered_map<Bidder, Bids> bids {
46  {"John", {
47  {{"lemon", "orange"}, 1},
48  {{"apple", "ball"}, 1},
49  }},
50  {"Bob", {
51  {{"lemon", "apple"}, 1},
52  {{"orange", "ball"}, 1},
53  }},
54  };
55  const std::vector<Bidder> bidders {"John", "Bob"};
56  const std::vector<Item> items {"apple", "ball", "orange", "lemon"};
57  auto get_bids = [&](const Bidder& bidder) -> const Bids& { return bids.at(bidder); };
58  auto get_value = [](const Bid& bid) { return bid.second; };
59  auto get_items = [](const Bid& bid) -> const Items& { return bid.first; };
61  bidders, items, get_bids, get_value, get_items
62  );
63 
64  // determine winners
65  Value social_welfare = 0;
67  std::move(bidders), std::move(items), get_bids, get_value, get_items
68  );
70  auction,
71  boost::make_function_output_iterator([&](Assignment a)
72  {
73  auto bidder = std::get<0>(a);
74  auto& cur_items = std::get<1>(a);
75  auto fraction = std::get<2>(a);
76  social_welfare += fraction * valuation.call<paal::auctions::value_query>(bidder, cur_items);
77  std::cout << bidder << " got a fraction " << fraction << " of bundle: ";
78  boost::copy(cur_items, std::ostream_iterator<Item>(std::cout, ", "));
79  std::cout << std::endl;
80  })
81  );
82  std::cout << "social welfare: " << social_welfare << std::endl;
83 
84  return 0;
85 }
int main()
[Fractional Winner Determination in MUCA Example]
void fractional_determine_winners_in_demand_query_auction(DemandQueryAuction &&auction, OutputIterator result, ItemToLpIdMap item_to_id, double epsilon, SeparationOracle separation_oracle=SeparationOracle{})
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
std::string Bidder
[Demand Query Auction Components Example]
Interfaces for creating auctions from xor bids valuations.