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

Private GIT Repository
8ee3b3e82dbe579afe2d86f55ba9d9a679811f66
[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
11     print_loads_p(false, xbt_log_priority_debug);
12
13     double alpha = 1.0 / (pneigh.size() + 1.0);
14     double myLoad = get_load();
15     for (unsigned i = 0; i < pneigh.size(); i++) {
16         double delta = std::max(myLoad - pneigh[i]->get_load(), 0.0);
17         double transfer = alpha * delta;
18         XBT_DEBUG("delta = %g ; transfer = %g", delta, transfer);
19         if (pneigh[i]->get_load() <= get_load() - 2 * transfer) {
20             send(pneigh[i], transfer);
21             XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());
22         } else {
23             break;
24         }
25     }
26 }
27
28 // Local variables:
29 // mode: c++
30 // End: