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

Private GIT Repository
Add references.
[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     using std::tr1::placeholders::_2;
14
15     pneigh_sort_by_load(std::less<double>());
16
17     print_loads_p(false, xbt_log_priority_debug);
18
19     // find limit between least loaded neighbors, and more loaded ones
20     pneigh_type::iterator bound =
21         std::lower_bound(pneigh.begin(), pneigh.end(),
22                          get_load(),
23                          bind(std::less<double>(),
24                               bind(&neighbor::get_load, _1), _2));
25
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)));
31
32     // send load...
33     double alpha = 1.0 / (pneigh.size() + 1.0);
34     for (unsigned i = 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());
39     }
40 }
41
42 // Local variables:
43 // mode: c++
44 // End: