All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
single_minded_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  namespace pa = paal::auctions;
34 
35  std::unordered_map<Bidder, Bid> bids {
36  {"Pooh Bear", {{"honey"}, 10}},
37  {"Rabbit", {{"baby carrot", "carrot"}, 2}},
38  };
39  std::vector<Bidder> bidders {"Pooh Bear", "Rabbit"};
40  std::vector<Item> items {"honey", "baby carrot", "carrot", "jam"};
41  auto get_value = [&](Bidder bidder) { return bids.at(bidder).second; };
42  auto get_items = [&](Bidder bidder) -> const Items& { return bids.at(bidder).first; };
43  auto get_copies_num = [](Item item) { return item == "baby carrot" ? 2 : 1; };
44 
46  bidders, items, get_value, get_items, get_copies_num
47  );
48 
49  Items bundle {"carrot", "honey", "jam"};
50 
51  std::cout << "pooh bear valuation: " <<
52  auction.call<pa::value_query>("Pooh Bear", bundle) << std::endl;
53 
54  std::cout << "rabbit valuation: " <<
55  auction.call<pa::value_query>("Rabbit", bundle) << std::endl;
56 
57  return 0;
58 }
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
Interfaces for creating auctions from single minded valuations.
std::string Bidder
[Demand Query Auction Components Example]
int main()
[Single Minded Auctions Example]