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

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