]> AND Private Git Repository - loba.git/blob - loba_makhoul.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Update TODO.
[loba.git] / loba_makhoul.cpp
1 #include <xbt/log.h>
2
3 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
4
5 #include <algorithm>
6 #include <tr1/functional>
7 #include "loba_makhoul.h"
8
9 void loba_makhoul::load_balance()
10 {
11     using std::tr1::bind;
12     using std::tr1::placeholders::_1;
13
14     pneigh_sort_by_load(std::less<double>());
15
16     print_loads_p(false, xbt_log_priority_debug);
17
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)));
23
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)));
29
30     // send load...
31     double alpha = 1.0 / (pneigh.size() + 1.0);
32     for (unsigned i = 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());
37     }
38 }
39
40 // Local variables:
41 // mode: c++
42 // End: