8 #ifndef PAAL_WINNER_DETERMINATION_IN_MUCA_HPP
9 #define PAAL_WINNER_DETERMINATION_IN_MUCA_HPP
18 #include <boost/concept/requires.hpp>
19 #include <boost/optional/optional.hpp>
20 #include <boost/property_map/property_map.hpp>
21 #include <boost/range/algorithm/transform.hpp>
22 #include <boost/range/concepts.hpp>
23 #include <boost/range/iterator.hpp>
28 #include <unordered_map>
36 template <
class Value,
class ItemSet>
38 Value m_best_items_val;
43 class GammaOracleAuction,
48 using item_set =
typename Base::items_t;
50 using result = std::pair<typename Base::bidder_t, item_set>;
74 class GammaOracleAuction,
79 BOOST_CONCEPT_REQUIRES(
82 ((boost::ForwardRangeConcept<
83 typename gamma_oracle_auction_traits<GammaOracleAuction>::bidders_universe_t
87 typename gamma_oracle_auction_traits<GammaOracleAuction>::items_t
93 typename gamma_oracle_auction_traits<GammaOracleAuction>::bidder_t,
94 typename gamma_oracle_auction_traits<GammaOracleAuction>::items_t
98 ((boost::ReadWritePropertyMapConcept<
100 typename gamma_oracle_auction_traits<GammaOracleAuction>::item_t
107 GammaOracleAuction&& auction,
108 OutputIterator result,
112 using Price =
typename boost::property_traits<PriceMap>::value_type;
116 using Value =
typename Traits::value;
117 using BidderInfo =
typename Traits::bidder_info;
118 using BidderIter =
typename Traits::bidder_iterator_t;
119 using Frac =
typename Traits::frac_t;
120 using Res =
typename Traits::result_t;
123 for (
auto item = std::begin(auction.template get<items>());
124 item != std::end(auction.template get<items>());
128 auto const copies = auction.template call<get_copies_num>(*item);
129 put(price, *item, 1.0 / copies);
131 Price price_sum = items_num;
134 std::vector<BidderInfo> bidders_info_vec(
bidders_number(auction));
136 auto last_assigned_bidder_info = bidders_info_vec.end();
137 BidderIter last_assigned_bidder;
138 Value total_value = 0, last_value{};
140 auto const multiplier = std::exp(Value(b) + 1) * items_num;
141 auto const gamma_ = auction.template get<gamma>();
142 auto get_threshold = [=](
const BidderInfo& b)
144 return (1 + 2 * gamma_) * b.m_best_items_val;
147 Res
best = boost::none;
148 auto get_frac = [](Res r) {
return r->second; };
149 auto bidder_info = bidders_info_vec.begin();
150 auto bidder = std::begin(auction.template get<bidders>());
151 for (; bidder_info != bidders_info_vec.end(); ++bidder_info, ++bidder) {
152 auto const threshold = get_threshold(*bidder_info);
153 auto result = auction.template call<gamma_oracle>(
156 if (!result)
continue;
157 if (!best || get_frac(result) < get_frac(best)) {
158 best = std::move(result);
159 last_assigned_bidder_info = bidder_info;
160 last_assigned_bidder = bidder;
161 last_value = get_frac(result).den + threshold;
165 auto& best_items = best->first;
166 for (
auto item = std::begin(best_items); item != std::end(best_items); ++item) {
167 auto const copies = auction.template call<get_copies_num>(*item);
168 auto const old_price =
get(price, *item);
169 auto const new_price =
170 old_price * std::pow(multiplier, 1.0 / (copies+ 1));
171 put(price, *item, new_price);
172 price_sum += copies* (new_price - old_price);
174 total_value += last_value - last_assigned_bidder_info->m_best_items_val;
175 last_assigned_bidder_info->m_best_items = std::move(best_items);
176 last_assigned_bidder_info->m_best_items_val = last_value;
177 }
while (price_sum + epsilon < multiplier);
179 const bool nothing_assigned =
180 last_assigned_bidder_info == bidders_info_vec.end();
181 if (nothing_assigned)
return;
184 puretype(last_assigned_bidder_info) bidder_info,
187 *result = std::make_pair(*bidder, std::move(bidder_info->m_best_items));
190 if (last_value > total_value - last_value) {
191 output(last_assigned_bidder_info, last_assigned_bidder);
194 auto bidder_info = bidders_info_vec.begin();
195 auto bidder = std::begin(auction.template get<bidders>());
196 for (; bidder_info != bidders_info_vec.end(); ++bidder_info, ++bidder)
197 if (bidder != last_assigned_bidder)
198 output(bidder_info, bidder);
214 class GammaOracleAuction,
215 class OutputIterator,
216 class Epsilon =
double
219 GammaOracleAuction&& auction,
220 OutputIterator result,
221 Epsilon epsilon = 1e-8
225 using ItemVal =
typename Traits::item_val_t;
227 std::unordered_map<ItemVal, Value> umap;
229 std::forward<GammaOracleAuction>(auction),
231 boost::make_assoc_property_map(umap),
Utils for the Boost PropertyMap.
Concept class for output iterator concept. We don't use boost::OutputIterator concept as it excludes ...
auto bidders_number(Auction &&auction)
Returns the number of bidders in an auction.
promote_with_t< T, double > promote_with_double_t
return type after promotion with double
Concept class for floating point types.
bool best(Solution &solution, ContinueOnSuccess on_success, components...comps)
This local search chooses the best possible move and applies it to the solution. Note that this strat...
void determine_winners_in_gamma_oracle_auction(GammaOracleAuction &&auction, OutputIterator result, PriceMap price, Epsilon epsilon)
detail
#define puretype(t)
for given expression returns its type with removed const and reference
Types associated with gamma oracle auction.
property_map_get< Map > make_property_map_get(Map map)
make for property_map_get
Concept class for move constructible types.
simple class to represent fraction
paal::auctions::auction_traits< Auction >::copies_num_t get_minimum_copies_num(Auction &&auction)
Returns minimum number of copies of an item in an auction.