18 using P = std::pair<size_t, size_t>;
25 std::vector<std::size_t>
lpt(std::size_t nbag, std::vector<std::size_t>& pieces,
double* bal) {
30 for (
size_t i = 0;
i < pieces.size(); ++
i) {
31 pvec.push_back(
P(
i, pieces[
i]));
34 auto P_comp = [](
const P& a,
const P& b) {
return a.second > b.second; };
36 std::sort(pvec.begin(), pvec.end(), P_comp);
38 std::vector<std::size_t> bagindices(pieces.size());
40 std::priority_queue<P, std::vector<P>, decltype(P_comp)> bagq(P_comp);
41 for (
size_t i = 0;
i < nbag; ++
i) {
45 for (
const auto& p: pvec) {
46 P bagqitem = bagq.top();
48 bagindices[p.first] = bagqitem.first;
49 bagqitem.second += p.second;
54 std::vector<size_t>
v(bagq.size());
55 for (
size_t i = 1;
i < nbag; ++
i) {
56 v[
i] = bagq.top().second;
63 printf(
"load balance = %g for %ld pieces in %ld bags\n", b, pieces.size(), nbag);
71 std::size_t sum = std::accumulate(
v.begin(),
v.end(), 0);
72 std::size_t max = *std::max_element(
v.begin(),
v.end());
73 return (
double(sum) /
v.size()) / max;