Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More explicit names
[simgrid.git] / src / surf / maxmin.c
index a4c1bbb..6390b6a 100644 (file)
@@ -1,24 +1,16 @@
-/* Authors: Arnaud Legrand                                                  */
+/*     $Id$     */
+
+/* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
 
 /* 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. */
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
 
 #include "xbt/sysdep.h"
 #include "xbt/error.h"
 #include "maxmin_private.h"
 #include <stdlib.h>
 
-/* extern lmm_system_t Sys; */
-/* extern lmm_constraint_t L1; */
-/* extern lmm_constraint_t L2; */
-/* extern lmm_constraint_t L3; */
-
-/* extern lmm_variable_t R_1_2_3; */
-/* extern lmm_variable_t R_1; */
-/* extern lmm_variable_t R_2; */
-/* extern lmm_variable_t R_3; */
-
-
 lmm_system_t lmm_system_new(void)
 {
   lmm_system_t l = NULL;
@@ -27,6 +19,7 @@ lmm_system_t lmm_system_new(void)
 
   l = xbt_new0(s_lmm_system_t, 1);
 
+  l->modified = 0;
   xbt_swag_init(&(l->variable_set),
                xbt_swag_offset(var, variable_set_hookup));
   xbt_swag_init(&(l->constraint_set),
@@ -62,6 +55,8 @@ void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var)
   int i;
   lmm_element_t elem = NULL;
 
+  sys->modified = 1;
+
   for (i = 0; i < var->cnsts_number; i++) {
     elem = &var->cnsts[i];
     xbt_swag_remove(elem, &(elem->constraint->element_set));
@@ -150,6 +145,8 @@ void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst,
 {
   lmm_element_t elem = NULL;
 
+  sys->modified = 1;
+
   if (var->cnsts_number >= var->cnsts_size)
     abort();
 
@@ -175,6 +172,14 @@ int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var)
   return(var->cnsts_number);
 }
 
+lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys, lmm_constraint_t cnst, 
+                                    lmm_variable_t *var)
+{
+  if(!(*var)) xbt_swag_getFirst(&(cnst->element_set));
+  else *var=xbt_swag_getNext(*var,cnst->element_set.offset);
+  return *var;
+}
+
 void *lmm_constraint_id(lmm_constraint_t cnst)
 {
   return cnst->id;
@@ -185,17 +190,17 @@ void *lmm_variable_id(lmm_variable_t var)
   return var->id;
 }
 
-static void saturated_constraints_update(lmm_system_t sys,
+static void saturated_constraint_set_update(lmm_system_t sys,
                                         lmm_constraint_t cnst,
                                         xbt_maxmin_float_t * min_usage)
 {
   lmm_constraint_t useless_cnst = NULL;
 
+  sys->modified = 1;
+
   if (cnst->remaining <= 0)
     return;
   if ((*min_usage < 0) || (*min_usage > cnst->remaining / cnst->usage)) {
-    xbt_swag_t active_elem_list = &(cnst->active_element_set);
-
     *min_usage = cnst->remaining / cnst->usage;
 
     while ((useless_cnst = xbt_swag_getFirst(&(sys->saturated_constraint_set))))
@@ -207,7 +212,7 @@ static void saturated_constraints_update(lmm_system_t sys,
   }
 }
 
-static void saturated_variables_update(lmm_system_t sys)
+static void saturated_variable_set_update(lmm_system_t sys)
 {
   lmm_constraint_t cnst = NULL;
   xbt_swag_t cnst_list = NULL;
@@ -235,6 +240,8 @@ void lmm_solve(lmm_system_t sys)
   xbt_swag_t elem_list = NULL;
   xbt_maxmin_float_t min_usage = -1;
 
+  if(!(sys->modified)) return;
+
   /* Init */
   var_list = &(sys->variable_set);
   xbt_swag_foreach(var, var_list) {
@@ -256,10 +263,10 @@ void lmm_solve(lmm_system_t sys)
     }
 
     /* Saturated constraints update */
-    saturated_constraints_update(sys, cnst, &min_usage);
+    saturated_constraint_set_update(sys, cnst, &min_usage);
   }
 
-  saturated_variables_update(sys);
+  saturated_variable_set_update(sys);
 
   /* Saturated variables update */
 
@@ -298,11 +305,13 @@ void lmm_solve(lmm_system_t sys)
     cnst_list = &(sys->active_constraint_set);
     min_usage = -1;
     xbt_swag_foreach(cnst, cnst_list) {
-      saturated_constraints_update(sys, cnst, &min_usage);
+      saturated_constraint_set_update(sys, cnst, &min_usage);
     }
-    saturated_variables_update(sys);
+    saturated_variable_set_update(sys);
 
   } while (xbt_swag_size(&(sys->saturated_variable_set)));
+
+  sys->modified = 0;
 }
 
 /* Not a O(1) function */
@@ -313,6 +322,7 @@ void lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
   int i;
   lmm_element_t elem = NULL;
 
+  sys->modified = 1;
   for (i = 0; i < var->cnsts_number; i++)
     if (var->cnsts[i].constraint == cnst) {
       elem->value = value;
@@ -320,21 +330,24 @@ void lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
     }
 }
 
-void lmm_update_variable_bound(lmm_variable_t var,
+void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
                               xbt_maxmin_float_t bound)
 {
+  sys->modified = 1;
   var->bound = bound;
 }
 
-void lmm_update_variable_weight(lmm_variable_t var,
+void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var,
                                xbt_maxmin_float_t weight)
 {
+  sys->modified = 1;
   var->weight = weight;
 }
 
-void lmm_update_constraint_bound(lmm_constraint_t cnst,
+void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst,
                                 xbt_maxmin_float_t bound)
 {
+  sys->modified = 1;
   cnst->bound = bound;
 }