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;
14 pneigh_sort_by_load(std::less<double>());
16 print_loads_p(false, xbt_log_priority_debug);
18 // find limit between least loaded neighbors, and more loaded ones
19 pneigh_type::iterator bound =
20 std::find_if(pneigh.begin(), pneigh.end(),
21 bind(std::less_equal<double>(),
22 get_load(), bind(&neighbor::get_load, _1)));
24 // compute load differences
25 std::vector<double> delta(bound - pneigh.begin());
26 std::transform(pneigh.begin(), bound, delta.begin(),
27 bind(std::minus<double>(),
28 get_load(), bind(&neighbor::get_load, _1)));
31 double alpha = 1.0 / (pneigh.size() + 1.0);
33 i < delta.size() && pneigh[i]->get_load() < get_load() ; ++i) {
34 double balance = delta[i] * alpha;
35 send(pneigh[i], balance);
36 XBT_DEBUG("sent %g to %s", balance, pneigh[i]->get_name());