+#include <xbt/log.h>
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
+
+#include "loba_makhoul2.h"
+
+// Note: adapted from Makhoul's code
+
+void loba_makhoul2::load_balance()
+{
+ pneigh_sort_by_load(std::less<double>());
+
+ print_loads_p(false, xbt_log_priority_debug);
+
+ double alpha = 1.0 / (pneigh.size() + 1.0);
+ double neighborLoadMax = 0.0; // maximum load of neighbors to
+ // which something has been sent
+ for (unsigned i = 0;
+ i < pneigh.size() && pneigh[i]->get_load() < get_load(); i++) {
+ double delta = get_load() - pneigh[i]->get_load();
+
+ // do not violate ping-pong condition
+ double transfer = std::min(alpha * delta, get_load() - neighborLoadMax);
+ XBT_DEBUG("delta = %g ; transfer = %g", delta, transfer);
+
+ send(pneigh[i], transfer);
+ XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());
+
+ double newNeighborLoad = pneigh[i]->get_load();
+ if (newNeighborLoad > neighborLoadMax)
+ neighborLoadMax = newNeighborLoad;
+ }
+}
+
+// Local variables:
+// mode: c++
+// End: