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

Private GIT Repository
Add forgotten files.
[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 (get_load() - 2 * transfer < pneigh[i]->get_load())
20             break;
21         send(pneigh[i], transfer);
22         XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());
23     }
24 }
25
26 // Local variables:
27 // mode: c++
28 // End: