18 #include <boost/optional/optional.hpp>
19 #include <boost/range/algorithm/copy.hpp>
27 namespace pa = paal::auctions;
28 namespace pds = paal::data_structures;
31 using Item = std::string;
32 using Items = std::vector<Item>;
35 const std::vector<Bidder> bidders {
"Pooh Bear",
"Rabbit"};
37 const Items items {
"honey",
"baby carrot",
"carrot",
"jam"};
40 template <
class GetPrice>
41 std::pair<Items, Value>
42 operator()(
Bidder bidder, GetPrice get_price)
const
44 if (bidder ==
"Pooh Bear") {
45 const Value util = 10 - get_price(
"honey");
46 if (util <= 0)
return std::make_pair(Items{}, 0);
47 return std::make_pair(Items{
"honey"}, util);
50 assert(bidder ==
"Rabbit");
52 const Value baby_val = 2, val = 3;
53 auto const baby_price = get_price(
"baby carrot"), price = get_price(
"carrot");
55 const Value baby_util = baby_val - baby_price,
56 util = val - price, both_util = baby_val + val - baby_price - price;
58 if (baby_util <= 0 && util <= 0 && both_util <= 0)
return std::make_pair(Items{}, 0);
60 if (baby_util >= util && baby_util >= both_util)
61 return std::make_pair(Items{
"baby carrot"}, baby_util);
63 if (util >= both_util)
64 return std::make_pair(Items{
"carrot"}, util);
66 return std::make_pair(Items{
"baby carrot",
"carrot"}, both_util);
79 auto get_price = [](Item item) {
return item ==
"honey" ? 5 : 2; };
81 std::cout <<
"pooh bear buys: ";
82 auto got_pooh_bear = auction.call<pa::demand_query>(
"Pooh Bear", get_price);
83 boost::copy(got_pooh_bear.first, std::ostream_iterator<Item>(std::cout,
", "));
84 std::cout << std::endl;
86 std::cout <<
"rabbit oracle buys: ";
87 auto got_rabbit = auction.call<pa::demand_query>(
"Rabbit", get_price);
88 boost::copy(got_rabbit.first, std::ostream_iterator<Item>(std::cout,
", "));
89 std::cout << std::endl;
int main()
[Demand Query Auction Components Example]
std::string Bidder
[Demand Query Auction Components Example]
auto make_demand_query_auction_components(Args &&...args)
make function for demand query components