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

Private GIT Repository
Remove pointless struct keyword.
[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     const double delta = 0.001;
18
19     std::sort(pneigh.begin(), pneigh.end(), compare());
20
21     print_loads_p(false, xbt_log_priority_debug);
22
23     bool found = true;
24
25     while (found) {
26         found = false;
27         for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
28             if (pneigh[i]->get_load() <= get_load() - 2 * delta) {
29                 found = true;
30                 send(pneigh[i], delta);
31                 XBT_DEBUG("sent to %s", pneigh[i]->get_name());
32             }
33         }
34     }
35 }
36
37 // Local variables:
38 // mode: c++
39 // End: