Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-check output more parsable
[simgrid.git] / src / surf / maxmin.c
index bd092b4..014457b 100644 (file)
@@ -15,6 +15,8 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf,
                                 "Logging specific to SURF (maxmin)");
 
+double sg_maxmin_precision = 0.00001;
+
 static void *lmm_variable_mallocator_new_f(void);
 static void lmm_variable_mallocator_free_f(void *var);
 static void lmm_variable_mallocator_reset_f(void *var);
@@ -24,6 +26,8 @@ static void lmm_remove_all_modified_set(lmm_system_t sys);
 int sg_maxmin_selective_update = 1;
 static int Global_debug_id = 1;
 static int Global_const_debug_id = 1;
+extern xbt_swag_t keep_track;
+
 lmm_system_t lmm_system_new(void)
 {
   lmm_system_t l = NULL;
@@ -53,7 +57,7 @@ lmm_system_t lmm_system_new(void)
   xbt_swag_init(&(l->saturated_constraint_set),
                 xbt_swag_offset(cnst, saturated_constraint_set_hookup));
 
-  l->variable_mallocator = xbt_mallocator_new(64,
+  l->variable_mallocator = xbt_mallocator_new(65536,
                                               lmm_variable_mallocator_new_f,
                                               lmm_variable_mallocator_free_f,
                                               lmm_variable_mallocator_reset_f);
@@ -105,7 +109,6 @@ static void lmm_var_free(lmm_system_t sys, lmm_variable_t var)
 {
 
   lmm_variable_disable(sys, var);
-  free(var->cnsts);
   xbt_mallocator_release(sys->variable_mallocator, var);
 }
 
@@ -159,18 +162,20 @@ XBT_INLINE void lmm_constraint_free(lmm_system_t sys,
 
 static void *lmm_variable_mallocator_new_f(void)
 {
-  return xbt_new(s_lmm_variable_t, 1);
+  lmm_variable_t var = xbt_new(s_lmm_variable_t, 1);
+  var->cnsts = NULL; /* will be created by realloc */
+  return var;
 }
 
 static void lmm_variable_mallocator_free_f(void *var)
 {
+  xbt_free(((lmm_variable_t) var)->cnsts);
   xbt_free(var);
 }
 
 static void lmm_variable_mallocator_reset_f(void *var)
 {
-  /* memset to zero like calloc */
-  memset(var, 0, sizeof(s_lmm_variable_t));
+  /* lmm_variable_new() initializes everything */
 }
 
 lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
@@ -186,10 +191,8 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
   var = xbt_mallocator_get(sys->variable_mallocator);
   var->id = id;
   var->id_int = Global_debug_id++;
-  var->cnsts = xbt_new0(s_lmm_element_t, number_of_constraints);
+  var->cnsts = xbt_realloc(var->cnsts, number_of_constraints * sizeof(s_lmm_element_t));
   for (i = 0; i < number_of_constraints; i++) {
-    /* Should be useless because of the 
-       calloc but it seems to help valgrind... */
     var->cnsts[i].element_set_hookup.next = NULL;
     var->cnsts[i].element_set_hookup.prev = NULL;
     var->cnsts[i].active_element_set_hookup.next = NULL;
@@ -199,17 +202,22 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
     var->cnsts[i].value = 0.0;
   }
   var->cnsts_size = number_of_constraints;
-  var->cnsts_number = 0;        /* Should be useless because of the 
-                                   calloc but it seems to help valgrind... */
+  var->cnsts_number = 0;
   var->weight = weight;
   var->bound = bound;
   var->value = 0.0;
 
-
+  var->mu = 0.0;
+  var->new_mu = 0.0;
   var->func_f = func_f_def;
   var->func_fp = func_fp_def;
   var->func_fpi = func_fpi_def;
 
+  var->variable_set_hookup.next = NULL;
+  var->variable_set_hookup.prev = NULL;
+  var->saturated_variable_set_hookup.next = NULL;
+  var->saturated_variable_set_hookup.prev = NULL;
+
   if (weight)
     xbt_swag_insert_at_head(var, &(sys->variable_set));
   else
@@ -429,16 +437,24 @@ void lmm_print(lmm_system_t sys)
     trace_buf =
         xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
     strcat(trace_buf, print_buf);
+    sprintf(print_buf, "%s(",(cnst->shared)?"":"max");
+    trace_buf =
+      xbt_realloc(trace_buf,
+                 strlen(trace_buf) + strlen(print_buf) + 1);
+    strcat(trace_buf, print_buf);      
     xbt_swag_foreach(elem, elem_list) {
-      sprintf(print_buf, "%f.'%d'(%f) + ", elem->value,
-              elem->variable->id_int, elem->variable->value);
+      sprintf(print_buf, "%f.'%d'(%f) %s ", elem->value,
+              elem->variable->id_int, elem->variable->value,(cnst->shared)?"+":",");
       trace_buf =
           xbt_realloc(trace_buf,
                       strlen(trace_buf) + strlen(print_buf) + 1);
       strcat(trace_buf, print_buf);
-      sum += elem->value * elem->variable->value;
+      if(cnst->shared) 
+       sum += elem->value * elem->variable->value;
+      else 
+       sum = MAX(sum,elem->value * elem->variable->value);
     }
-    sprintf(print_buf, "0 <= %f ('%d')", cnst->bound, cnst->id_int);
+    sprintf(print_buf, "0) <= %f ('%d')", cnst->bound, cnst->id_int);
     trace_buf =
         xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
     strcat(trace_buf, print_buf);
@@ -451,7 +467,7 @@ void lmm_print(lmm_system_t sys)
       strcat(trace_buf, print_buf);
     }
     //   DEBUG1("%s", trace_buf);
-    fprintf(stderr, "%s", trace_buf);
+    fprintf(stderr, "%s\n", trace_buf);
     trace_buf[0] = '\000';
     xbt_assert3(!double_positive(sum - cnst->bound),
                 "Incorrect value (%f is not smaller than %f): %g",
@@ -489,6 +505,8 @@ void lmm_solve(lmm_system_t sys)
   if (!(sys->modified))
     return;
 
+  XBT_IN1("(sys=%p)", sys);
+
   /*
    * Compute Usage and store the variables that reach the maximum.
    */
@@ -510,7 +528,6 @@ void lmm_solve(lmm_system_t sys)
     }
   }
 
-  DEBUG1("Active constraints : %d", xbt_swag_size(cnst_list));
   xbt_swag_foreach(cnst, cnst_list) {
     /* INIT */
     cnst->remaining = cnst->bound;
@@ -529,9 +546,12 @@ void lmm_solve(lmm_system_t sys)
           cnst->usage = elem->value / elem->variable->weight;
 
         make_elem_active(elem);
+        if(keep_track){
+            xbt_swag_insert((elem->variable)->id, keep_track);
+        }
       }
     }
-    DEBUG2("Constraint Usage %d : %f", cnst->id_int, cnst->usage);
+    DEBUG2("Constraint Usage '%d' : %f", cnst->id_int, cnst->usage);
     /* Saturated constraints update */
     saturated_constraint_set_update(sys, cnst, &min_usage);
   }
@@ -630,6 +650,7 @@ void lmm_solve(lmm_system_t sys)
   if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
     lmm_print(sys);
   }
+  XBT_OUT;
 }
 
 /* Not a O(1) function */