All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
value_query_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 <boost/range/algorithm/copy.hpp>
19 
20 #include <cassert>
21 #include <iostream>
22 #include <iterator>
23 #include <string>
24 #include <set>
25 #include <unordered_set>
26 #include <vector>
27 
29 
30 namespace pa = paal::auctions;
31 
32 using Bidder = std::string;
33 using Item = std::string;
34 using Value = unsigned int;
35 
36 const std::vector<Bidder> bidders {"Pooh Bear", "Rabbit"};
37 
38 const std::vector<Item> items {"honey", "baby carrot", "carrot", "jam"};
39 
41  int operator()(Item item) const
42  {
43  return item == "baby carrot" ? 2 : 1;
44  }
45 };
46 
48  template <class ItemSet>
49  Value operator()(Bidder bidder, const ItemSet& item_set) const
50  {
51  if (bidder == "Pooh Bear")
52  return item_set.count("honey") > 0 ? 10 : 0;
53  assert(bidder == "Rabbit");
54  Value res = 0;
55  for (Item item: item_set)
56  if (item.find("carrot") != std::string::npos) ++res;
57  return res;
58  }
59 };
60 
62 
63 int main()
64 {
66  auto const auction = pa::make_value_query_auction_components(
67  bidders, items, value_query_func(), get_copies_num_func()
68  );
70 
72  std::cout << "bidders: ";
73  boost::copy(
74  auction.get<pa::bidders>(), std::ostream_iterator<Bidder>(std::cout, ", ")
75  );
76  std::cout << std::endl;
77 
78  std::cout << "items with copies numbers: ";
79  for (auto item: auction.get<pa::items>())
80  std::cout << item << " = " << auction.call<pa::get_copies_num>(item) << ", ";
81  std::cout << std::endl;
82 
83  std::cout << "pooh bear valuation: " <<
84  auction.call<pa::value_query>("Pooh Bear", std::set<Item>{"jam", "honey"}) <<
85  std::endl;
86 
87  std::cout << "rabbit valuation: " <<
88  auction.call<pa::value_query>(
89  "Rabbit", std::unordered_set<Item>{"carrot", "baby carrot"}) <<
90  std::endl;
92 
93  return 0;
94 }
std::string Bidder
[Demand Query Auction Components Example]
auto make_value_query_auction_components(Args &&...args) -> decltype(value_query_components::make_components(std::forward< Args >(args)...))
make function for value query components
int main()
[Value Query Auction Components Example]