15 #ifndef PAAL_FRACTIONAL_WINNER_DETERMINATION_IN_MUCA_HPP
16 #define PAAL_FRACTIONAL_WINNER_DETERMINATION_IN_MUCA_HPP
28 #include <boost/concept/requires.hpp>
29 #include <boost/property_map/property_map.hpp>
30 #include <boost/range/combine.hpp>
31 #include <boost/range/counting_range.hpp>
36 #include <type_traits>
43 template <
class B
idder,
class B
idId,
class Bundle>
48 bid(
Bidder bidder, BidId bid_id, Bundle bundle) :
49 m_bidder(bidder), m_bid_id(bid_id), m_bundle(bundle) {}
75 class DemandQueryAuction,
80 BOOST_CONCEPT_REQUIRES(
84 ((boost::ForwardRangeConcept<
85 typename demand_query_auction_traits<DemandQueryAuction>::bidders_universe_t
88 ((boost::ForwardRangeConcept<
89 typename demand_query_auction_traits<DemandQueryAuction>::items_t
93 typename demand_query_auction_traits<DemandQueryAuction>::items_t
99 typename demand_query_auction_traits<DemandQueryAuction>::bidder_t,
100 typename demand_query_auction_traits<DemandQueryAuction>::items_t,
105 ((boost::ReadWritePropertyMapConcept<
107 typename demand_query_auction_traits<DemandQueryAuction>::item_t
114 DemandQueryAuction&& auction,
115 OutputIterator result,
116 ItemToLpIdMap item_to_id,
118 SeparationOracle separation_oracle = SeparationOracle{}
120 using traits_t = demand_query_auction_traits<DemandQueryAuction>;
121 using bundle_t =
typename traits_t::items_t;
122 using bidder_t =
typename traits_t::bidder_t;
123 using bid_t = detail::bid<bidder_t, lp::row_id, bundle_t>;
124 using result_t =
typename traits_t::result_t;
127 dual.set_optimization_type(lp::MINIMIZE);
130 auto&& items_ = auction.template get<items>();
131 for (
auto item = std::begin(items_); item != std::end(items_); ++item) {
132 auto const copies = auction.template call<get_copies_num>(*item);
133 auto const id = dual.
add_column(copies, 0, lp::lp_traits::PLUS_INF,
"");
134 put(item_to_id, *item,
id);
140 for (
auto&
id: bidder_to_id)
141 id = dual.
add_column(1, 0, lp::lp_traits::PLUS_INF,
"");
144 std::vector<bid_t> generated_bids;
152 boost::optional<result_t> res;
153 boost::optional<bidder_t> last_bidder;
155 auto how_much_violated =
159 last_bidder = bidder;
160 res = auction.template call<demand_query>(bidder, get_price);
161 auto const util = res->second;
163 if (alpha > epsilon)
return boost::optional<double>(alpha);
164 return boost::optional<double>{};
170 if (bidder != *last_bidder) {
171 res = auction.template call<demand_query>(bidder, get_price);
174 auto& items = res->first;
175 auto const util = res->second;
179 auto const value = util + price;
181 lp::linear_expression(bidder_id), item_to_id_func);
182 auto const bid_id = dual.
add_row(expr >= value);
183 generated_bids.emplace_back(bidder, bid_id, std::move(items));
187 boost::combine(auction.template get<bidders>(), bidder_to_id));
190 auto find_violated = separation_oracle(get_candidates, how_much_violated, add_violated);
192 auto solve_lp = [&]()
194 auto const res = dual.resolve_simplex(lp::DUAL);
195 assert(res == lp::OPTIMAL);
202 for (
auto& bid: generated_bids) {
203 auto const fraction = dual.get_row_dual_value(bid.m_bid_id);
204 if (fraction <= epsilon)
continue;
205 *result = std::make_tuple(std::move(bid.m_bidder),
206 std::move(bid.m_bundle), fraction);
223 template <
class DemandQueryAuction,
class OutputIterator>
225 DemandQueryAuction&& auction,
226 OutputIterator result,
227 double epsilon = 1e-7
230 using ItemVal =
typename traits_t::item_val_t;
232 std::unordered_map<ItemVal, lp::col_id> map;
234 std::forward<DemandQueryAuction>(auction),
236 boost::make_assoc_property_map(map),
Utils for the Boost PropertyMap.
The common LP solvers base class. Responsible for:
col_id add_column(double cost_coef=0, double lb=0., double ub=lp_traits::PLUS_INF, const std::string &name="")
void fractional_determine_winners_in_demand_query_auction(DemandQueryAuction &&auction, OutputIterator result, ItemToLpIdMap item_to_id, double epsilon, SeparationOracle separation_oracle=SeparationOracle{})
detail
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.
auto make_tuple_uncurry(F f)
make for tuple_uncurry
auto make_dynamic_return_constant_functor(T t)
make function for dynamic_return_constant_functor
problem_type row_generation(TryAddViolated try_add_violated, SolveLp solve_lp)
std::string Bidder
[Demand Query Auction Components Example]
auto compose(F f, G g)
functor composition: x -> f(g(x))
This file contains set of simple useful functors or functor adapters.
T accumulate_functor(const Range &rng, T init, Functor f, BinaryOperation bin_op=BinaryOperation{})
combination of boost::accumulate and boost::adaptors::transformed
double get_col_value(col_id col) const
auto sum_functor(const Range &rng, Functor f)
sum of functor values over the range elements
property_map_get< Map > make_property_map_get(Map map)
make for property_map_get
row_id add_row(const double_bounded_expression &constraint=double_bounded_expression{}, const std::string &name="")
Concept class for move constructible types.
Types associated with demand query auction.