Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
trivial API extension of the maxmin solver
[simgrid.git] / src / surf / maxmin.c
index 7d5dbf0..081a8eb 100644 (file)
@@ -117,12 +117,24 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
                                double bound, int number_of_constraints)
 {
   lmm_variable_t var = NULL;
-
+  int i;
   var = xbt_new0(s_lmm_variable_t, 1);
   var->id = id;
   var->cnsts = xbt_new0(s_lmm_element_t, number_of_constraints);
+  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;
+    var->cnsts[i].active_element_set_hookup.prev = NULL;
+    var->cnsts[i].constraint = NULL;
+    var->cnsts[i].variable = NULL;
+    var->cnsts[i].value = 0.0;
+  }
   var->cnsts_size = number_of_constraints;
-  /* var->cnsts_number = 0; *//* Useless because of the calloc  */
+  var->cnsts_number = 0; /* Should be useless because of the 
+                           calloc but it seems to help valgrind... */
   var->weight = weight;
   var->bound = bound;
   var->value = 0.0;
@@ -165,6 +177,19 @@ void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst,
   make_constraint_active(sys, cnst);
 }
 
+void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
+                   lmm_variable_t var, double value)
+{
+  int i ; 
+  sys->modified = 1;
+
+  for(i=0; i< var->cnsts_number ; i++)
+    if(var->cnsts[i].constraint == cnst) break;
+  
+  if(i<var->cnsts_number) var->cnsts[i].value +=value;
+  else lmm_expand(sys,cnst,var,value);
+}
+
 lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
                                       lmm_variable_t var, int num)
 {
@@ -258,6 +283,7 @@ void lmm_solve(lmm_system_t sys)
 
   /* Init */
   var_list = &(sys->variable_set);
+  DEBUG1("Variable set : %d", xbt_swag_size(var_list));
   xbt_swag_foreach(var, var_list) {
     var->value = 0.0;
   }
@@ -266,6 +292,7 @@ void lmm_solve(lmm_system_t sys)
   /* Compute Usage and store the variables that reach the maximum */
 
   cnst_list = &(sys->active_constraint_set);
+  DEBUG1("cnst_list : %d", xbt_swag_size(cnst_list));
   xbt_swag_foreach(cnst, cnst_list) {
     /* INIT */
     elem_list = &(cnst->element_set);
@@ -291,7 +318,6 @@ void lmm_solve(lmm_system_t sys)
     /* Fix the variables that have to be */
     var_list = &(sys->saturated_variable_set);
 
-
     xbt_swag_foreach(var, var_list) {
       /* First check if some of these variables have reach their upper
          bound and update min_usage accordingly. */