Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'clean_events' of github.com:Takishipp/simgrid into clean_events
[simgrid.git] / src / surf / fair_bottleneck.cpp
index d6c424a..30b45e2 100644 (file)
@@ -4,11 +4,12 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "xbt/sysdep.h"
-#include "xbt/log.h"
 #include "maxmin_private.hpp"
-#include <stdlib.h>
+#include "xbt/log.h"
+#include "xbt/sysdep.h"
+#include <float.h>
 #include <math.h>
+#include <stdlib.h>
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_maxmin);
 #define SHOW_EXPR_G(expr) XBT_DEBUG(#expr " = %g",expr);
@@ -32,7 +33,7 @@ void bottleneck_solve(lmm_system_t sys)
 
   static s_xbt_swag_t cnst_to_update;
 
-  if (!(sys->modified))
+  if (not sys->modified)
     return;
 
   /* Init */
@@ -77,7 +78,7 @@ void bottleneck_solve(lmm_system_t sys)
 
   XBT_DEBUG("Fair bottleneck Initialized");
 
-  /* 
+  /*
    * Compute Usage and store the variables that reach the maximum.
    */
   do {
@@ -99,9 +100,9 @@ void bottleneck_solve(lmm_system_t sys)
           nb++;
       }
       XBT_DEBUG("\tThere are %d variables", nb);
-      if (nb > 0 && !cnst->sharing_policy)
+      if (nb > 0 && not cnst->sharing_policy)
         nb = 1;
-      if (!nb) {
+      if (not nb) {
         cnst->remaining = 0.0;
         cnst->usage = cnst->remaining;
         xbt_swag_remove(cnst, cnst_list);
@@ -113,10 +114,11 @@ void bottleneck_solve(lmm_system_t sys)
 
     xbt_swag_foreach_safe(_var, _var_next, var_list) {
       var = static_cast<lmm_variable_t>(_var);
-      double min_inc =  var->cnsts[0].constraint->usage / var->cnsts[0].value;
-      for (int i = 1; i < var->cnsts_number; i++) {
+      double min_inc = DBL_MAX;
+      for (int i = 0; i < var->cnsts_number; i++) {
         lmm_element_t elm = &var->cnsts[i];
-        min_inc = MIN(min_inc, elm->constraint->usage / elm->value);
+        if (elm->value > 0)
+          min_inc = MIN(min_inc, elm->constraint->usage / elm->value);
       }
       if (var->bound > 0)
         min_inc = MIN(min_inc, var->bound - var->value);
@@ -145,7 +147,7 @@ void bottleneck_solve(lmm_system_t sys)
           cnst->usage = MIN(cnst->usage, elem->value * elem->variable->mu);
         }
       }
-      if (!cnst->sharing_policy) {
+      if (not cnst->sharing_policy) {
         XBT_DEBUG("\tUpdate constraint %p (%g) by %g", cnst, cnst->remaining, cnst->usage);
 
         double_update(&(cnst->remaining), cnst->usage, sg_maxmin_precision);