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

Private GIT Repository
Add as_parameters (as for A. Sider), copy current sample_parameters.
[loba.git] / loba_makhoul.cpp
1 #include <xbt/log.h>
2
3 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
4
5 #include "loba_makhoul.h"
6
7 void loba_makhoul::load_balance()
8 {
9     pneigh_sort_by_load(std::less<double>());
10     print_loads_p(false, xbt_log_priority_debug);
11
12     double alpha = 1.0 / (pneigh.size() + 1.0);
13     double my_load = get_load();
14     bool cont = true;
15     for (unsigned i = 0 ;
16          cont && i < pneigh.size() && pneigh[i]->get_load() < my_load ; ++i) {
17
18         double delta = my_load - pneigh[i]->get_load();
19         double transfer = alpha * delta;
20         XBT_DEBUG("delta = %g ; transfer = %g", delta, transfer);
21         if (pneigh[i]->get_load() + transfer <= get_load() - transfer) {
22             send(pneigh[i], transfer);
23             XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());
24         } else {
25             cont = false;
26         }
27     }
28 }
29
30 // Local variables:
31 // mode: c++
32 // End: