Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finally working.
authorvelho <velho@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 10 May 2007 12:54:08 +0000 (12:54 +0000)
committervelho <velho@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 10 May 2007 12:54:08 +0000 (12:54 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3498 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/surf/lagrange.c

index bdffdc4..7cf0332 100644 (file)
@@ -20,7 +20,6 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_lagrange, surf, "Logging specific to SURF (lagrange)");
 
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_lagrange, surf, "Logging specific to SURF (lagrange)");
 
-
 /*
  * Local prototypes to implement the lagrangian optimization with optimal step, also called dicotomi.
  */
 /*
  * Local prototypes to implement the lagrangian optimization with optimal step, also called dicotomi.
  */
@@ -34,7 +33,6 @@ double partial_diff_mu      (double mu, void * param_var);
 double partial_diff_lambda  (double lambda, void * param_cnst);
 
 
 double partial_diff_lambda  (double lambda, void * param_cnst);
 
 
-
 void lagrange_solve(lmm_system_t sys)
 {
   /*
 void lagrange_solve(lmm_system_t sys)
 {
   /*
@@ -45,7 +43,6 @@ void lagrange_solve(lmm_system_t sys)
   double dicotomi_min_error = 1e-8;
   double overall_error = 1;
 
   double dicotomi_min_error = 1e-8;
   double overall_error = 1;
 
-
   /*
    * Variables to manipulate the data structure proposed to model the maxmin
    * fairness. See docummentation for more details.
   /*
    * Variables to manipulate the data structure proposed to model the maxmin
    * fairness. See docummentation for more details.
@@ -59,7 +56,6 @@ void lagrange_solve(lmm_system_t sys)
   xbt_swag_t var_list   = NULL;
   lmm_variable_t var    = NULL;
 
   xbt_swag_t var_list   = NULL;
   lmm_variable_t var    = NULL;
 
-
   /*
    * Auxiliar variables.
    */
   /*
    * Auxiliar variables.
    */
@@ -121,6 +117,7 @@ void lagrange_solve(lmm_system_t sys)
       if((var->bound >= 0) && (var->weight > 0) ){
        var->new_mu = dicotomi(var->mu, partial_diff_mu, var, dicotomi_min_error);
        if(var->new_mu < 0) var->new_mu = 0;
       if((var->bound >= 0) && (var->weight > 0) ){
        var->new_mu = dicotomi(var->mu, partial_diff_mu, var, dicotomi_min_error);
        if(var->new_mu < 0) var->new_mu = 0;
+       var->mu = var->new_mu;
       }
     }
 
       }
     }
 
@@ -131,20 +128,22 @@ void lagrange_solve(lmm_system_t sys)
     xbt_swag_foreach(cnst, cnst_list) {
       cnst->new_lambda = dicotomi(cnst->lambda, partial_diff_lambda, cnst, dicotomi_min_error);
       DEBUG2("====> cnst->lambda (%p) = %e", cnst, cnst->new_lambda);      
     xbt_swag_foreach(cnst, cnst_list) {
       cnst->new_lambda = dicotomi(cnst->lambda, partial_diff_lambda, cnst, dicotomi_min_error);
       DEBUG2("====> cnst->lambda (%p) = %e", cnst, cnst->new_lambda);      
+      cnst->lambda = cnst->new_lambda;
     }
 
     }
 
-    /*                       
-     * Update values of mu and lambda
-     */
-    //forall mu_i in mu_1, mu_2, ..., mu_n
-    xbt_swag_foreach(var, var_list) {
-      var->mu = var->new_mu ;
-    }
+
+/*     /\*                        */
+/*      * Update values of mu and lambda */
+/*      *\/ */
+/*     //forall mu_i in mu_1, mu_2, ..., mu_n */
+/*     xbt_swag_foreach(var, var_list) { */
+/*       var->mu = var->new_mu ; */
+/*     } */
   
   
-    //forall lambda_i in lambda_1, lambda_2, ..., lambda_n
-    xbt_swag_foreach(cnst, cnst_list) {
-      cnst->lambda = cnst->new_lambda;
-    }
+/*     //forall lambda_i in lambda_1, lambda_2, ..., lambda_n */
+/*     xbt_swag_foreach(cnst, cnst_list) { */
+/*       cnst->lambda = cnst->new_lambda; */
+/*     } */
 
     /*
      * Now computes the values of each variable (\rho) based on
 
     /*
      * Now computes the values of each variable (\rho) based on
@@ -193,7 +192,6 @@ void lagrange_solve(lmm_system_t sys)
     }
   
   }
     }
   
   }
-
   
   //verify the KKT property of each flow
   xbt_swag_foreach(var, var_list){
   
   //verify the KKT property of each flow
   xbt_swag_foreach(var, var_list){
@@ -208,7 +206,6 @@ void lagrange_solve(lmm_system_t sys)
 
   }
 
 
   }
 
-
   if(overall_error <= epsilon_min_error){
     DEBUG1("The method converge in %d iterations.", iteration);
   }else{
   if(overall_error <= epsilon_min_error){
     DEBUG1("The method converge in %d iterations.", iteration);
   }else{
@@ -235,6 +232,11 @@ double dicotomi(double init, double diff(double, void*), void *var_cnst, double
   double min_diff, max_diff, middle_diff;
   
   min = max = init;
   double min_diff, max_diff, middle_diff;
   
   min = max = init;
+
+  if(init == 0){
+    min = max = 1;
+  }
+
   min_diff = max_diff = middle_diff = 0.0;
   overall_error = 1;
 
   min_diff = max_diff = middle_diff = 0.0;
   overall_error = 1;
 
@@ -243,10 +245,16 @@ double dicotomi(double init, double diff(double, void*), void *var_cnst, double
     return 0.0;
   }
 
     return 0.0;
   }
 
+  DEBUG0("====> not detected positive diff in 0");
+
   while(overall_error > min_error){
   while(overall_error > min_error){
+
     min_diff = diff(min, var_cnst);
     max_diff = diff(max, var_cnst);
 
     min_diff = diff(min, var_cnst);
     max_diff = diff(max, var_cnst);
 
+    DEBUG2("DICOTOMI ===> min = %e , max = %e", min, max);
+    DEBUG2("DICOTOMI ===> diffmin = %e , diffmax = %e", min_diff, max_diff);
+
     if( min_diff > 0 && max_diff > 0 ){
       if(min == max){
        min = min / 2.0;
     if( min_diff > 0 && max_diff > 0 ){
       if(min == max){
        min = min / 2.0;
@@ -330,18 +338,18 @@ double partial_diff_lambda(double lambda, void *param_cnst){
     
     tmp = 0;
 
     
     tmp = 0;
 
-    DEBUG2("===> Variable (%p) %s", var, (char *)var->id);
+    //DEBUG2("===> Variable (%p) %s", var, (char *)var->id);
 
     for(i=0; i<var->cnsts_number; i++){
       tmp += (var->cnsts[i].constraint)->lambda;
 
     for(i=0; i<var->cnsts_number; i++){
       tmp += (var->cnsts[i].constraint)->lambda;
-      DEBUG1("======> lambda %e + ", (var->cnsts[i].constraint)->lambda);
+      //DEBUG1("======> lambda %e + ", (var->cnsts[i].constraint)->lambda);
     }
        
     if(var->bound > 0)
       tmp += var->mu;
     
 
     }
        
     if(var->bound > 0)
       tmp += var->mu;
     
 
-    DEBUG2("======> lambda - %e + %e ", cnst->lambda, lambda);
+    //DEBUG2("======> lambda - %e + %e ", cnst->lambda, lambda);
 
     tmp = tmp - cnst->lambda + lambda;
     
 
     tmp = tmp - cnst->lambda + lambda;
     
@@ -350,12 +358,12 @@ double partial_diff_lambda(double lambda, void *param_cnst){
     
     lambda_partial += (-1.0/tmp);
 
     
     lambda_partial += (-1.0/tmp);
 
-    DEBUG1("======> %e ", (-1.0/tmp));
+    //DEBUG1("======> %e ", (-1.0/tmp));
   }
 
   lambda_partial += cnst->bound;
 
   }
 
   lambda_partial += cnst->bound;
 
-  DEBUG1("===> %e ", lambda_partial);
+  //DEBUG1("===> %e ", lambda_partial);
 
   return lambda_partial;
 }
 
   return lambda_partial;
 }