- if (imin != -1) {
- // found someone
- double balance = (my_load - min) / 2;
- DEBUG6("%d:%g %d:%g %g %g", imin, min, imax, max, my_load, balance);
- pneigh[imin]->set_to_send(balance);
- pneigh[imin]->set_load(min+balance);
- return balance;
- } else {
- return 0.0;
+ if (imin != -1) { // found someone
+ double balance = std::min((get_load() - min) / 2.0,
+ (get_load() - max));
+ XBT_DEBUG("%d:%g %d:%g %g %g",
+ imin, min, imax, max, get_load(), balance);
+ send(pneigh[imin], balance);