Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the wrong macro usage of WITHOUT_ANSWER
[simgrid.git] / src / surf / maxmin.c
index 929c106..2b65794 100644 (file)
@@ -21,7 +21,7 @@ typedef struct s_dyn_light {
   int size;
 } s_dyn_light_t, *dyn_light_t;
 
-double sg_maxmin_precision = 0.00001;
+XBT_EXPORT_NO_IMPORT(double) sg_maxmin_precision = 0.00001;
 
 static void *lmm_variable_mallocator_new_f(void);
 static void lmm_variable_mallocator_free_f(void *var);
@@ -32,6 +32,10 @@ static void lmm_remove_all_modified_set(lmm_system_t sys);
 static int Global_debug_id = 1;
 static int Global_const_debug_id = 1;
 
+static void lmm_var_free(lmm_system_t sys, lmm_variable_t var);
+static XBT_INLINE void lmm_cnst_free(lmm_system_t sys,
+                                     lmm_constraint_t cnst);
+
 lmm_system_t lmm_system_new(int selective_update)
 {
   lmm_system_t l = NULL;
@@ -254,6 +258,62 @@ XBT_INLINE double lmm_variable_getbound(lmm_variable_t var)
   return (var->bound);
 }
 
+void lmm_shrink(lmm_system_t sys, lmm_constraint_t cnst,
+                lmm_variable_t var)
+{
+  lmm_element_t elem = NULL;
+  int found = 0;
+
+  int i;
+  for (i = 0; i < var->cnsts_number; i++) {
+    elem = &(var->cnsts[i]);
+    if (elem->constraint == cnst) {
+      found = 1;
+      break;
+    }
+  }
+
+  if (!found) {
+    XBT_WARN("cnst %p is not found in var %p", cnst, var);
+    return;
+  }
+
+  sys->modified = 1;
+
+  XBT_INFO("remove elem(value %lf, cnst %p, var %p) in var %p",
+      elem->value, elem->constraint, elem->variable, var);
+
+  xbt_swag_remove(elem, &(elem->constraint->element_set));
+  var->cnsts[i] = var->cnsts[var->cnsts_number - 1];
+  var->cnsts_number -= 1;
+
+
+  if (xbt_swag_size(&(cnst->element_set)) == 0)
+    make_constraint_inactive(sys, cnst);
+  else {
+    /* This shrink operation effects the given constraint as well as all the constraints of the variable? */
+    lmm_update_modified_set(sys, cnst);
+    lmm_update_modified_set(sys, var->cnsts[0].constraint);
+  }
+
+
+#if 0
+  if (!sys->selective_update_active) {
+    make_constraint_active(sys, cnst);
+
+  } else if (elem->value > 0 || var->weight > 0) {
+    make_constraint_active(sys, cnst);
+    lmm_update_modified_set(sys, cnst);
+
+    /* FIXME: Why is only the cnsts[0] used here? Don't we do this other cnts[i]? */
+    /* if a variable object has changes, we might want to propagate changes to all constraints of it? */
+    if (var->cnsts_number > 1)
+      lmm_update_modified_set(sys, var->cnsts[0].constraint);
+  }
+#endif
+
+}
+
 void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst,
                 lmm_variable_t var, double value)
 {
@@ -385,7 +445,7 @@ static XBT_INLINE void saturated_constraint_set_update(double usage,
   } else if (*min_usage == usage) {
     if(saturated_constraint_set->pos == saturated_constraint_set->size) { // realloc the size
       saturated_constraint_set->size *= 2;
-      saturated_constraint_set->data = realloc(saturated_constraint_set->data, (saturated_constraint_set->size) * sizeof(int));
+      saturated_constraint_set->data = xbt_realloc(saturated_constraint_set->data, (saturated_constraint_set->size) * sizeof(int));
     }
     saturated_constraint_set->data[saturated_constraint_set->pos] = cnst_light_num;
     saturated_constraint_set->pos++;