X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/2f365d3503318b9911fe71d29878ea49a753534d..8b38487ddaa9feb357243d58db9cb5403d758262:/loba_besteffort.cpp?ds=sidebyside diff --git a/loba_besteffort.cpp b/loba_besteffort.cpp index 18e8c0c..22343e0 100644 --- a/loba_besteffort.cpp +++ b/loba_besteffort.cpp @@ -6,8 +6,31 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba); void loba_besteffort::load_balance() { - // write code here... - xbt_die("Load-balancing algorithm besteffort not implemented!"); + pneigh_sort_by_load(std::less()); + print_loads_p(false, xbt_log_priority_debug); + + unsigned bound = pneigh.size(); + double sum = get_load(); + for (unsigned i = 0 ; i < bound ; ++i) { + if (get_load() <= pneigh[i]->get_load()) { + bound = i; + } else { + double newsum = sum + pneigh[i]->get_load(); + if (pneigh[i]->get_load() <= newsum / (i + 2)) + sum = newsum; + else + bound = i; + } + } + + double mean = sum / (bound + 1); + for (unsigned i = 0 ; i < bound ; ++i) { + double transfer = mean - pneigh[i]->get_load(); + if (opt::option_x) + transfer /= opt::option_x; // HACK!!! + send(pneigh[i], transfer); + XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name()); + } } // Local variables: