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

Private GIT Repository
ccfd7005553b5c46e7d78a9588091579d5045023
[loba.git] / loba_fairstrategy.cpp
1 #include <algorithm>
2 #include <xbt/log.h>
3
4 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
5
6 #include "loba_fairstrategy.h"
7
8 class compare {
9 public:
10     bool operator()(const neighbor*a, const neighbor*b) {
11         return a->get_load() > b->get_load();
12     }
13 };
14
15 void loba_fairstrategy::load_balance()
16 {
17     std::sort(pneigh.begin(), pneigh.end(), compare());
18
19     print_loads_p(false, xbt_log_priority_debug);
20
21     bool found = true;
22
23     while (found) {
24         found = false;
25         for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
26             if (pneigh[i]->get_load() <= get_load() - .002) {
27                 found = true;
28                 send(pneigh[i], .001);
29                 DEBUG1("sent to %s", pneigh[i]->get_name());
30             }
31         }
32     }
33 }
34
35 // Local variables:
36 // mode: c++
37 // End: