3 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
6 #include <tr1/functional>
7 #include "loba_makhoul.h"
9 void loba_makhoul::load_balance()
12 using std::tr1::placeholders::_1;
13 using std::tr1::placeholders::_2;
15 pneigh_sort_by_load(std::less<double>());
17 print_loads_p(false, xbt_log_priority_debug);
19 // find limit between least loaded neighbors, and more loaded ones
20 pneigh_type::iterator bound =
21 std::lower_bound(pneigh.begin(), pneigh.end(),
23 bind(std::less<double>(),
24 bind(&neighbor::get_load, _1), _2));
26 // compute load differences
27 std::vector<double> delta(bound - pneigh.begin());
28 std::transform(pneigh.begin(), bound, delta.begin(),
29 bind(std::minus<double>(),
30 get_load(), bind(&neighbor::get_load, _1)));
33 double alpha = 1.0 / (pneigh.size() + 1.0);
35 i < delta.size() && pneigh[i]->get_load() < get_load() ; ++i) {
36 double balance = delta[i] * alpha;
37 send(pneigh[i], balance);
38 XBT_DEBUG("sent %g to %s", balance, pneigh[i]->get_name());