19 #include <boost/optional/optional.hpp>
20 #include <boost/range/algorithm/copy.hpp>
29 namespace pa = paal::auctions;
30 namespace pds = paal::data_structures;
33 using Item = std::string;
34 using Items = std::vector<Item>;
38 const std::vector<Bidder> bidders {
"Pooh Bear",
"Rabbit"};
40 const Items items {
"honey",
"baby carrot",
"carrot",
"jam"};
42 const int gamma_val = 2;
45 template <
class GetPrice,
class Threshold>
46 boost::optional<std::pair<Items, Frac>>
47 operator()(
Bidder bidder, GetPrice get_price, Threshold z)
const {
49 if (bidder ==
"Pooh Bear") {
51 if (val <= z)
return boost::none;
52 return std::make_pair(Items{
"honey"},
Frac(get_price(
"honey"), val - z));
55 assert(bidder ==
"Rabbit");
57 const Value baby_val = 2, val = 3;
58 auto const baby_price = get_price(
"baby carrot");
59 auto const price = get_price(
"carrot");
60 auto const baby_frac =
Frac(baby_price, baby_val - z),
61 frac =
Frac(price, val - z),
62 both_frac =
Frac(baby_price + price, baby_val + val - z);
64 auto check = [=](
Frac candidate,
Frac other1,
Frac other2) {
65 if (candidate.
den <= 0)
return false;
66 auto check_single = [=](
Frac candidate,
Frac other) {
67 return other.den <= 0 || candidate <= gamma_val * other;
69 return check_single(candidate, other1) && check_single(candidate, other2);
72 if (check(baby_frac, frac, both_frac))
73 return std::make_pair(Items{
"baby carrot"}, baby_frac);
74 if (check(frac, baby_frac, both_frac))
75 return std::make_pair(Items{
"carrot"}, frac);
76 if (check(both_frac, baby_frac, frac))
77 return std::make_pair(Items{
"baby carrot",
"carrot"}, both_frac);
93 auto get_price_func = [](Item item) {
return item ==
"honey" ? 5 : 2; };
95 std::cout <<
"pooh bear buys: ";
97 auction.call<pa::gamma_oracle>(
"Pooh Bear", get_price_func, 10);
99 std::cout <<
"nothing";
101 boost::copy(got_pooh_bear->first, std::ostream_iterator<Item>(std::cout,
", "));
102 std::cout << std::endl;
104 std::cout <<
"rabbit oracle buys: ";
105 auto got_rabbit = auction.call<pa::gamma_oracle>(
"Rabbit", get_price_func, 1);
107 std::cout <<
"nothing";
109 boost::copy(got_rabbit->first, std::ostream_iterator<Item>(std::cout,
", "));
110 std::cout << std::endl;
int main()
[Gamma Oracle Auction Components Example]
std::string Bidder
[Demand Query Auction Components Example]
Implementation of fractions, which are used only for comparison purposes, and thus they can be used w...
auto make_gamma_oracle_auction_components(Args &&...args) -> decltype(gamma_oracle_components::make_components(std::forward< Args >(args)...))
make function for gamma oracle components
simple class to represent fraction